Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How include static files to setuptools - python package

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

# setup.py import os,glob from setuptools import setup,find_packages  setup(     name = "PotatoProject",     version = "0.1.1",     author = "Master Splinter",     author_email = "[email protected]",     description = ("The potatoproject!"),     url = 'http://www.google.com',     license = "BSD",      # adding packages     packages=find_packages('src'),     package_dir = {'':'src'},      # trying to add files...     include_package_data = True,     package_data = {         '': ['*.txt'],         '': ['static/*.txt'],         'static': ['*.txt'],     },      scripts=['src/startPotato'],     classifiers=[         "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?!

like image 779
joaoricardo000 Avatar asked Aug 07 '12 14:08

joaoricardo000


People also ask

How do I include a file in a Python package?

Place the files that you want to include in the package directory (in our case, the data has to reside in the roman/ directory). Add the field include_package_data=True in setup.py. Add the field package_data={'': [... patterns for files you want to include, relative to package dir...]} in setup.py .

How do I include non Python files in a package?

For non-python files to be included in an installation, they must be within one of the installed package directories. If you specify non-python files outside of your package directories in MANIFEST.in, they will be included in your distribution, but they will not be installed.

How do I import setuptools in Python?

Follow the below steps to install the Setuptools package on Linux using the setup.py file: Step 1: Download the latest source package of Setuptools for Python3 from the website. Step 3: Go to the setuptools-60.5. 0 folder and enter the following command to install the package.

Does Python include setuptools?

the setuptools is not part of the python vanilla codebase, hence not a vanilla modules. python.org installers or mac homebrew will install it for you, but if someone compile the python by himself or install it on some linux distribution he may not get it and will need to install it by himself.


1 Answers

As pointed out in the comments, there are 2 ways to add the static files:

1 - include_package_data=True + MANIFEST.in

A MANIFEST.in file in the same directory of setup.py that looks like this:

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

With include_package_data = True in setup.py.

2 - package_data in setup.py

package_data = {     'static': ['*'],     'Potato': ['*.txt'] } 

Specify the files inside the setup.py.


Do not use both include_package_data and package_data in setup.py.

include_package_data will nullify the package_data information.

Official docs:
https://setuptools.readthedocs.io/en/latest/userguide/datafiles.html

like image 129
joaoricardo000 Avatar answered Sep 18 '22 00:09

joaoricardo000