Skip to content

Evaluate PEP 508 environment markers when parsing requirements - #520

Open
dchaudhari7177 wants to merge 1 commit into
adamchainz:mainfrom
dchaudhari7177:fix/evaluate-environment-markers
Open

Evaluate PEP 508 environment markers when parsing requirements#520
dchaudhari7177 wants to merge 1 commit into
adamchainz:mainfrom
dchaudhari7177:fix/evaluate-environment-markers

Conversation

@dchaudhari7177

Copy link
Copy Markdown

Fixes #517.

parse_pip ignored PEP 508 environment markers, so a line like colorama==0.4.6 ; sys_platform == 'win32' was always treated as an expected requirement — a false-positive mismatch on any environment the marker excludes (e.g. colorama "missing" on Linux).

Now each requirement's marker is evaluated with packaging.markers.Marker, and lines whose marker doesn't apply to the current environment are skipped. A malformed marker is left for pip to report rather than silently dropping the requirement. Splitting on ; before parsing also makes name/version extraction robust to markers written without surrounding spaces.

Dependency note

This adds packaging to dependencies (the project was zero-dependency). Correct PEP 508 marker evaluation really needs it, and packaging is present in every environment where pip runs, so it shouldn't change pip-lock's practical footprint. If you'd rather keep the zero-dependency install, I'm happy to switch to an optional import (evaluate markers when packaging is importable, otherwise fall back to current behaviour) — just say the word.

Tests

Added cases for a marker that matches (kept), doesn't match (skipped), has no surrounding spaces, is combined with extras, and is malformed (kept). The skip cases fail on main and pass with the change; full suite green; ruff check/format clean. Added a CHANGELOG entry.

@dchaudhari7177
dchaudhari7177 force-pushed the fix/evaluate-environment-markers branch from 7b234cb to 400a0f7 Compare August 9, 2026 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Environment markers (e.g. ; sys_platform == 'win32') are ignored, causing false positive mismatches

1 participant