How to obtain arguments passed to setup.py from pip with '--install-option'?

前端 未结 5 1116
花落未央
花落未央 2020-12-03 04:57

I am using pip 1.4.1, attempting to install a package from a local path, for example:

pip install /path/to/my/local/package

This does what

5条回答
  •  长情又很酷
    2020-12-03 05:18

    You need to extend the install command with a custom command of your own. In the run method you can expose the value of the option to setup.py (in my example I use a global variable).

    from setuptools.command.install import install
    
    
    class InstallCommand(install):
        user_options = install.user_options + [
            ('someopt', None, None), # a 'flag' option
            #('someval=', None, None) # an option that takes a value
        ]
    
        def initialize_options(self):
            install.initialize_options(self)
            self.someopt = None
            #self.someval = None
    
        def finalize_options(self):
            #print("value of someopt is", self.someopt)
            install.finalize_options(self)
    
        def run(self):
            global someopt
            someopt = self.someopt # will be 1 or None
            install.run(self)
    

    Register the custom install command with the setup function.

    setup(
        cmdclass={
            'install': InstallCommand,
        },
        :
    

    It seems that the order of your arguments is off

    pip install /path/to/my/local/package --install-option="--someopt"

提交回复
热议问题