Search code examples
pythonpipsetuptools

Specifying package data in pyproject.toml


I use setuptools. In setup.cfg, I can define

[options.package_data]
myModule =
    '*.csv'

to make sure that data will be installed for my users.

Can I achive the same with pyproject.toml instead?


Solution

  • Starting in setuptools version 61.0.0 there is beta support for this feature. See the documentation https://setuptools.pypa.io/en/stable/userguide/datafiles.html

    The syntax is

    [tool.setuptools.package-data]
    myModule = ["*.csv"]
    

    Update 2024-01-12: This is no longer in beta. A handful of different mechanisms can enable for data inclusion. One mechanism is to ask for automatic discovery based on git. It should suffice to set the setuptools version and enable the -scm plugin. Now all files tracked by git will be considered data files. The relevant section is...

    [build-system]
    requires = [
        "setuptools>=60",
        "setuptools-scm>=8.0"]
    

    I produced a complete example and posted on github. https://github.com/el-hult/mypkg

    Read the full documentation for more options.