question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] `[options.package_data]` in setup.cfg does nothing

See original GitHub issue

setuptools version

57.0.0

Python version

3.9.5

OS

Arch

Additional environment information

No response

Description

I have this project: https://gitlab.com/greyltc/runpanel/-/tree/a93fac114f5443dc5ae55b9a8eb395b3244e282b

It has a setup.cfg file with

[options]
include_package_data = True

and

[options.package_data]
runpanel = *.yaml

As you can see from the repo there, there’s a system_config.yaml file present that I expect to be included as package data. But after I install the package, and run

import importlib.resources
list(importlib.resources.contents('runpanel'))

I get only ['__pycache__', '__init__.py', '__main__.py', 'app.py', 'sysdbus.py']. There’s no yaml file.

Expected behavior

I expect that when I follow the packaging docs for including package_data files here: https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html?highlight=package_data that data should make it into my package.

How to Reproduce

  1. Install my project here https://gitlab.com/greyltc/runpanel/-/tree/a93fac114f5443dc5ae55b9a8eb395b3244e282b
  2. Notice that there are no .yaml package data files included

Output

$ ipython
In [1]: import importlib.resources
   ...: list(importlib.resources.contents('runpanel'))
Out[1]: ['__pycache__', '__init__.py', '__main__.py', 'app.py', 'sysdbus.py']

Code of Conduct

  • I agree to follow the PSF Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
abravalhericommented, Jan 17, 2022

Ah, I see, I missed that the files have to be in the package folder. I’ll stick to MANIFEST.in then.

Sorry if that is confusing in the docs: https://setuptools.pypa.io/en/latest/userguide/datafiles.html

Both include_package_data and package_data will only work with files inside the package directory (not the root of the project).

1reaction
kwinkunkscommented, Feb 1, 2022

Thank you very much for this explanation, and thanks for everything you’re doing to make packaging easier.

Re the docs, at the top of the page it says this:

First, you can simply use the include_package_data keyword […] This tells setuptools to install any data files it finds in your packages. The data files must be specified via the distutils MANIFEST.in file.

But that did not work for me. The only thing that worked, and it worked on its own (without either include_package_data or MANIFEST.in), was options.package_data.

I am using only setup.cfg, with only the package name being set in setup.py, so I’m not 100% certain I’m mapping the advice on this page (which all seems to use setup()) to my situation.

I need to look at setuptools_scm… I have not been paying attention to it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - How to include package data with setuptools/distutils?
Starting with setuptools 30.3.0 (released 2016-12-08), you can keep your setup.py very small and move the configuration to a setup.cfg file.
Read more >
setup.py vs setup.cfg in Python - Towards Data Science
cfg is an ini file, containing option defaults for setup.py commands. You can pretty much specify every keyword we used in the setup.py...
Read more >
Data Files Support - Setuptools - Python Packaging Authority
However, only mypkg1 has .rst data files. In such a case, if you want to use the package_data option, the following configuration will...
Read more >
Simple documentation for setup.cfg - Discussions on Python.org
I was using “data files” as a generic term, just meaning “files containing data which my package needs”. It looks like I need...
Read more >
A Practical Guide to Using Setup.py - GoDataDriven
using pip install scikit-learn , while you use it by importing from sklearn . The version of your package. This is the version...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found