我编写了一个Python模块,其中包括一个用C编写的子模块:该模块本身称为 foo ,而C部分为 foo._bar 。结构如下:
I have written a Python module including a submodule written in C: the module itself is called foo and the C part is foo._bar. The structure looks like:
src/ foo/__init__.py <- contains the public stuff foo/_bar/bar.c <- the C extension doc/ <- Sphinx configuration conf.py ...foo / __ init __。py 进口 _bar 进行增强,并且有用的内容在 foo 模块中公开。生成时此方法工作正常,但显然不能以未编译的形式工作,因为 _bar 在生成之前不存在。
foo/__init__.py imports _bar to augment it, and the useful stuff is exposed in the foo module. This works fine when it's built, but obviously won't work in uncompiled form, since _bar doesn't exist until it's built.
我想使用Sphinx记录项目,并使用 foo 模块上的= nofollow noreferrer> autodoc 扩展。这意味着我需要先构建项目,然后再构建文档。
I'd like to use Sphinx to document the project, and use the autodoc extension on the foo module. This means I need to build the project before I can build the documentation.
由于我是使用distutils进行构建的,因此构建的模块最终以一些名为dir build / lib.linux-ARCH-PYVERSION —这意味着我不能仅仅将目录硬编码到Sphinx的 conf.py 。
Since I build with distutils, the built module ends up in some variably named dir build/lib.linux-ARCH-PYVERSION — which means I can't just hard-code the directory into a Sphinx' conf.py.
那么我该如何配置distutils setup.py 脚本,以在构建的模块上运行Sphinx构建器?
So how do I configure my distutils setup.py script to run the Sphinx builder over the built module?
为了完整起见,这是对 setup 的调用(假东西是子类 build 和 build_ext ):
For completeness, here's the call to setup (the 'fake' things are custom builders that subclass build and build_ext):
setup(cmdclass = { 'fake': fake, 'build_ext_fake' : build_ext_fake }, package_dir = {'': 'src'}, packages = ['foo'], name = 'foo', version = '0.1', description = desc, ext_modules = [module_real])推荐答案
既然distutils可以弄清楚变量的构建路径,为什么不直接使用它呢?
Since distutils has a way of figuring out the variable build path, why not just use it?
import distutilsmand.build from distutils.dist import Distribution b = distutilsmand.build.build(Distribution()) b.initialize_options() b.finalize_options() print b.build_temp # If you're building a library, you might need: print b.build_lib # Other values of interest are: b.build_purelib b.build_platlib b.build_scripts b.build_base即使distutils文档稀疏,在这里您可以找到一线关于那里的建筑类型。
Even thought the distutils docs are sparse, here you'll find one-liners about what kinds of build are there.
更多推荐
将Sphinx与distutils构建的C扩展一起使用
发布评论