dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #24954
Re: runpy.run_path missing on buildbot
On Tue, Nov 8, 2011 at 9:50 PM, Anders Logg <logg@xxxxxxxxx> wrote:
> On Tue, Nov 08, 2011 at 09:13:20AM +0100, Johannes Ring wrote:
>> On Mon, Nov 7, 2011 at 9:12 PM, Anders Logg <logg@xxxxxxxxx> wrote:
>> > On Sat, Nov 05, 2011 at 06:02:05PM +0100, Johannes Ring wrote:
>> >> On Sat, Nov 5, 2011 at 2:50 AM, Anders Logg <logg@xxxxxxxxx> wrote:
>> >> > Some unit tests are failing on my buildbot because runpy.run_path is
>> >> > missing.
>> >> >
>> >> > It seems it was added in Python 2.5.
>> >>
>> >> It was added in Python 2.7 according to the Python docs:
>> >>
>> >> http://docs.python.org/library/runpy.html#runpy.run_path
>> >
>> > ok, does anyone know what the proper replacement is for Python 2.5?
>>
>> Can you use execfile?
>
> I ended up using os.system since execfile doesn't seem to handle
> command-line arguments:
>
> def run_path(path, args):
> "Replacement for runpy.run_path when it doesn't exist"
>
> if has_run_path:
> sys.argv = ["foo"] + [str(arg) for arg in args]
> runpy.run_path(path)
> else:
> status = os.system("python " + path + " " + \
> " ".join(str(arg) for arg in args))
> if not status == 0:
> raise RuntimeError, "Python script failed"
It seems to me that execfile does handle command line arguments. Example:
In test1.py:
execfile("test2.py")
In test2.py:
import sys
print sys.argv
Then:
$ python test1.py 1 2 3 4
['test1.py', '1', '2', '3', '4']
But you have a solution that works now so I guess it's not a big deal.
Johannes
Follow ups
References