Python:如何制作诗歌包括一个不在副path上的软件包/模块?

发布于 2025-02-07 13:14:43 字数 2094 浏览 1 评论 0原文

在一个回购中,我有两个python项目都取决于共享的公用事业包。我的目标是在软件分发软件包(即.tzr.gz文件)中打包两个项目中的每个项目),

我目前正在使用setuptools完成此操作。 setup.py文件,并且很难。我宁愿使用诗歌分别管理和包装每个项目中的每个项目。

请考虑我问题的“最小再现”:

repo
    project1/ 
        __init__.py
        main_module.py
        pyproject.toml
    project2/ 
        __init__.py
        main_module.py
        pyproject.toml
    util/
        __init__.py
        util_module.py

我试图通过修改其project1来使诗歌包括util软件包,通过修改其project.toml 这样:

[tool.poetry]
name = "project1"
version = "0.1.0"
description = ""
authors = [""]
packages = [
    { include = "../util/*.py" }
]

[tool.poetry.dependencies]
python = "^3.9"

[tool.poetry.dev-dependencies]
pytest = "^5.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

当我运行诗歌构建时,我会得到此错误:

Building project1 (0.1.0)
  - Building sdist

  ValueError

  'C:\\repo\\util\\__init__.py' is not in the subpath of 'C:\\repo\\project1' OR one path is relative and the other is absolute.

  at ~\.pyenv\pyenv-win\versions\3.9.6\lib\pathlib.py:929 in relative_to
       925│         n = len(to_abs_parts)
       926│         cf = self._flavour.casefold_parts
       927│         if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts):
       928│             formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
    →  929│             raise ValueError("{!r} is not in the subpath of {!r}"
       930│                     " OR one path is relative and the other is absolute."
       931│                              .format(str(self), str(formatted)))
       932│         return self._from_parsed_parts('', root if n == 1 else '',
       933│                                        abs_parts[n:])

诗歌 支持我的用例?如果没有,我想念什么?

另外,请建议另一种分别包装我的两个项目的方法,但两个软件包都必须包括共享util软件包。

I have, in a single repo, two Python projects that both depend on a shared utility package. My goal is to package each of the two projects in a software distribution package (i.e. a .tzr.gz file)

I am currently getting this done using setuptools and setup.py files and having a hard time of it. I would much rather use Poetry to manage and package each of the two projects separately.

Please consider this "minimal repro" of my problem:

repo
    project1/ 
        __init__.py
        main_module.py
        pyproject.toml
    project2/ 
        __init__.py
        main_module.py
        pyproject.toml
    util/
        __init__.py
        util_module.py

I tried to get Poetry to include the util package when building project1 by modifying its project.toml this way:

[tool.poetry]
name = "project1"
version = "0.1.0"
description = ""
authors = [""]
packages = [
    { include = "../util/*.py" }
]

[tool.poetry.dependencies]
python = "^3.9"

[tool.poetry.dev-dependencies]
pytest = "^5.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

When I run poetry build I get this error:

Building project1 (0.1.0)
  - Building sdist

  ValueError

  'C:\\repo\\util\\__init__.py' is not in the subpath of 'C:\\repo\\project1' OR one path is relative and the other is absolute.

  at ~\.pyenv\pyenv-win\versions\3.9.6\lib\pathlib.py:929 in relative_to
       925│         n = len(to_abs_parts)
       926│         cf = self._flavour.casefold_parts
       927│         if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts):
       928│             formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
    →  929│             raise ValueError("{!r} is not in the subpath of {!r}"
       930│                     " OR one path is relative and the other is absolute."
       931│                              .format(str(self), str(formatted)))
       932│         return self._from_parsed_parts('', root if n == 1 else '',
       933│                                        abs_parts[n:])

Doesn't poetry support my use-case? If not, what am I missing?

Alternatively, please suggest another approach to package my two projects separately, but both packages must include the shared util package.

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

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

发布评论

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

评论(2

赠意 2025-02-14 13:14:43

UTIT本身应作为另一个Python软件包(请注意额外的pyproject.toml)

repo
    project1/ 
        ...
    project2/ 
        ...
    util/
        ...
        pyproject.toml

,然后按照任何其他软件包的平常添加它:

poetry add ../util

它应将其添加到pyproject.toml

[tool.poetry.dependencies]
python = "^3.9"
util = { path = "../util" }

Util itself should be built as another python package (note the extra pyproject.toml)

repo
    project1/ 
        ...
    project2/ 
        ...
    util/
        ...
        pyproject.toml

Then add it as you normally would with any other package:

poetry add ../util

Which should add it to pyproject.toml:

[tool.poetry.dependencies]
python = "^3.9"
util = { path = "../util" }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文