tags:

views:

127

answers:

1

We have numerous projects in our organization that are mixed Python/C. Currently we're trying to standardize on a directory layout for our projects and are trying to come up with a convenient scheme. One point of contention is where to put C extension modules in the tree.

We're tossing around a couple of options (relative to project root):

./src/package/subpackage/module.c

or alongside the python modules in the package tree:

./package/subpackage/module.c

or in a src directory in the subpackage:

./package/subpackage/src/module.c

One reason for keeping them out of the package directories could be because it will lead to clutter, especially if there are other .c and .h files which aren't themselves modules but still need to be compiled. Also in the "integrated" scheme, what do you do with headers and files that are used by more than one module? Put them in a common top-level directory?

I'd be interested to know what other people are using, or if there are any established best practices for this.

+1  A: 

I think the layout of the Python standard library is a reasonable example: under trunk, which is basically the root for the SVN repo (net of branches &c), the Modules directory has a lot of .c and .h files, the Lib directory a lot of .py files.

In my own projects I tend to divide sources up similarly (and actually if I have Cython or Pyrex ones, or SWIG etc, I tend to have other directories yet for subdivision), though with different directory names (I confess I don't have a consistent rule for the directory names themselves, nor have I ever heard of good guidelines for such names).

Alex Martelli
I did look at the Python standard library, and I'm not convinced it's a good example. Mostly because a lot of decisions of the organization were made way back and may not reflect all the stuff currently in use.I guess if I were to go down this route, I'd need a build script that then collects the modules from all different locations and puts them in a final package directory for testing or deployment?
Kamil Kisiel