Search code examples
pythondjangopackagingsdist

python django webapp packaging sdist


When I run python setup.py sdist in my project directory and check the contents with tar --list -f .\dist\my_project_name-1.0.tar.gz I expected to see one important python file (manage.py) and a couple of directories such as templates which contains .html files, and static containing .css files. However, these files are all missing from the tar archive.

I've looked at many questions: Q1 Q2 Q3 Q4

but adding a MANIFEST.in or adding the following lines to my setup.py didn't change anything. And what about my manage.py? Shouldn't python files be included by default with sdist?

include_package_data=True,
data_files=[('templates','my_app/templates/my_app/*.html']),
            ('static', ['my_app/static/my_app/static/css/*.css'])]

Also, I get the same exact result with python setup.py sdist bdist_wheel (although I'm not sure what's the difference with the two commands).


Solution

  • what about my manage.py? Shouldn't python files be included by default with sdist?

    No, all python files won't be included by default. The other important part of your setup.py is the packages and py_modules keywords. You must specify all packages and subpackages and modules you want to include.

    In general, Django apps aren't distributed with the manage.py file, but if you want to include it, you can add py_modules=['manage'] to the setup keywords (assuming that manage.py is alongside setup.py).

    To get your built distributions to contain data files, like your templates and static files, your MANIFEST.in needs to include them. You should add entries like these:

    recursive-include my_app/templates *
    recursive-include my_app/static *
    

    The data_files keyword is not needed. Simply use include_package_data=True and it will respect your MANIFEST.in.

    Also, I get the same exact result with python setup.py sdist bdist_wheel

    sdist (source distribution) and bdist_wheel (wheel binary distribution) are just separate distribution formats.

    So, compared to the first command, you're just telling it to build the source distribution AND a wheel. Adding bdist_wheel doesn't modify how the source distribution is built.