Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory layout for a Python project with C extension modules

Tags:

python

c

module

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.

like image 546
Kamil Kisiel Avatar asked Mar 19 '10 21:03

Kamil Kisiel


1 Answers

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).

like image 167
Alex Martelli Avatar answered Oct 05 '22 10:10

Alex Martelli