[Python-Dev] Setting project home path the best way

Daniel Holth dholth at gmail.com
Fri Nov 16 04:22:27 CET 2012


Are you familiar with executing directories having __main__.py as python scripts?

Daniel Holth

On Nov 15, 2012, at 4:43 PM, Christian Tismer <tismer at stackless.com> wrote:

> Hi Kristjan,
> 
> does that mean that your scheme simply works, without any config step
> necessary after I did my checkout?
> This would in fact be an interesting alternative to 
> 
>    Python setup.py develop
> 
> but I'm not sure if this is the same scheme on windows and Os X. 
> 
> Getting this part right was rather tricky, and I fear this is still an issue. 
> 
> Right now I think to just force my users to run the install step, since it is quite
> accepted in general. 
> 
> Still, I'd love to see a way with no action needed at all: write yout your structure,
> and it works as-is. Seems to be impossible without tricks. 
> 
> Cheers - chris
> 
> Sent from my Ei4Steve
> 
> On Nov 15, 2012, at 10:17, Kristján Valur Jónsson <kristjan at ccpgames.com> wrote:
> 
>> When python is being run from a compile environment, it detects this by looking for "Lib" folders in directories above the one containing the executable. 
>> (I always thought that this "special" execution mode, hardwired in, was a bit odd, and suggested that this could be made a function of pep405)
>> Anyway, keeping your executable as part of the tree is the trick I use, and to make things nice I put  right next to it:
>> site.py
>> sitecustomize.py
>> 
>> sitecustomize.py is where you would put the logic to set sys.path by walking up the hierarchy and finding the proper root.
>> site.py is there to merely import sitecustomize.py, in case a site.py is not found in all the default places python looks.
>> 
>> K
>> 
>> 
>>> -----Original Message-----
>>> From: Python-Dev [mailto:python-dev-
>>> bounces+kristjan=ccpgames.com at python.org] On Behalf Of Christian Tismer
>>> Sent: 11. nóvember 2012 20:31
>>> To: python-dev at python.org
>>> Subject: [Python-Dev] Setting project home path the best way
>>> 
>>> Hi friends,
>>> 
>>> 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 '.'
>>> 
>>> Problem:
>>> 
>>> - 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. .
>>> 
>>> Question:
>>> 
>>> 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?
>>> 
>>> Reason:
>>> 
>>> 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?
>>> 
>>> Cheers - chris
>>> 
>>> Sent from my Ei4Steve
>>> _______________________________________________
>>> Python-Dev mailing list
>>> Python-Dev at python.org
>>> http://mail.python.org/mailman/listinfo/python-dev
>>> Unsubscribe: http://mail.python.org/mailman/options/python-
>>> dev/kristjan%40ccpgames.com
>> 
>> <winmail.dat>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/dholth%40gmail.com


More information about the Python-Dev mailing list