How to work on a package

Roel Schroeven roel at roelschroeven.net
Tue Feb 6 16:44:48 EST 2018


I'm fairly comfortable writing Python code, but I only have experience 
writing scripts with perhaps a few supporting modules. Now I want to 
start writing a package, and I'm feeling a bit helpless: I'm not sure 
how to organize my work.

In my way of thinking, I would have a working tree for the package (or 
even more than one), and also an installed version (once version 0.1 or 
so is ready).

For example, let's say I'm working on luaparser 
(https://github.com/boolangery/py-lua-parser). There are tests in 
directory luaparser/tests, and I want to execute those tests. So I 
execute, for example:

$ python3 -m unittest test_ast.py

But that doesn't work:

E
======================================================================
ERROR: test_ast (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_ast
Traceback (most recent call last):
   File "/usr/lib/python3.5/unittest/loader.py", line 153, in 
loadTestsFromName
     module = __import__(module_name)
   File "/home/roel/temp/py-lua-parser/luaparser/tests/test_ast.py", 
line 1, in <module>
     from luaparser.utils  import tests
ImportError: No module named 'luaparser'


The test tries to import the global luaparser package (beause they use 
absoluate imports, which is the recommended way if I understand 
correctly), but that's not what I want: I want to test the local version 
in my working tree.

I guess I could use something like

$ PYTHONPATH=../.. python3 -m unittest test_ast.py

but it feels like there should be a better way than manually specifying 
the module search path.

How do people usually do this? Is there maybe a guide that explains the 
practical side of writing packages?

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

Roel Schroeven




More information about the Python-list mailing list