Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

django

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.

like image 755
Nox Avatar asked May 25 '12 20:05

Nox


2 Answers

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'],
    ...
)
like image 190
Martijn Pieters Avatar answered Oct 11 '22 16:10

Martijn Pieters


You can use git archive to produce a zip file with the contents of the git repository (like it would in a fresh working directory). Then you can use those files to package the egg however you need to.

See: git archive

like image 42
Gavin H Avatar answered Oct 11 '22 17:10

Gavin H