我正在开发一个python包,我想提供自定义--install-option标志,以便在用户已经提供的情况下跳过一些安装步骤。
为此,我按照本主题中的说明进行操作:
How to obtain arguments passed to setup.py from pip with '--install-option'?
现在这最初似乎有效,但只是因为我在requirements.txt中的所有要求已经存在。
当我从干净安装重试它时,--install-option也会传播到依赖包的任何安装调用,然后无法安装。
在这种情况下,我的开关是--skipRLibraries。这是我用来安装软件包的命令:
pip install -vvv . --global-option="--skipRLibraries"
它会收集所有依赖项,并在开始安装时立即失败:
Installing collected packages: joblib, pysam, pybedtools, sortedcontainers, intervaltree, python-dateutil, pytz, numpy, pandas, biopython, Cython, slamdunk
Running setup.py install for joblib ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-OhpiVV/joblib/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" --skipRLibraries install --record /tmp/pip-0Ca3kV-record/install-record.txt --single-version-externally-managed --compile:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: option --skipRLibraries not recognized
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-OhpiVV/joblib/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" --skipRLibraries install --record /tmp/pip-0Ca3kV-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-OhpiVV/joblib/
这是我的安装命令扩展名:
from setuptools.command.install import install as _install
class install(_install):
user_options = _install.user_options + [
('externalNGM', None, None),
('externalSamtools', None, None),
('skipRLibraries', None, None)
]
def initialize_options(self):
_install.initialize_options(self)
self.externalNGM = None
self.externalSamtools = None
self.skipRLibraries = None
def finalize_options(self):
_install.finalize_options(self)
def run(self):
global externalNGM, externalSamtools
externalNGM = self.externalNGM
externalSamtools = self.externalSamtools
skipRLibraries = self.skipRLibraries
#from subprocess import call
#call(["pip install -r requirements.txt --no-clean"], shell=True)
_install.run(self)
self.execute(_runExternalBuilds, (self.install_lib, externalNGM, externalSamtools, skipRLibraries),msg="Installing external dependencies")
当然我把它添加到我的设置():
cmdclass={'install': install},
知道如何将标志限制为仅安装我的实际模块吗?
编辑:
我在Github的pip问题部分也讨论了这个问题:
https://github.com/pypa/pip/issues/1883
唯一的解决方案是首先安装包含所有要求的包,然后使用安装标志重新安装它: pip install foo pip install --no-deps --force-reinstall --upgrade --install-option =" - do-some-magic" FOO
但那是a)超级愚蠢和b)不适用于我的模块,因为默认情况下附带外部软件,并且交换机意味着跳过此外部模块的安装。所以我会在第一次安装它之前再次安装它。