[Python-ideas] Add a command line option to adjust sys.path? (was Re: Add a site.cfg to keep a persistent list of paths)
rrr at ronadam.com
Thu Oct 21 06:36:01 CEST 2010
On 10/20/2010 09:32 PM, Nick Coghlan wrote:
> On Thu, Oct 21, 2010 at 4:46 AM, Ron Adam<rrr at ronadam.com> wrote:
>> On 10/20/2010 08:38 AM, Nick Coghlan wrote:
>>> A different idea along these lines that I've been pondering is an
>>> actual -p path option for the interpreter command line, that allowed a
>>> sequence of directories to be provided that would be prepended to
>>> PYTHONPATH (and hence included in sys.path).
>>> So if you're wanting to test two different versions of a module (from
>>> a parent directory containing the two versions in separate
>>> python -p versionA run_tests.py
>>> python -p versionB run_tests.py
>>> For more permanent additions to sys.path, PYTHONPATH (possibly in
>>> conjunction with virtualenv) is reasonable answer. Zipfile and
>>> directory execution covers execution of more complex applications
>>> containing multiple files as if they were simple scripts.
>>> The main piece I see missing from the puzzle is the ability to easily
>>> switch back and forth between multiple versions of a support package
>>> or library without mucking with persistent state like the environment
>>> variables or the filesystem.
>> Yes, I don't like changing the system wide environment variables and file
>> system options. It's too easy to break other things that depend on them.
>> How about adding the ability to use a .pth file from the current program
> A simple check to see if a supplied path was a directory or not would
> let us do both with one new option:
> -p Specify a directory or a .pth file (see site module docs) to be
> prepended to sys.path
Prepending would be great. ;-)
> distutils2 could then provide a way to generate an appropriate .pth
> file instead of installing a distribution.
Where would the .pth file be and how would I run the application if I don't
know I need to specify a .pth file? How would I know I need to specify a
.pth file? (ie... if I'm trying to figure out what is wrong on some one
If you have a default .pth file in the same directory as the .py file being
run, then that would give a way to specify an alternative or local library
of modules and packages that is program specific without doing anything
special. It would be included in the distribution files as well, so
distuitils2 doesn't have to generate anything.
+1 on the -p option with .pth files also.
Can .pth files use environment variables?
More information about the Python-ideas