Dependencies in mandatory groups are not exported by default

Abierto
#253 0 comentarios 7 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
cli, tooling

Línea de trabajo

Comienza reproduciendo el comportamiento con el ejemplo de pyproject.toml, su poetry.lock y poetry export -f requirements.txt --without-hashes; compara el resultado con poetry install. Se considera terminado cuando la exportación incluye de forma predeterminada las dependencias de los grupos obligatorios, pero sigue excluyendo los grupos opcionales a menos que se seleccionen explícitamente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
336
Forks
59
Merge medio
10 min
PR fusionados (30 d)
1

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python-poetry/poetry-plugin-export

Todos los issues de python-poetry/poetry-plugin-export

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.