[Python-Dev] Setting project home path the best way SOLVED
tismer at stackless.com
Mon Nov 12 13:48:57 CET 2012
Hi Nick, Holger,
this is a crazy fault of mine, see the end below.
> I have a project that has its root somewhere on my machine.
> This project has many folders and contains quite some modules.
> There is a common root of the module tree, and I want to use
> - either absolute imports
> - relative imports with '.'
> - I want to run any module inside the heirarchy from the command-line
> - this should work, regardless what my 'cwd' is
> - this should work with or without virtualenv.
> So far, things work fine with virtualenv, because sys.executable is in the project module tree.
> Without virtualenv, this is not so. But I hate to make settings like PYTHONPATH, because these are not permanent. .
> How should I define my project root dir in a unique way, without setting an environment variable?
> What is the lest intrusive way to spell that?
> I'd like to make things work correctly and unambigously when I call a script
> inside the module heirarchy. Things are not fixed: there exist many checkouts
> In the file system, and each should know where to search its home/root in the tree.
> Is this elegantly possible to deduce from the actually executed script file?
On 12.11.12 01:38, Nick Coghlan wrote:
> The only way I know how to do it is to have my cwd set to the
> directory I want on sys.path, then use -m for script execution (using
> a separate shell session for anything where I want a different working
> I don't know of any way to handle a varying cwd without manipulating
> the path directly through either virtualenv or PYTHONPATH.
> Sent from my phone, thus the relative brevity :)
Holger wrote (private message):
> ich selbst nutze seit langer Zeit setuptools, genauer:
> python setup.py develop
> z.B. in pytest, execnet, tox. Das ist wie "setup.py install" nur dass
> das paket "inplace" installiert wird. Aber vermutlich kennst du das schon?!
So here is the crazy story:
I'm actually using setuptools for my tiffany project with
My real work is about the Pydica project which is a lot more.
There I'm playing sys.path tricks, using virtualenv and the fact
that I have full control over the local site-packages, and use some
tricky .pth scripts to set everything up. But it needs virtualenv.
Believe it or not:
*I was not able to realize that all my problems are already solved*
if I change Pydica and build a proper setup using setuptools.
I needed to bug python-dev with this, and finally got the right
hint from Holger Krekel who is absolutely right here - no point in
playing tricks, because this is all solved. And Pydica is about to
be prepared for PyPI, anyway.
My blocker was probably that Pydica is very much in development,
and I did not think right about it. The project does not need to be
ready in order to use setuptools!
My apologies, and many thanks again! This solved a Gordian Knot.
It is great when people help me to leave a dead-lock in my brain :-)
cheers - Chris
Christian Tismer :^) <mailto:tismer at stackless.com>
Software Consulting : Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/
14482 Potsdam : PGP key -> http://pgp.uni-mainz.de
phone +49 173 24 18 776 fax +49 (30) 700143-0023
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
More information about the Python-Dev