python-poetry / python-poetry/poetry-plugin-export

marker ordering is nondeterministic

Open
#334 9 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
335
Forks
57
Avg merge
1h 23m
Merged PRs (30d)
3

Description

The ordering of system platform requirements in the marker section produced by poetry-plugin-export appears to be nondeterministic. Repeated invocations of poetry export --without-hashes -f requirements.txt in our project will at a roughly coin flip probability produce either of the following two requirement specs:

-colorama==0.4.6 ; (sys_platform == "win32" or platform_system == "Windows") and python_full_version == "3.9.21"
+colorama==0.4.6 ; (platform_system == "Windows" or sys_platform == "win32") and python_full_version == "3.9.21"

Obviously (a || b) && c and (b || a) && c are logically equivalent, so there's no problem here in terms of actually installing the project, but we have precommit hooks and CI tooling to ensure that requirements.txt is kept up to date with changes in poetry.lock, and the fact that the marker section may change arbitrarily is causing build and check failures.

Unfortunately this is also not currently easily possible to work around by using a "smarter" approach to checking equivalence with the existing packaging tooling; packaging.requirements.Marker.__eq__() appears to be a simple string comparison:

>>> from packaging.requirements import Requirement
>>> r1 = Requirement('colorama==0.4.6 ; (sys_platform == "win32" or platform_system == "Windows") and python_full_version >= "3.9.21"')
>>> r2 = Requirement('colorama==0.4.6 ; (platform_system == "Windows" or sys_platform == "win32") and python_full_version >= "3.9.21"')
>>> r1 == r2
False

Request: any (a || b) component of the generated marker should be sorted lexically.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by repeatedly running poetry export --without-hashes -f requirements.txt and inspect the marker-generation path responsible for platform requirements. Reproduce the alternating ordering with the reported colorama example. Done means equivalent (a || b) components are emitted in lexical order and repeated exports produce stable requirements output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.