如何使用 pyproject.toml 和诗歌从单个 python 模块构建多个包?

发布于 2025-01-14 11:21:17 字数 639 浏览 3 评论 0原文

我想实现与 Dask 库类似的行为,可以使用 pip 安装 daskdask[dataframe]、<代码>dask[array] 等。他们通过使用带有软件包密钥的 setup.py 来实现此目的 像这样。如果我仅安装 dask,则不会安装 dask[dataframe],并且在执行模块时它们会警告您这一点。

我在诗歌文档中找到了这个,但是当我执行poetry build< /code> 我只得到一个包含所有包的 .whl 文件。

如何打包我的模块,以便能够使用 poetry 安装库的特定部分?

I want to achieve a similar behavior as the library Dask does, it is possible to use pip to install dask, dask[dataframe], dask[array] and others. They do it by using the setup.py with a packages key like this. If I install only dask the dask[dataframe] is not installed and they warn you about this when executing the module.

I found this in the poetry documentation but when I execute poetry build I only get one .whl file with all of the packages within.

How can I package my module to be able to install specific parts of a library using poetry?

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

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

发布评论

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

评论(1

紫轩蝶泪 2025-01-21 11:21:17

实际上,Dask 示例并不单独安装子包,它只是单独安装自定义依赖项,如

为了使用poetry完成相同的行为,您需要使用这个 (正如用户 @sinoroc 在 此评论

来自 poetry extras 页面的示例 pyproject.toml 是这样的:

[tool.poetry]
name = "awesome"

[tool.poetry.dependencies]
# These packages are mandatory and form the core of this package’s distribution.
mandatory = "^1.0"

# A list of all of the optional dependencies, some of which are included in the
# below `extras`. They can be opted into by apps.
psycopg2 = { version = "^2.7", optional = true }
mysqlclient = { version = "^1.3", optional = true }

[tool.poetry.extras]
mysql = ["mysqlclient"]
pgsql = ["psycopg2"]

通过使用poetry build --formatwheel 将创建一个单独的轮文件。

为了使用 pip 和wheel 文件安装一组特定的额外依赖项,您应该使用:

pip install "wheel_filename.whl[mysql]"

Actually the Dask example does not install subpackages separately, it just installs the custom dependencies separately as explained in this link.

In order to accomplish the same behavior using poetry you need to use this (as mentioned by user @sinoroc in this comment)

The example pyproject.toml from the poetry extras page is this:

[tool.poetry]
name = "awesome"

[tool.poetry.dependencies]
# These packages are mandatory and form the core of this package’s distribution.
mandatory = "^1.0"

# A list of all of the optional dependencies, some of which are included in the
# below `extras`. They can be opted into by apps.
psycopg2 = { version = "^2.7", optional = true }
mysqlclient = { version = "^1.3", optional = true }

[tool.poetry.extras]
mysql = ["mysqlclient"]
pgsql = ["psycopg2"]

By using poetry build --format wheel a single wheel file would be created.

In order to install a specific set of extra dependencies using pip and the wheel file you should use:

pip install "wheel_filename.whl[mysql]"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文