fix: handle @latest version specifier with environment markers - #11098
dajiaohuang wants to merge 1 commit into
Conversation
Fixes issue where would fail with 'Path .../latest for <package> does not exist' error because: 1. The regex stripping @latest in init._parse_requirements only matched end-of-string, not @latest followed by markers. 2. The _parse_pep508 detection regex didn't account for @latest pattern, causing invalid PEP 508 parsing to be attempted. The fix updates the @latest stripping regex to also handle cases where @latest is followed by a semicolon (environment markers), while preserving the marker portion. Also adds the @latest detection pattern to _parse_pep508 for robustness in case RequirementsParser is called from other places. Fixes python-poetry#10227
|
Are you making
this is definitely wrong, a PEP508 parser should fail to parse non-compliant strings |
kokokoXUY
left a comment
There was a problem hiding this comment.
I found a reproducible VCS revision regression in the new @latest normalization; details inline.
| def parse(self, requirement: str) -> DependencySpec: | ||
| requirement = requirement.strip() | ||
| requirement = re.sub( | ||
| r"@\s*latest(\s*;|$)", r"\1", requirement, flags=re.IGNORECASE |
There was a problem hiding this comment.
This unconditional rewrite also matches a legitimate VCS revision named latest. I reproduced RequirementsParser.parse("git+https://github.com/demo/demo.git@latest") at this PR head (bce8925): it returns {'git': 'https://github.com/demo/demo.git'} with no rev, whereas the unchanged base returns rev: 'latest'. That silently installs the default branch instead of the requested revision. The same rewrite in init.py affects poetry add too. Could the @latest normalization be limited to a package-name version specifier, leaving VCS URLs and direct references untouched? A regression test for a Git URL with @latest would guard this.
Resolves #10227
Problem
When using
poetry addwith@latestversion specifier combined with environment markers (e.g.,poetry add --lock "poetry@latest ; platform_machine!=\"aarch64\""), the command would fail with the error:```
Path /path/to/project/latest for poetry does not exist
```
This happened because:
@latestininit._parse_requirements()only matched at end-of-string (`@\s*latest$`), failing when markers followed_parse_pep508detection regex did not account for the@latestpattern, causing invalid PEP 508 parsing to be attempted, which then fell through to path parsing (treating "latest" as a directory)Fix
@lateststripping regex in bothinit.pyandRequirementsParser.parse()to handle cases where@latestis followed by a semicolon (environment markers), while preserving the marker portion: `@\slatest(\s;|$)`@latestdetection pattern to_parse_pep508()for robustness@latestwith and without extras and markersTest cases added
All existing tests continue to pass.