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?
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?
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"]
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:
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)
In addition to the other existing answers, one can also simply use a MANIFEST.in
file.
See https://packaging.python.org/en/latest/guides/using-manifest-in/
As of now, if you are using pyproject.toml
and setuptool
you do not need to do anything. Just add some extra files in the same directory as your Python code.
But note that it will only add them if they are checked into source control, and you are using setuptools-scm
(the example tells you to so you probably are).
For example this is my pyproject.toml
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
[project]
name = "foo"
authors = [
{name = "...", email = "..."},
]
description = "..."
readme = "README.md"
requires-python = ">=3.9"
dependencies = [
"pydantic",
"jinja2"
]
version = "1.0.1"
[project.scripts]
foo = "foo:main"
And I have these files:
.
├── pyproject.toml
├── pyrightconfig.json
├── README.md
├── setup.py
└── src
└── foo
├── command.py
├── index.html
├── __init__.py
├── render.py
└── triage.py
And when I run python3 -m build
it does add index.html
to the wheels.
Also setup.py
is just for backwards compatibility. You don't actually need it.
If you're using Hatchling, per the docs, you can also do this via:
[tool.hatch.build]
include = [
"myModule/**/*.csv",
"**/*.py",
]
exclude = [
"tests/**",
]
Assuming a project dir structure like
project_root_directory
├── pyproject.toml
└── src
└── mypkg
├── __init__.py
├── data1.rst
├── data2.rst
├── data1.txt
└── data2.txt
simply add the following to your pyproject.toml
[tool.setuptools.packages.find]
where = ["src"]
[tool.setuptools.package-data]
mypkg = ["*.txt", "*.rst"]
More info can be found in the docs @ https://setuptools.pypa.io/en/latest/userguide/datafiles.html