Search code examples
pythonsetuptools

Python module: use during setup but not to be installed


How can I specify to Setuptools that a module should be available during setup, but not installed for run-time?

I have made an extension command used by my Python distribution (in this case it auto-generates version metadata), and the module is included in the project tree.

foo-project/
    setup.py
    MANIFEST.in
    foo/
        __init__.py
        bar.py
    version_info.py

To run Setuptools commands (such as egg_info or develop), the version_info module is imported by setup. So that file version_info.py needs to be part of the source distribution.

But putting that file in the source distribution also (by default?) automatically includes it in any binary distribution, such as bdist_wheel or bdist_dumb. That's wrong, because the file isn't needed at run-time and should not be installed.

How can I specify that the file is a Python module needed in the source distribution for setup commands, but not to be installed?


Solution

  • You can include source distribution files in the MANIFEST.in file; these files are included when building a source distribution that includes the setup.py file.

    Do not include the file in data_files or package_data or py_modules and it won't be included in the binary distribution (just like setup.py won't be).