How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespace collisions

ToddLMorgan at gmail.com ToddLMorgan at gmail.com
Thu Apr 20 11:26:25 EDT 2006


Summary:
How should multiple (related) projects be arranged (structured) and
configured so that the following is possible:
o	Sharing common code (one of the projects would be a "common"
project referenced by all others and likely the others would share at
least the common project and possibly more as times goes on)
o	Clear separation of "production" code and "test" code (ie to
readily ship source and test as separate components. Usually I'd do
that with separate hierarchies (src vs test folders)
o	Enabling the running of individual unittests and aggregated
testsuites
o	Avoiding namespace collisions - whilst still ensuring commonality
(or ownership) of the projects (ie common base package)

The longer version is detailed below which outlines my specific
problem.

I was hoping that someone could help me out with my python programming
dilemma.I am having a huge problem organising my python projects so
that the imports and from s to work correctly. I'm a Java/J2EE
developer by trade so I have a reasonable grasp of the fundamentals
regarding computer programming in general, but obviously not-so-good in
python. I have noted from my reading on the web that my Java skills may
actually be more of a hinderance - so feel free to tell me if I am
making any programming java in python mistakes.

I'm working on a few projects concurrently so I have tried to
arranged my projects like this:

COMMON
src
        a.b.c.common
test
	a.b.c.common

APP1
src
         a.b.c.app1
test
         a.b.c.app1

APP2
src
         a.b.c.app2
test
         a.b.c.app2


But it has not worked due to import/from issues. It appears that using
a common base package hierarchy (as is standard practice in the java
world) caused issues. Ie not able to use "a.b.c" as the base
package for all my projects, in order to avoid namespace collisions. I
attempted to resolve this by altering the packages to make the project
name as the base package. Ie the new packages were
·	common.a.b.c.common
·	app1.a.b.c.app1
·	app2.a.b.c.app2

My final problem is that I am not able to run my tests (unittest) as I
can't seem to find the right imports or froms to use that will work
for both from an aggregate (suite) test and the individual tests. I
have an individual AllTests.py at the root of the test folder and all
the appropriate __init__.pys in all the folders (to make them package
loaders). It appears to be that the directory from which the
AllTests.py is run is subverting the path/package hierarchy as it is
loaded first and is conflicting with my PYTHONPATH env variables (or I
am getting the python packaging and path totally wrong - which is
entirely possible).

So how should a project to be structured and configured to enable all
of these requirements? Any special requirements for the __init__.py,
PYTHONPATH, or other configuration tricks?

Thanks
      Todd




More information about the Python-list mailing list