[py-dev] Local import

holger krekel holger at merlinux.eu
Wed Dec 23 15:42:16 CET 2009


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