[py-dev] Local import

Joan Miller peloko45 at gmail.com
Sat Jan 23 14:45:13 CET 2010


I was wrong since that it isn't necessary to import the source from
tests. It's better to use 'python setup.py develop' because it manages
well this problem.

"When you're installing a distribution, you can install it in develop
mode instead with python setup.py develop. Using this mode, a special
link file is created in your site-packages directory. This link points
back to the current folder or 'root package'. Any changes you make to
the software here will be reflected immediately without having to do
an install again.

When you're ready to install for good do a real install."

http://www.siafoo.net/article/77#install-vs-develop


2009/12/23 holger krekel <holger at merlinux.eu>:
> On Wed, Dec 23, 2009 at 13:28 +0000, Joan Miller wrote:
>> I'm using the next function to access to the source from tests without
>> install it (python setup.py develop). It's very usefull during
>> development so it could be added to py.
>
> If you use 'python setup.py develop' you should be able to
> import your package that you are currently working on already.
>
> Can you post an example how and from which file you use
> the posted function?
>
> cheers,
> holger
>
>
>> ------------------------
>> import os
>> import sys
>>
>> def import_local(parent='test', child='lib'):
>>     """Inserts local library on 'sys.path'.
>>
>>     Goes up until the root of the project (upper of 'parent' directory)
>>     and inserts the 'child' directory.
>>     """
>>     parent_path = os.path.abspath(os.path.dirname(__file__))
>>
>>     while parent in os.path.basename(parent_path):
>>         parent_path = os.path.dirname(parent_path)
>>
>>     sys.path.insert(0, os.path.join(parent_path, child))
>> ------------------------
>> _______________________________________________
>> py-dev mailing list
>> py-dev at codespeak.net
>> http://codespeak.net/mailman/listinfo/py-dev
>>
>
> --
>



More information about the Pytest-dev mailing list