JRicardo000 JRicardo000 - 2 years ago 122
Python Question

How include static files to setuptools - python package

It's impossible to include static files! I tried everything that I've found in tutorials and the documentation, but all in vain...

I want to include the ./static/data.txt, there is my code:

# setup.py
import os,glob
from setuptools import setup,find_packages

name = "PotatoProject",
version = "0.1.1",
author = "Master Splinter",
author_email = "splinter@initech.com",
description = ("The potatoproject!"),
url = 'http://www.google.com',
license = "BSD",

# adding packages
package_dir = {'':'src'},

# trying to add files...
include_package_data = True,
package_data = {
'': ['*.txt'],
'': ['static/*.txt'],
'static': ['*.txt'],

"Development Status :: 3 - Alpha",
"Topic :: Utilities",
"License :: OSI Approved :: BSD License",

the file system:

├── setup.py
└── src
├── distutils_setup.py
├── Potato
│   ├── __init__.py
│   ├── potatoData.txt
│   └── printer.py
├── startPotato
├── static
│   └── data.txt
└── Tomato
├── big.py
└── __init__.py

the output when running:
$ python setup.py sdist

running sdist
running egg_info
creating src/PotatoProject.egg-info
writing src/PotatoProject.egg-info/PKG-INFO
writing top-level names to src/PotatoProject.egg-info/top_level.txt
writing dependency_links to src/PotatoProject.egg-info/dependency_links.txt
writing manifest file 'src/PotatoProject.egg-info/SOURCES.txt'
reading manifest file 'src/PotatoProject.egg-info/SOURCES.txt'
writing manifest file 'src/PotatoProject.egg-info/SOURCES.txt'
warning: sdist: standard file not found: should have one of README, README.txt

creating PotatoProject-0.1.1
creating PotatoProject-0.1.1/src
creating PotatoProject-0.1.1/src/Potato
creating PotatoProject-0.1.1/src/PotatoProject.egg-info
creating PotatoProject-0.1.1/src/Tomato
making hard links in PotatoProject-0.1.1...
hard linking setup.py -> PotatoProject-0.1.1
hard linking src/startPotato -> PotatoProject-0.1.1/src
hard linking src/Potato/__init__.py -> PotatoProject-0.1.1/src/Potato
hard linking src/Potato/printer.py -> PotatoProject-0.1.1/src/Potato
hard linking src/PotatoProject.egg-info/PKG-INFO -> PotatoProject-0.1.1/src/PotatoProject.egg-info
hard linking src/PotatoProject.egg-info/SOURCES.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info
hard linking src/PotatoProject.egg-info/dependency_links.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info
hard linking src/PotatoProject.egg-info/top_level.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info
hard linking src/Tomato/__init__.py -> PotatoProject-0.1.1/src/Tomato
hard linking src/Tomato/big.py -> PotatoProject-0.1.1/src/Tomato
Writing PotatoProject-0.1.1/setup.cfg
creating dist
Creating tar archive
removing 'PotatoProject-0.1.1' (and everything under it)

and no txt added! No static/data.txt nor Potato/potatoData.txt...

What am I missing?!

Answer Source

Just added a MANIFEST.in in the same directory of setup.py, that looks like this:

include src/static/*
include src/Potato/*.txt

and It worked (:

I do not know if this is the best way out, looks like that the setup.py should do this by itself, but worked anyway...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download