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

前端 未结 5 1120
花落未央
花落未央 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 05:29

    It works well and also documented.

    from setuptools.command.install import install
    
    class InstallCommand(install):             
        user_options = install.user_options + [
            ('engine=', None, ''),
        ]                                      
    
        def initialize_options(self):          
            install.initialize_options(self)   
            self.engine = None  
    
        def finalize_options(self):                   
            print("value of engine is", self.engine)
            install.finalize_options(self)            
    
        def run(self):                                
            print(self.engine)                       
            install.run(self)                         
    
    setup(
    ...
    cmdclass={'install': InstallCommand}
    ...
    )
    

    One of common mistakes is to pass setup options to pip like you pass it to setup directly. Use options from pip like that:

    pip install . --install-option="--engine=rabbitmq"
    

    But this way is a wrong way:

    pip install . --install-option="--engine rabbitmq"
    

    Absence of equal sign causes well known error:

    error: option --engines rabbitmq not recognized

提交回复
热议问题