1

Given this directory structure (empty __init__.py and logging.yml is fine):

foo
│   setup.py
│
└─── foo
     │   __init__.py
     │
     └─── config
              logging.yml

Here is my attempt, this setup.py:

from os import path
from setuptools import find_packages, setup

package_name = "foo"


if __name__ == "__main__":
    setup(
        name=package_name,
        packages=find_packages(),
        package_dir={package_name: package_name},
        package_data={"config":[path.join(package_name, "config", "logging.yml")]},
        include_package_data=True,
    )

# Also tried:
# package_data={"config": [path.join("config", "logging.yml")]}
# package_data={"": [path.join("config", "logging.yml")]}
# package_data={"": [path.join(package_name, "config", "logging.yml")]}

No errors after a python setup.py install (also tried python -m pip install .), but running from my virtualenv root fd -HIFuuueyml logging returns no results and it's absent from foo.egg-info\SOURCES.txt.

PS: Testing locally with 3.13.0a5; setuptools 69.2.0; pip 24.0. But on my CI test & release to 2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 across Windows, Linux and macOS.

3
  • That part is wrong regardless of package data: package_dir={package_name: package_name}. See the docs at setuptools.pypa.io/en/latest/userguide/package_discovery.html . With your dir structure you don't need package_dir at all; my advice is to remove the line. Commented Mar 30, 2024 at 13:08
  • With package_data={"config":… you declare that config is a package. But it isn't. So the answer for the question in the title is: no. Again, the docs: setuptools.pypa.io/en/latest/userguide/datafiles.html Commented Mar 30, 2024 at 13:10
  • @phd - In my comment I specify the other ways I did package_data. I'll try removing package_dir and see if that fixes this. EDIT: Nope, that didn't work either. Tried all permutations of package_data enumerated in my question. Commented Mar 30, 2024 at 15:01

1 Answer 1

1

This works:

from setuptools import find_packages, setup

package_name = "foo"


if __name__ == "__main__":
    setup(
        name=package_name,
        packages=find_packages(),
        package_data={"foo": ["config/logging.yml"]},
        include_package_data=True,
    )

You have only 1 (one) package foo, so your package_data should be for this package.

Sign up to request clarification or add additional context in comments.

4 Comments

Oh wow I finally found my logging.yml. It's in C:\[dir]\Python\Python313\Lib\site-packages\foo rather than [virtualenv]\Lib\site-packages\foo. Even though my virtualenv is definitely activated. Hmm.
Ok with py on Windows this works on 3.13.0a5 and 2.7.18. Thanks
@SamuelMarks Somehow you installed the package globally and not in the [virtualenv]. If you manage to install it in the [virtualenv] you will surely find the data file at [virtualenv]\Lib\site-packages\foo\config\logging.yml
Yeah Windows was acting weird. python.exe was definitely in the [virtualenv] but it installed packages globally. Switching to py within the activated virtualenv solved the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.