4

I write and maintain a Python library for quantum chemistry calculations called PyQuante. I have a fairly standard Python distribution with a setup.py file in the main directory, a subdirectory called "PyQuante" that holds all of the Python modules, and one called "Src" that contains source code for C extension modules.

I've been lucky enough to have some users donate code that uses Cython, which I hadn't used before, since I started PyQuante before either it or Pyrex existed. On my suggestion, they put the code into the Src subdirectory, since that's where all the C code went.

However, looking at the code that generates the extensions, I wonder whether I should have simply put the code in subdirectories of the Python branch instead. And thus my question is:

what are the best practices for the directory structure of python distributions with both Python and Cython source files?

  • Do you put the .pyx files in the same directory as the .py files?
  • Do you put them in in a subdirectory of the one that holds the .py files?
  • Do you put them in a child of the .py directory's parent?

Does the fact that I'm even asking this question betray my ignorance at distributing .pyx files? I'm sure there are many ways to make this work, and am mostly concerned with what has worked best for people.

Thanks for any help you can offer.

4

1 回答 1

2

将 .pyx 文件与 .py 文件放在同一目录中对我来说最有意义。这是scikit-learn的作者所做的,也是我在我的py-earth模块中所做的。我想我认为 Cython 模块是 Python 模块的优化替代品。我通常会从用纯 Python 编写一个包开始,然后如果我需要更好的性能,用 Cython 替换一些模块。由于我将 Cython 模块视为 Python 模块的替代品,因此将它们放在同一个位置对我来说是有意义的。它也适用于使用 --inplace 参数的测试构建。

于 2013-06-03T20:41:12.823 回答