将Sphinx与distutils构建的C扩展一起使用

编程入门 行业动态 更新时间:2024-10-11 13:23:36
本文介绍了将Sphinx与distutils构建的C扩展一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我编写了一个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扩展一起使用

本文发布于:2023-11-17 09:09:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Sphinx   distutils

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!