1

I'm kind of lost in all the locations you can add data files. First, there is the MANIFEST.in file. As I understand, this is only to specify source files to be included in "source distribution". Then, there is the data_files argument to setup() function, where you list files that should be installed, but it's from the root (either /, either ~user/.local). And finally, there is package_data that pretends to do what I want... But on a bdist, I don't see any difference with data_files

I have a data file, say "default_conf.cfg".

my MANIFEST.in contains :

include default_conf.cfg

and my setup.py :

setup(
  # ...
  package_data={
    '': ['default_conf.cfg'],
  }
)

When I do a ./setup.py sdist, the file is included, same with ./setup.py bdist (as expected)

However, if I try to install as editable package (pip install --user -e .), I can't access it with pkg_resources.resource_string(__name__, 'default_conf.cfg')

What am I missing to be able to access it from any kind on distribution/install ?

(The documentation is quite verbose, and information are dispersed across several pages so it's easy to miss something.)

EDIT

I put my data file as a subdir of my module and it seems to be better :

my_pkg/
|-my_pkg/
| |-__init__.py
| |-data/
| | |-default_conf.cfg
| 
|-setup.py

setup.py :

setup(
  # ...
  package_data={
    'my_module': ['data/default_conf.cfg'],
  }
)

However, when I try to pip install --user -e ., the content of the .egg-link is /.../my_pkg/build/lib instead of /.../my_pkg, then of course, it is not live-editable... Why does setuptools use this path ?

hl037_
  • 3,520
  • 1
  • 27
  • 58
  • What is `pkg_resource`? – hoefling Jul 12 '18 at 10:14
  • https://setuptools.readthedocs.io/en/latest/pkg_resources.html The "standard way" to access resources (normally) – hl037_ Jul 12 '18 at 11:39
  • well, there was a copy-paste typo, now, I corrected the call to `resource_string` – hl037_ Jul 12 '18 at 11:45
  • 1
    Your `package_data` is now correct, so it should work. First of all, try cleaning up: `pip uninstall -y mypkg`, delete `build` and `mypkg.egg-info` dirs in the project dir, then rerun `pip install --editable .`. If this doesn't help, check whether you have an unnecessary `__init__.py` in your project dir and remove it. – hoefling Jul 12 '18 at 12:48
  • what do you mean by "unnecessary `__init__.py" ? because I effectively have an empty `__init__.py` because I have only submodule – hl037_ Jul 12 '18 at 13:24
  • btw, I created another question to complete this one : https://stackoverflow.com/questions/51306780/when-does-setuptools-install-editable-link-to-my-module-build-lib-andwhen – hl037_ Jul 12 '18 at 13:25
  • I meant, if the error is not resolved by clean rebuild, check if you have an `__init__.py` file in the same dir your `setup.py` is, often it's a source for errors where the `build` dir is added to python path. The project structure you've shown in the post looks good. – hoefling Jul 12 '18 at 13:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/174887/discussion-between-hl037-and-hoefling). – hl037_ Jul 12 '18 at 13:34

1 Answers1

0

The edit actually answers the question. The install editable problem was caused by a py2to3 step that was by default in my setup.py template.

hl037_
  • 3,520
  • 1
  • 27
  • 58