4

I am trying to deliver a Django app via pip (stored on Pypi). The problem is that when I install the app with pip, it does not contain the static folder inside of the main specified package.

Here is what I have:

├── LICENSE.txt
├── MANIFEST.in
├── README.rst
├── setup.cfg
├── setup.py
└── zxcvbn_password
    ├── fields.py
    ├── __init__.py
    ├── static
    │   └── zxcvbn_password
    │       └── js
    │           ├── password_strength.js
    │           ├── zxcvbn-async.js
    │           └── zxcvbn.js
    ├── validators.py
    └── widgets.py

What I do is the following:

python setup.py register -r pypi
python setup.py sdist upload -r pypi

The tar archive is correctly created (it contains the static folder), and when I download this same archive from PyPi, it also contains the static folder. But installing it with pip just gives me the following in zxcvbn_password inside my site-packages:

└── zxcvbn_password
    ├── fields.py
    ├── __init__.py
    ├── validators.py
    └── widgets.py

This is how I write my setup.py:

from distutils.core import setup

setup(
    name='django-zxcvbn-password',
    packages=['zxcvbn_password'],
    include_package_data=True,
    url='https://github.com/Pawamoy/django-zxcvbn-password',
    # and other data ...
)

And my MANIFEST.in:

include LICENSE.txt
include README.rst
recursive-include zxcvbn_password/static *

Am I doing something wrong? Why the static folder is not installed when pip uses setup.py install?

Edit

I added the line of setup.py importing the setup function from distutils.
I get this warning when running python setup.py sdist upload -r pypitest:
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'include_package_data'

pawamoy
  • 3,382
  • 1
  • 26
  • 44
  • 1
    Not sure what cause this but have you tried ìnclude static` in the manifest. Also check out this: https://packaging.python.org/en/latest/distributing.html – Mikko Ohtamaa Mar 12 '15 at 19:54
  • 1
    Consider self-answering your question instead of adding your solution to the question. Here on SE, the goal is to provide a somewhat comprehensive QA archive. If you find a solution to your problem, self-answering is perfectly fine and encouraged as it may help others to find a solution to your question. – cel Mar 13 '15 at 10:53
  • Okay fine, I will do this, thanks for your explanation :) – pawamoy Mar 14 '15 at 12:19

1 Answers1

0

Solution with Distutils

# MANIFEST.in

include LICENSE.txt
include README.rst
# recursive-include zxcvbn_password/static *

and

# setup.py

from distutils.core import setup

setup(
    name='django-zxcvbn-password',
    packages=['zxcvbn_password'],
    package_data={'': ['static/zxcvbn_password/js/*.js']},
    # include_package_data=True,
    url='https://github.com/Pawamoy/django-zxcvbn-password',
    # and other data ...
)

I commented out the recursive-include line from MANIFEST.in and the include_package_data=True from setup.py: apparently they are not needed if you specify the package_data={...} line in setup.py.

Solution with Setuptools

# MANIFEST.in

include LICENSE.txt
include README.rst
recursive-include zxcvbn_password/static *

and

# setup.py

from setuptools import setup

setup(
    name='django-zxcvbn-password',
    packages=['zxcvbn_password'],
    include_package_data=True,
    url='https://github.com/Pawamoy/django-zxcvbn-password',
    # and other data ...
)

The only line that has changed is from setuptools import setup.

Conclusion

My problem was trully coming from the way I was importing the setup function. Reading this: Differences between distribute, distutils, setuptools and distutils2?, I understood that Setuptools has more functionality than Distutils.

Community
  • 1
  • 1
pawamoy
  • 3,382
  • 1
  • 26
  • 44