如何从 pyproject.toml 托管库的轮子中排除“tests”文件夹?

问题描述 投票:0回答:3

我尽力从

setup.py
托管库迁移到纯
pyproject.toml
库。 我有以下文件夹结构:

tests
└── <files>
docs
└── <files>
sepal_ui
└── <files>
pyproject.toml

在我的

pyproject.toml
中,以下文件和包发现设置:

[build-system]
requires = ["setuptools>=61.2", "wheel"]

[tool.setuptools]
include-package-data = false

[tool.setuptools.packages.find]
include = ["sepal_ui*"]
exclude = ["docs*", "tests*"]

在生产轮中,我得到以下信息:

tests
└── <files>
docs
└── <files>
sepal_ui
└── <files>
sepal_ui.egg-info
└── top-level.txt

查看 top-level.txt,我发现只包含 sepal_ui,所以我的问题很简单,为什么即使不使用额外的“docs”和“tests”文件夹,仍然包含它们?如何摆脱它们?

PS:我知道 MANIFEST.in 解决方案,如果它确实是唯一的解决方案,我会接受它,但我发现在 2 个文件中指定是多余的。

python setuptools pyproject.toml
3个回答
9
投票

有趣的事实,它从一开始就有效......

为下一个人不想花几个小时无所事事的人提供小型调试工作流程。

pyproject.toml 的配置

以下配置是从存储库根目录的

docs/
tests/
文件夹中删除文件的最低配置。如果您在每个模块中传播测试,请考虑添加
*.tests*
:

[build-system]
requires = ["setuptools>=61.2", "wheel"]

[tool.setuptools]
include-package-data = false

[tool.setuptools.packages.find]
include = ["sepal_ui*"]
exclude = ["docs*", "tests*"]

环境干净

那是我的错误。 Python 将信息缓存在

build/
egg-info
文件夹中。 setuptools 将使用存储在
egg-info/SOURCE.txt
中的最少文件,因此第一步:删除以前的构建文件

然后只需运行:

python -m build

检查wheel和tar.gz

从一开始我只检查 tar.gz(天真地)认为

.whl
.tar.gz
是相同的。并不是当
tests
文件夹保留在
tar.gz
文件中时,它就从轮子中消失了。


2
投票

这对我的孵化幼体很有用:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build]
exclude = [
  "/.*",
  "/docs",
  "/tests",
]

0
投票

飞利特:

[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"

[tool.flit.sdist]
include = ["doc/"]
exclude = ["doc/*.html"]
© www.soinside.com 2019 - 2024. All rights reserved.