Skip to content

Wrong validation when extra marker starts with "in" (probably marker expand) #10342

@mcichorzA

Description

@mcichorzA

Description

I was playing with poetry-export plugin, it was giving me strange results when I tried to export requirements.txt with one of my EXTRA dependencies.

The issue is when EXTRA starts with "in" it's not validated properly (or after my research, it's not expanded correctly).
I have managed to prepare example and also include logs from debugger where instead of "extra == investigatorisnotworkingproperly" it was expanded to "extra in vestigatorisnotworkingproperly.

Try execute

poetry export f requirements.txt --without-hashes --without-urls --extras investigatorisnotworkingproperly

with pyproject.toml I have provided.
Below debugger logs

[asyncio:asyncio] Using selector: EpollSelector
> /mnt/c/Users/a831057/PycharmProjects/potry_test/.poetry/plugins/poetry_plugin_export/walker.py(291)get_project_dependency_packages2()
    290
--> 291         if not marker.validate({"extra": extras}):
    292             #print(f"DEBUG: Skipping package={package} due to marker validation failure")

[asyncio:asyncio] Using selector: EpollSelector
ipdb> extras
['investigatorisnotworkingproperly']
[asyncio:asyncio] Using selector: EpollSelector
ipdb> s
--Call--
> /home/cichy/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/core/version/markers.py(591)validate()
    590
--> 591     def validate(self, environment: Mapping[str, Any] | None) -> bool:
    592         if self._name == "extra":

[asyncio:asyncio] Using selector: EpollSelector
ipdb>
> /home/cichy/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/core/version/markers.py(592)validate()
    591     def validate(self, environment: Mapping[str, Any] | None) -> bool:
--> 592         if self._name == "extra":
    593             return self.expand().validate(environment)

[asyncio:asyncio] Using selector: EpollSelector
ipdb> self.expand()
<MarkerUnion extra == "extra1" or extra in "vestigatorisnotworkingproperly" or extra == "vestigatorisnotworkingproperly">
[asyncio:asyncio] Using selector: EpollSelector
ipdb> q

extra in "vestigatorisnotworkingproperly" is crearly wrong

There must be a bug somewhere there
https://github.com/python-poetry/poetry-core/blob/2528905d2a7aa6b4b6c21f13f9a2604db5e8ad80/src/poetry/core/version/markers.py#L347

I will try to find it on my own also.

Workarounds

Dont use names for EXTRA which starts with "in".

Poetry Installation Method

pipx

Operating System

Ubuntu 22

Poetry Version

Poetry (version 2.1.2)

Poetry Configuration

cache-dir = "/home/cichy/.cache/pypoetry"
data-dir = "/home/cichy/.local/share/pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
python.installation-dir = "{data-dir}/python"  # /home/cichy/.local/share/pypoetry/python
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/cichy/.cache/pypoetry/virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Python Sysconfig

sysconfig.log
Paste the output of 'python -m sysconfig', over this line.

Example pyproject.toml

[project]
name = "poetry-test"
version = "0.1.0"
description = ""
authors = [
    {name = "cichyx96",email = "[email protected]"}
]
readme = "README.md"
requires-python = ">=3.10"


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

# Various dependencies fro lambdas
attrs = { version = "^24.2.0", optional = true }
boto3 = { version = "^1.34.139", optional = true }
requests = { version = "^2.31.0", optional = true }

[tool.poetry.extras]
extra1 = ["attrs"]
extra2 = ["boto3"]
investigatorisnotworkingproperly = ["attrs", "boto3", "requests"]
vestigatorisnotworkingproperly = ["attrs", "boto3", "requests"]

[tool.poetry.requires-plugins]
poetry-plugin-export = ">=1.8"

[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"

Poetry Runtime Logs

poetry-runtime.log
Paste the output of 'poetry -vvv <command>', over this line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreRelated to the poetry-core librarykind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions