The reusable app docs (https://docs.djangoproject.com/en/1.9/intro/reusable-apps/) tells you to list template and static files in MANIFEST.in
, but it doesn't look like python setup.py bdist_wheel
looks at that file at all.
I've seen references to data_files
but those files go in directories relative to the python installation (sys.prefix
) and not the package installation (and sys.prefix
isn't uniformly related to site-packages
across systems).
Am I correct in assuming that myapp/templates/myapp/foo.html
should end up in .../site-packages/myapp/templates/myapp/foo.html
and similarly for static files, and that the user needs to run a manage.py collectstatic
after pip install myapp
?
Update (example):
The following structure:
(build2) go|c:\srv\tmp\myapp> tree
.
|-- MANIFEST.in
|-- myapp
| |-- static
| | `-- myapp
| | `-- foo.css
| |-- templates
| | `-- myapp
| | `-- foo.html
| |-- urls.py
| `-- views.py
`-- setup.py
5 directories, 6 files
setup.py
import setuptools
from distutils.core import setup
setup(
name='myapp',
version='0.1.0',
packages=['myapp']
)
MANIFEST.in
recursive-include myapp/templates *
recursive-include myapp/static *
running python setup.py sdist
and python setup.py bdist_wheel
creates the following files bin myapp/dist:
2016-06-18 13:47 2,073 myapp-0.1.0-py2-none-any.whl
2016-06-18 13:46 2,493 myapp-0.1.0.zip
if you look inside the .zip file, you'll find the templates and static folders, if you rename the .whl file to .zip and look inside it, the directories are not included.
Update 2 (solution):
Changing the MANIFEST.in file to
recursive-include myapp *
and setup.py to
from setuptools import find_packages, setup
setup(
name='myapp',
version='0.1.0',
include_package_data=True,
packages=['myapp'],
zip_safe=False,
)
then running python setup.py bdist_wheel
will create a .whl
file that installs myapp/templates
and myapp/static
in the expected places.
What Is a Python Wheel? A Python . whl file is essentially a ZIP ( . zip ) archive with a specially crafted filename that tells installers what Python versions and platforms the wheel will support. A wheel is a type of built distribution.
The MANIFEST.in
file needs to be changed to:
recursive-include myapp *
This includes everything under myapp/myapp
with the correct paths. In particular, this includes myapp/myapp/templates
, which is necessary.
The declaration above also includes myapp/myapp/static
which could be useful if you plan to run manage.py collectstatic
after installing the .whl
file.
In setup.py
, the setup
function needs to be imported from setuptools
(and not distutils), i.e.:
from setuptools import find_packages, setup
setup(
name='myapp',
version='0.1.0',
include_package_data=True,
packages=['myapp'],
zip_safe=False,
)
When you now run python setup.py bdist_wheel
it will create a .whl
file that installs myapp/templates
and myapp/static
in the expected places.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With