Can I specify package data in pyproject.toml

Question:

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?

Asked By: LudvigH

||

Answers:

if I understand your concern, you are using setuptools as a building and distributing system and you want to move some configs from setup.[py,cfg] namely package_data to pyproject.toml, if so you have to use an other tool to build and distribute your package e.g poetry as stated in @Romibuzi’s answer because it’s not possible unless the setuptools’ team plan a new major release to include a full support of pyproject.toml and then no need for extra/standalone config setup.cfg file.

some references:

Update

as per v61.0.0, setuptools brings a partial support (still in beta version) for this feature.

refer to @LudvigH’s answer. (thank you btw)

Answered By: cizario

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"]
Answered By: LudvigH

If you’re using Hatchling, per the docs, you can also do this via:

[tool.hatch.build]
include = [
  "myModule/**/*.csv",
  "**/*.py",  
]
exclude = [
  "tests/**",
]
Answered By: brandonscript
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.