You can dynamically create the setuptools module and commit the values passed to setup :
>>> import imp >>> module = """ ... def setup(*args, **kwargs): ... print(args, kwargs) ... """ >>> >>> setuptools = imp.new_module("setuptools") >>> exec module in setuptools.__dict__ >>> setuptools <module 'setuptools' (built-in)> >>> setuptools.setup(3) ((3,), {})
After the above, you have the setuptools module with the setup function. You may need to create some more functions for all import operations to work. After that, you can import setup.py and compile the contents. This, as a rule, is a complicated approach, since setup.py can contain any Python code with conditional imports and dynamic calculations for passing setup() values.
source share