pythonsetuptoolssetup.pyeggdata-files

Including non-Python files without __init__.py using `package_data` in setup.py?


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.


Solution

  • 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.