扩展setuptools install命令,使用pip --user-options选项失败

时间:2016-05-03 14:04:48

标签: python pip options setuptools extends

我正在扩展python setup.py文件。添加一些额外的选项来决定安装哪个环境。

我像这样扩展了类“install”:

from setuptools.command.install import install

class BatchInstallCommand(install):
    user_options = install.user_options + [
        ('local', None, 'Local installation'),
        ('devel', None, 'Develpment installation')
    ]

    def initialize_options(self):
        install.initialize_options(self)
        self.local = None
        self.devel = None

    def finalize_options(self):
        install.finalize_options(self)
        assert (self.local or self.devel)

    def run(self):
        self.install_config_files()  # Install enviroment files
        install.run(self)

    def install_config_files(self):
         # function that install files depending the enviroment
         ...

这种方法可以正常使用setup.py安装并传递可选参数,如下所示:

$ python setup install --local

我想以相同的方式使用pip,使用pip参数传递可选参数--install-option,如下所示:

$ pip install --upgrade ./package --install-option="--local"

但它根本不起作用,因为pip将“--local”选项传递给所有包依赖项,并且这些包不知道这个自定义选项。所以我得到这样的错误:

  Running setup.py install for cryptography
  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 --local not recognized

使用--upgrade选项安装时会发生这种情况。如果我在一个全新的虚拟环境中安装我的软件包,pip可以毫无问题地安装软件包。

有什么建议吗?

0 个答案:

没有答案
相关问题