loretoparisi
loretoparisi

Reputation: 16271

Using setuptools to copy non .py files

My python project installs via setup.py. The project structure looks like:

├── Makefile
├── README.rst
├── circle.yml
├── docs
│   ├── Makefile
│   ├── conf.py
│   ├── deps.txt
│   ├── guide_installation.rst
│   ├── guide_model.rst
│   ├── guide_transliteration.rst
│   ├── index.rst
│   ├── make.bat
│   └── module_trans.rst
├── indictrans
│   ├── __init__.py
│   ├── _decode
│   ├── _utils
│   ├── base.py
│   ├── iso_code_transformer.py
│   ├── libindic_
│   ├── mappings
│   ├── models
│   ├── polyglot_tokenizer
│   ├── script_transliterate.py
│   ├── test.py
│   ├── tests
│   ├── transliterator.py
│   ├── trunk
│   └── unicode_marks.py
├── requirements.txt
├── setup.cfg
├── setup.py
├── test-requirements.txt
└── tox.ini

where the subfolder indictrans/models looks like

├── ben-eng
│   ├── classes.npy
│   ├── coef.npy
│   ├── intercept_final.npy
│   ├── intercept_init.npy
│   ├── intercept_trans.npy
│   └── sparse.vec
├── ben-guj
│   ├── classes.npy
│   ├── coef.npy
│   ├── intercept_final.npy
│   ├── intercept_init.npy
│   ├── intercept_trans.npy
│   └── sparse.vec

so I have .npy and .vec files to be included in the project. In my setup.py I'm trying to explicitly include this folder models via the include_package_data directive like:

setup(
    setup_requires=['pbr'],
    pbr=True,
    packages=find_packages(),
    include_package_data=True,
    package_data={'models': ['*.npy','*.vec']},
    ext_modules=cythonize(extensions)
)

and in the setup.cfg I have

[files]
packages = 
    indictrans

but running python setup.py install does not copy the models folder to the installation folder /usr/local/lib/python2.7/dist-packages/indictrans/.

If I print the it is the output of the find_packages I get

['indictrans', 'indictrans.tests', 'indictrans.libindic_', 'indictrans._utils', 'indictrans._decode', 'indictrans.polyglot_tokenizer', 'indictrans.models', 'indictrans.trunk', 'indictrans.libindic_.utils', 'indictrans.libindic_.soundex', 'indictrans.libindic_.utils.tests', 'indictrans.libindic_.soundex.utils', 'indictrans.libindic_.soundex.tests', 'indictrans.libindic_.soundex.utils.tests', 'indictrans.polyglot_tokenizer.tests', 'indictrans.trunk.tests']

so I will assume that indictrans/models would be included, but it is not.

Upvotes: 4

Views: 2296

Answers (2)

Niklas Mertsch
Niklas Mertsch

Reputation: 1489

  1. Add include_package_data=True to your setup-function (you already did that).
  2. Create a file MANIFEST.in in the same directory as setup.py

MANIFEST.in can look as follows:

include indictrans/models/ben-eng/*
include indictrans/models/ben-guj/*

You don't need setup.cfg for doing this.

Source: This great writeup of python packaging

EDIT about recursive-include: According to the documentation this should also work:

recursive-include indictrans/models *.npy *.vec

Upvotes: 7

phd
phd

Reputation: 94425

include_package_data=True requires MANIFEST.in.

To include data for the module indictrans.models you have to provide the full name:

package_data={'indictrans.models': ['*.npy','*.vec']},

Upvotes: 3

Related Questions