使用setup.cfg在Python软件包中包含数据文件夹

发布于 2025-01-24 23:42:45 字数 1043 浏览 3 评论 0原文

我有以下SETUP.CFG文件,我想发布到PYPI的通常项目,应该使用数据文件夹运输,在我的情况下,RU_CORE_NEWS_SM-3.1.0。 (我正在使用setUptools):

[metadata]
name = test-project-name
version = 0.6.0

[options]
packages = find:
python_requires = >=3.6
include_package_data = True
install_requires = 
    spacy==3.1.3
    beautifulsoup4

[options.package_data]
test_project_name/ru_core_news_sm-3.1.0 = *.*

这是我的目录结构

base_project_name/
├── test_project_name
│   ├── __init__.py
│   ├── a.py
│   └── ru_core_news_sm-3.1.0
├── pyproject.toml
├── MANIFEST.in
└── setup.cfg

中有一个:

recursive-include test_project_name/ru_core_news_sm-3.1.0 *.*

我正在通过执行pip install path/to/base_project_name来测试安装

,我在清单 数据文件夹中的所有文件,但只有一些文件,我不知道为什么。

这些是基本文件夹中的文件:

”

这就是我使用pip到其他位置(两个项目都使用VENV)的“测试”时剩下的:

​?

I have the following setup.cfg file, a usual project I want to publish to pypi and which should be shipped with a data folder, in my case ru_core_news_sm-3.1.0. (I am using setuptools):

[metadata]
name = test-project-name
version = 0.6.0

[options]
packages = find:
python_requires = >=3.6
include_package_data = True
install_requires = 
    spacy==3.1.3
    beautifulsoup4

[options.package_data]
test_project_name/ru_core_news_sm-3.1.0 = *.*

This is my directory structure

base_project_name/
├── test_project_name
│   ├── __init__.py
│   ├── a.py
│   └── ru_core_news_sm-3.1.0
├── pyproject.toml
├── MANIFEST.in
└── setup.cfg

and I have this in my MANIFEST.in:

recursive-include test_project_name/ru_core_news_sm-3.1.0 *.*

I am testing the install by executing pip install path/to/base_project_name

However, this does not get me all files in the data folder, but only some of them, and I don't know why.

These are the files in the base folder:

before

and this is what remains when I have "test installed" it using pip to some other location (both projects use venv):

after

What could be the reason?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末が日狂欢 2025-01-31 23:42:46

Setuptools 62.3.0 开始,您现在可以使用递归通配符“ **”),将(sub)目录递归。这样,您可以在其中包含包含所有文件夹和文件的整个文件夹。

例如,当使用pyproject.toml文件时,这就是您递归包含两个文件夹的方式:

[tool.setuptools.package-data]
"ema_workbench.examples.data" = ["**"]
"ema_workbench.examples.models" = ["**"]

但是您也只能在文件夹和所有子文件夹中包含某些文件类型。如果要包含所有markdown(.md)文件,例如:

[tool.setuptools.package-data]
"ema_workbench.examples.data" = ["**/*.md"]

使用setup.py.pysetup.cfg时,它也应起作用。

参见细节。

Starting with Setuptools 62.3.0, you can now use recursive wildcards ("**") to include a (sub)directory recursively. This way you can include whole folders with all their folders and files in it.

For example, when using a pyproject.toml file, this is how you include two folders recursively:

[tool.setuptools.package-data]
"ema_workbench.examples.data" = ["**"]
"ema_workbench.examples.models" = ["**"]

But you can also only include certain file-types, in a folder and all subfolders. If you want to include all markdown (.md) files for example:

[tool.setuptools.package-data]
"ema_workbench.examples.data" = ["**/*.md"]

It should also work when using setup.py or setup.cfg.

See https://github.com/pypa/setuptools/pull/3309 for the details.

盛装女皇 2025-01-31 23:42:46

我发现问题:您不应使用*。*包括所有文件,而是简单地*。因为有时文件没有结尾,然后将被忽略。取决于文件(subest.in):

recursive-include project_name/ru_core_news_sm-3.1.0 *

或(setup.cfg)

test_project_name/ru_core_news_sm-3.1.0 = *

I found the problem: You should not use *.* to include all files, but instead simply *. Because sometimes files don't have an ending, which will then get ignored. Depending on the file (MANIFEST.in):

recursive-include project_name/ru_core_news_sm-3.1.0 *

or (setup.cfg)

test_project_name/ru_core_news_sm-3.1.0 = *
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文