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
A quick and easy way similar to that given by totaam would be to use argparse to grab the -foo argument and leave the remaining arguments for the call to distutils.setup(). Using argparse for this would be better than iterating through sys.argv manually imho. For instance, add this at the beginning of your setup.py:
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('--foo', help='required foo argument', required=True)
args, unknown = argparser.parse_known_args()
sys.argv = [sys.argv[0]] + unknown
The add_help=False
argument means that you can still get the regular setup.py help using -h
(provided --foo
is given).