Code Management
BlueBird
phil at freehackers.org
Sat Nov 24 05:50:42 EST 2007
On Nov 21, 7:05 am, "Sergio Correia" <sergio.corr... at gmail.com> wrote:
> As a side note, I find much easier to drop a PTH file than messing
> with pythonpath. If you are not familiar with PTH files, what I do is
> this
>
> 1) Go to "C:\Program Files\Python25\Lib\site-packages" or whatever is
> appropiate in your case.
> 2) Create a text file, name it something like "MyProjects.PTH" (note
> the extension!)
> 3) in the file, just write the path of the folder that contains all
> your projects (in my case, C:/docs/python)
>
> The idea is to keep the main python installation separated from the
> modules you are currently developing. Your python installation goes to
> "program files/python" or "bin/python", and your personal projects go
> somewhere else (usually inside your 'user' folder). This smooths many
> things, like working with different versions of a package you are
> developing.
>
Hi,
If I understand you correctly, you have the following directory
organisation
[Python installation]/site-packages/[MyProject.pth pointing to /home/
user/python-dev/]
And then you do your development in python-dev. But how do you manage
multiple development branches of the same program ?
My directory structure looks like this:
python-dev:
+ prog-branch1/
| + foo
| | + foo.py
| | + tests
| | + test_foo.py
| + bar
| + bar.py
| + tests
| + test_bar.py
+ prog-branch2/
+ foo
| + foo.py
| + tests
| + test_foo.py
+ bar
+ bar.py
+ tests
+ test_bar.py
bar/bar.py needs to import symbols from foo/foo.py . And bar/tests/
test_bar.py needs some symbols from both bar/bar.py and foo/foo.py
I don't understand how having python-dev in the .pth file solves the
problem.
In my case, I make all my imports relative to the root of my project:
bar/bar.py:
from foo.foo import some_foo
bar/tests/test_bar.py
from foo.foo import some_foo
from foo.bar import some_bar
The way I managed to make it work is by extending sys.path but I would
be happy to find a better solution:
bar/bar.py is actually:
import os, sys
sys.path.append( '..')
from foo.foo import some_foo
and bar/tests/test_bar.py is actually:
import os, sys
sys.path.append( os.path.join('..','..') )
from foo.foo import some_foo
from foo.foo import some_bar
What is not nice with this method is that every runnable test script
must extend unconditionally the sys.path . That creates some clutter.
Philippe
More information about the Python-list
mailing list