Dependencies in mandatory groups are not exported by default

Đang mở
#253 0 bình luận 7 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
cli, tooling

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện hành vi với ví dụ pyproject.toml, poetry.lock tương ứng và poetry export -f requirements.txt --without-hashes; so sánh kết quả với poetry install. Hoàn thành khi bản export mặc định bao gồm các dependency từ những group bắt buộc, đồng thời vẫn loại trừ các group tùy chọn trừ khi chúng được chọn một cách rõ ràng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

poetry export and poetry install have the following identical arguments and documentation:

  • --without: The dependency groups to ignore. (multiple values allowed)
  • --with: The optional dependency groups to include. (multiple values allowed)

The way that poetry install works is as such: if you run poetry install without any additional parameters, it installs dependencies from the default group (under [tool.poetry.dependencies]) and all mandatory groups (I use the word mandatory in this post to specify groups that are not optional). You can customize this behaviour by excluding mandatory groups using --without or including optional groups using --with. This is intuitive, and is compatible with what the documentation for --with and --without parameters imply. However, this is not how poetry export works.

poetry export only exports dependencies from the default group (under [tool.poetry.dependencies]) and their sub-dependencies. Dependencies in optional AND mandatory groups are excluded from export, unless they are explicitly included using --with. There is no utility for --without, because all groups are excluded by default. This in incompatible with the documentation, inconsistent with other poetry commands especially poetry install, and counter-intuitive. I believe poetry export's behaviour should be changed to match that of poetry install.

Here is an example showing the issue. I have explicitly defined one of the groups as mandatory, but that is not strictly necessary. Groups that are not defined as optional are mandatory by default.

pyproject.toml:

[tool.poetry]
name = "poetry_export_groups"
version = "0.1.0"
description = ""
authors = ["Example <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
bottle = "^0.12.25"

[tool.poetry.group.mandatorygroup]
optional = false

[tool.poetry.group.mandatorygroup.dependencies]
colorama = "^0.4.6"

[tool.poetry.group.optionalgroup]
optional = true

[tool.poetry.group.optionalgroup.dependencies]
multipart = "^0.2.4"

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

I run poetry lock to create poetry.lock:

# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand.

[[package]]
name = "bottle"
version = "0.12.25"
description = "Fast and simple WSGI-framework for small web-applications."
optional = false
python-versions = "*"
files = [
    {file = "bottle-0.12.25-py3-none-any.whl", hash = "sha256:d6f15f9d422670b7c073d63bd8d287b135388da187a0f3e3c19293626ce034ea"},
    {file = "bottle-0.12.25.tar.gz", hash = "sha256:e1a9c94970ae6d710b3fb4526294dfeb86f2cb4a81eff3a4b98dc40fb0e5e021"},
]

[[package]]
name = "colorama"
version = "0.4.6"
description = "Cross-platform colored terminal text."
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
files = [
    {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
    {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
]

[[package]]
name = "multipart"
version = "0.2.4"
description = "Parser for multipart/form-data."
optional = false
python-versions = "*"
files = [
    {file = "multipart-0.2.4-py3-none-any.whl", hash = "sha256:5aec990820b8a9e94f9c164fbeb58cf118cfbde2854865b67a9a730edd1fb9d1"},
    {file = "multipart-0.2.4.tar.gz", hash = "sha256:06ba205360bc7096fefe618e4f1e9b2cdb890b4f2157053a81f386912a2522cb"},
]

[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "5f9c8003cc21f00ff4bda58eceedf883f970eae295a97350bc93d2d6721815ea"

Now if I poetry install without any additional arguments, bottle and colorama are installed—the former is a default dependency and the latter is in a mandatory group. However, multipart—which is in an optional group—is not installed unless explicitly included using --with.

$ poetry install
Installing dependencies from lock file

Package operations: 2 installs, 0 updates, 0 removals

  • Installing bottle (0.12.25)
  • Installing colorama (0.4.6)

Installing the current project: poetry_export_groups (0.1.0)

However, when I try exporting requirements, mandatory dependencies (in our case colorama, which is in a mandatory group) are not included in the export by default. Contrary to what the documentation says, --with is required for optional AND mandatory groups, making it inconsistent with other poetry commands and its behaviour counter-intuitive.

$ poetry export -f requirements.txt --without-hashes

bottle==0.12.25 ; python_version >= "3.11" and python_version < "4.0"

I am using Poetry 1.7.1 and poetry-plugin-export 1.6.0

Ngôn ngữ chính
Python
Star
336
Fork
59
Merge trung bình
10 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python-poetry/poetry-plugin-export

Tất cả issue của python-poetry/poetry-plugin-export

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.