distutils: How to pass a user defined parameter to setup.py?

前端 未结 8 994
温柔的废话
温柔的废话 2020-11-30 21:32

Please prompt me how to pass a user-defined parameter both from the command line and setup.cfg configuration file to distutils\' setup.py script. I want to write a setup.py

8条回答
  •  时光说笑
    2020-11-30 22:19

    I successfully used a workaround to use a solution similar to totaam's suggestion. I ended up popping my extra arguments from the sys.argv list:

    import sys
    from distutils.core import setup
    foo = 0
    if '--foo' in sys.argv:
        index = sys.argv.index('--foo')
        sys.argv.pop(index)  # Removes the '--foo'
        foo = sys.argv.pop(index)  # Returns the element after the '--foo'
    # The foo is now ready to use for the setup
    setup(...)
    

    Some extra validation could be added to ensure the inputs are good, but this is how I did it

提交回复
热议问题