python - Directly call distutils' or setuptools' setup() function with command name/options, without parsing the command line? -


I want to call Python's distutils 'or setuptools' setup () function in a little unorthodox manner, but I'm not sure Does that mean distillates for such use?

For example, suppose there is currently a 'setup.py' file that looks like this (apathy has been raised literally from Docs - Setuptools is almost identical): distutils.core Import Setup Setup (name = 'distributes', version = '1.0', description = 'Python distribution utility', author = 'From Greg Ward

 ', Author_email='gward@python.net ', Url =' http: //www.python.org/sigs/distutils-sig/ ', packages = [' distutils', 'distutils.command'],)  

usually , Just to create .spec file for RPM of this module I can run python setup.py bdist_rpm --spec-only , which parses the command and calls the code 'bdist_rpm' to handle RPM-specific stuff .spec The file ends in './dist'.

How can I change my setup () invitation so that it executes 'bdist_rpm' command without '--spec-only' option, parsing command line parameters? Can I pass the command name and option as the parameters of setup? Or can I manually build a command line, and instead of passing it as a parameter?

Note: I already know that I can call the script in a different process using the OS with a real command line. System () or subprocess module or something similar. I am trying to avoid using any type of external command invoices. I am specifically looking for a solution that runs setup () in the current interpreter.

For the background, I am converting some release-management shell scripts into a Python program. One task 'setup.py' is going to create a SEPC file for further release testing. Running 'setup.py' as an external command with its own command line options looks like a strange method, and it makes the rest of the program complicated, I think there may be a more pensive way. .

It has never been created, but I see in Distutils / core.py, where I Setup () :

 Look at the beginning of  if 'script_name' is not in attrs: attrs ['script_name'] = Os.path.basename (sys.argv) [0]) If 'script_args' is not in attrs: attrs ['script_args'] = sys.argv [1:]  

So, it seems that you add " Out "Setup can add:

  Setup (... script_name = 'setup.py', script_args = ['bdist_rpm', '-spec -only'])  

Comments