英文:
how to exclude "tests" folder from the wheel of a pyproject.toml managed lib?
问题
我尽力从一个由 `setup.py` 管理的库迁移到一个纯粹使用 `pyproject.toml` 的库。
我有以下文件夹结构:
tests
└── <文件>
docs
└── <文件>
sepal_ui
└── <文件>
pyproject.toml
在我的 `pyproject.toml` 中,我对文件和包的发现设置如下:
```toml
[build-system]
requires = ["setuptools>=61.2", "wheel"]
[tool.setuptools]
include-package-data = false
[tool.setuptools.packages.find]
include = ["sepal_ui*"]
exclude = ["docs*", "tests*"]
在生成的 wheel 中,我得到以下内容:
tests
└── <文件>
docs
└── <文件>
sepal_ui
└── <文件>
sepal_ui.egg-info
└── top-level.txt
查看 top-level.txt,我发现只有 sepal_ui 被包含了,所以我的问题很简单:为什么额外的 "docs" 和 "tests" 文件夹仍然被包含,即使它们没有被使用?如何摆脱它们?
附注:我知道 MANIFEST.in 解决方案,如果这真的是唯一的解决方案,我将接受,但我觉得在两个文件中指定是多余的。
<details>
<summary>英文:</summary>
I try my best to move from a `setup.py` managed lib to a pure `pyproject.toml` one.
I have the following folder structure:
tests
└── <files>
docs
└── <files>
sepal_ui
└── <files>
pyproject.toml
and in my `pyproject.toml` the following setup for file and packages discovery:
```toml
[build-system]
requires = ["setuptools>=61.2", "wheel"]
[tool.setuptools]
include-package-data = false
[tool.setuptools.packages.find]
include = ["sepal_ui*"]
exclude = ["docs*", "tests*"]
and in the produce wheel, I get the following:
tests
└── <files>
docs
└── <files>
sepal_ui
└── <files>
sepal_ui.egg-info
└── top-level.txt
looking at the top-level.txt, I see that only sepal_ui is included so my question is simple why do the extra "docs" and "tests" folder are still included even if they are not used? how to get rid of them ?
PS: I'm aware of the MANIFEST.in solution that I will accept if it's really the only one but I found it redundant to specify in 2 files.
答案1
得分: 9
Fun fact, it was working from the start....
Small debugging workflow for the next person that does not want to spend hours for nothing.
configuration of the pyproject.toml
the following configuration is the minimal to remove files from a docs/
and tests/
folders that are at the root of the repository. If you disseminated your tests in each modules, consider adding *.tests*
:
[build-system]
requires = ["setuptools>=61.2", "wheel"]
[tool.setuptools]
include-package-data = false
[tool.setuptools.packages.find]
include = ["sepal_ui*"]
exclude = ["docs*", "tests*"]
Clean environment
That was my mistake. Python is cahing information in the build/
and egg-info
folder. setuptools will use the lest of files stored in egg-info/SOURCE.txt
so first step: get rid of previous build files.
Then simply run:
python -m build
check both wheel and tar.gz
From the start I was checking only tar.gz thinking (naively) that .whl
and .tar.gz
were the same. It's not while the tests
folder remains in the tar.gz
file, it's absent from the wheel.
英文:
Fun fact, it was working from the start....
Small debugging workflow for the next person that does not want to spend hours for nothing.
configuration of the pyproject.toml
the following configuration is the minimal to remove files from a docs/
and tests/
folders that are at the root of the repository. If you disseminated your tests in each modules, consider adding *.tests*
:
[build-system]
requires = ["setuptools>=61.2", "wheel"]
[tool.setuptools]
include-package-data = false
[tool.setuptools.packages.find]
include = ["sepal_ui*"]
exclude = ["docs*", "tests*"]
Clean environment
That was my mistake. Python is cahing information in the build/
and egg-info
folder. setuptools will use the lest of files stored in egg-info/SOURCE.txt
so first step: get rid of previous build files.
Then simply run:
python -m build
check both wheel and tar.gz
From the start I was checking only tar.gz thinking (naively) that .whl
and .tar.gz
were the same. It's not while the tests
folder remains in the tar.gz
file, it's absent from the wheel.
答案2
得分: 0
这对刚孵化出来的项目对我有用:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build]
exclude = [
".*",
"docs",
"tests",
]
英文:
This has worked for me for hatchling:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build]
exclude = [
"/.*",
"/docs",
"/tests",
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论