为Python软件包使用`--global-option`指定建立时间的依赖性 [英] Specify setup time dependency with `--global-option` for a python package
问题描述
我正在尝试打包一个具有建立时(以及运行时)依赖项的python库:它import
是模块,以便这些模块可以将某些提供的C头文件的位置通知安装过程:
I'm trying to package a python library that has setup-time (and also run-time) dependencies: it import
s the modules so that the modules can inform the setup process of the location of some provided C headers:
from distutils.extension import Extension
from pybedtools.helpers import get_includes as pybedtools_get_includes
from pysam import get_include as pysam_get_include
# [...]
extensions = [
Extension(
"bam25prime.libcollapsesam", ["bam25prime/libcollapsesam.pyx"],
include_dirs=pysam_get_include()),
Extension(
"bam25prime.libcollapsebed", ["bam25prime/libcollapsebed.pyx"],
include_dirs=pybedtools_get_includes(),
language="c++"),
]
# [...]
但是,其中一个依赖项(pybedtools
)需要使用特定的--global-option
pip选项进行安装(请参阅文章末尾,如果不提供该选项,会发生什么情况.)
However, one of the dependencies (pybedtools
) needs to be installed with a specific --global-option
pip option (see at the end of the post what happens when the option is not provided).
如果我理解正确,那么在使用setup.py
之前自动具有一些依赖关系的最新方法是在pyproject.toml
文件的[build-system]
部分中指示它们.
If I understand correctly, the currently up-to-date way to automatically have some dependencies available before setup.py
is used is to indicate them in the [build-system]
section of a pyproject.toml
file.
我尝试了以下pyproject.toml
:
[build-system]
requires = [
"pysam",
"pybedtools @ git+https://github.com/blaiseli/pybedtools.git@fix_missing_headers --global-option='cythonize'",
]
build-backend = "setuptools.build_meta"
(顺便说一句,我花了很多时间弄清楚如何指定build-backend
,该文档不容易发现.)
(By the way, it took me quite some time to figure out how to specify the build-backend
, the documentation is not easily discoverable.)
但是,这会在pip install
上产生以下错误:
However, this generates the following error upon pip install
:
ERROR: Invalid requirement: "pybedtools @ git+https://github.com/blaiseli/pybedtools.git@fix_missing_headers --global-option='cythonize'"
Hint: It looks like a path. File 'pybedtools @ git+https://github.com/blaiseli/pybedtools.git@fix_missing_headers --global-option='cythonize'' does not exist.
如何正确指定依赖项选项?
如果仅指定软件包及其URL("pybedtools @ git+https://github.com/blaiseli/pybedtools.git@fix_missing_headers
),安装将失败,如下所示:
If I simply specify the package and its URL ("pybedtools @ git+https://github.com/blaiseli/pybedtools.git@fix_missing_headers
), the install fails as follows:
Exception:
Cython-generated file 'pybedtools/cbedtools.cpp' not found.
Please install Cython and run
python setup.py cythonize
正是在尝试解决上述错误时,我发现了有关--global-option
pip选项的信息.
我可以手动运行pip install --global-option="cythonize" git+https://github.com/blaiseli/pybedtools.git@fix_missing_headers
,并且只要安装了该软件包的依赖项,安装就可以进行,否则由于无法识别的"cythonize"
选项(
It was while trying to tackle the above error that I found out about the --global-option
pip option.
I can manually run pip install --global-option="cythonize" git+https://github.com/blaiseli/pybedtools.git@fix_missing_headers
, and the install works, provided the dependencies of that package are already installed, otherwise their install fails because of an unrecognized "cythonize"
option (which is another issue...).
请注意,仅当从源安装时才需要此选项(例如,从github上的fork安装时,如我的情况).
Note that this option is only needed when installing "from source" (for instance when installing from a fork on github, as is my case here).
推荐答案
与您其他问题怀疑cythonize
是 setuptools 命令,而不是 global选项.
Same thing as in your other question, I suspect cythonize
is a setuptools command and not a global option.
如果确实如此,那么最好在setup.cfg
中设置一个别名.如果运行python setup.py alias install cythonize install
,则应将以下内容添加到setup.cfg
:
If it's indeed the case, then you would be better off setting an alias in your setup.cfg
. If you run python setup.py alias install cythonize install
, this should add the following to your setup.cfg
:
[aliases]
install = cythonize install
稍后运行pip install
时, pip 将使用此别名,并且cythonize
命令将在install
命令之前执行.
When running pip install
later, pip will honor this alias and the cythonize
command will be executed right before the install
command.
这篇关于为Python软件包使用`--global-option`指定建立时间的依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!