Search code examples
pythondjangoegg

How can I exclude files in my .gitignore when packaging a Python egg?


I'm packaging my first Django app and I want to leave out my settings_local.py file from the egg. Ideally I'm looking for a way to just have everything in my .gitignore file also excluded from the egg.

I've tried the following variations in my MANIFEST.in file (one per egg creation attempt):

prune project_name settings_local.py
prune project_name/settings_local.py
exclude project_name settings_local.py
exclude project_name/settings_local.py

I also tried adding the following line to my startup.py file (at the recommendation of a friend):

exclude_package_data= {'': 'settings_local.py'},

Any suggestions would be very much appreciated.


Solution

  • Don't use a MANIFEST.in but use setuptools-git instead; with that package all files included in your git repository will also be part of the egg, and any files listed in .gitignore will not be.

    I have the package installed globally, in my python's site-packages, but it should be enough to list it in your setup.py in the setup_requires structure:

    setup(...
        setup_requires=['setuptools-git'],
        ...
    )