[Python-ideas] Add a command line option to adjust sys.path? (was Re: Add a site.cfg to keep a persistent list of paths)

Nick Coghlan ncoghlan at gmail.com
Thu Oct 21 04:32:32 CEST 2010

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
>> subdirectories):
>> 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
> directory?

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

distutils2 could then provide a way to generate an appropriate .pth
file instead of installing a distribution.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list