Search code examples
pythonpackagesetuptoolspypi

How to exclude a single file from package with setuptools and setup.py


I am working on blowdrycss. The repository is here.

I want the settings file for blowdrycss_settings.py to be excluded from the final package on pypi. The intention is to dynamically build a custom settings file that will be placed in the users virtualenv / project folder.

In setup.py, I have the following:

packages=find_packages(exclude=['blowdrycss_settings.py', ]),

I also tried exclude_package_data:

exclude_package_data={
    '': ['blowdrycss_settings.py'],
    '': ['blowdrycss/blowdrycss_settings.py'],
    'blowdrycss': ['blowdrycss_settings.py'],
},

I then run python setup.py sdist bdist.

However, when I look in the build folder I still see blowdrycss_settings.py:

- build 
    - lib
        - blowdrycss_settings.py

It seems like it should be simple to just exclude a file.

How do I exclude blowdrycss_settings.py from the distributed package?


Solution

  • Here is my solution.

    Underneath of blowdrycss, I created a new module called settings so the directory structure now looks like this:

    blowdrycss
        blowdrycss
            settings
                blowdrycss_settings.py
    

    Based on this reference, inside of setup.py I have the following:

    packages=find_packages(exclude=['*.settings', ]),   
    

    To build the distribution:

    1. Delete the build, dist, and .egg-info folders.
    2. Run python setup.py sdist bdist

    In retrospect, it is good that I was unable to do what I was originally attempting. The new structure feels cleaner and is more modular.