Repository navigation
feat(requirement): PEP 508 dependency specifier (#18636) - #7
Merged
Merged
Conversation
Port pypa/packaging's _parse_requirement: name [extras] (versionspec | "@" url) [";" marker], driving the shared internal/pep508 tokenizer end-to-end in one pass rather than splitting the string on ";" (which would mishandle a URL requirement whose URL itself contains ";"). - internal/pep508: add requirement-only token kinds (Identifier, LBracket, RBracket, Comma, Semicolon, AT, Specifier, URL) and ParseRequirement, which parses the marker clause mid-stream via the existing ParseMarker - no substring re-parse, no second lexer. - marker: add FromExpr, the seam that lets requirement/ wrap an already-parsed pep508.Expr into a Marker without re-lexing. - requirement: public Requirement/Parse/String, delegating the specifier to version.NewSpecifiers, extras to extras.Normalize, and distinguishing malformed-syntax/bad-version/bad-marker error categories under the ErrInvalidRequirement sentinel.
Polish requirement/doc.go to describe the implemented Parse/Requirement API and ErrInvalidRequirement, add the missing NOTICE attribution for the requirement/ package's dependency-specifier grammar (pypa/packaging _parse_requirement + requirements.py, Apache-2.0; Astral uv's uv-pep508 crate, dual Apache-2.0/MIT), and mark the requirement/ row implemented in README.md.
- Remove the misleading versionParse test helper (no alias collision exists); call sites now use version.Parse directly. - Add a comment on the URL tokenizer rule noting the deliberate space+tab divergence from upstream packaging's space-only rule. - Add a test asserting foo() (empty parenthesized specifier) is rejected as ErrInvalidRequirement.
…ace/tab (#18636) The URL rule (\A[^ \t]+) treated newline/CR as URL characters, so a defensively-multiline value like "name @ https://x/y\n; python_version > \"3\"" would absorb the marker clause into the URL token and lose it. Change the rule to \A\S+, the exact complement of the WS rule, so any whitespace terminates the URL - safe since a valid URL never contains whitespace. Add a regression test covering a newline between the URL and the marker clause; the existing URL-with-";" behavior is unaffected since ";" is not whitespace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
requirement/— PEP 508 dependency specifiers — the third and final PR of the PEP 508 core (extras → marker → requirement) for the native Go PyPI resolver (RFD 0001, epic rstudio/package-manager#18625). Builds on extras/ (#18638) and marker/ (#18637), both merged.Closes rstudio/package-manager#18636.
What
requirement.Parse(s) → Requirementparsingname [extras] [versionspec | @ url] [; marker], withRequirement{Name, Extras, Specifiers, URL, Marker},String()(round-trippable), and anErrInvalidRequirementsentinel.internal/pep508) drives the same parser-driven tokenizer the marker package uses and parses the; markerclause by callingpep508.ParseMarkermid-stream — no;substring split, no second lexer. This is what makes a URL containing;(pkg @ https://x/y;z.whl ; python_version > "3") parse correctly: the greedy, whitespace-terminated URL token consumes the URL whole and the marker is still separated.marker.FromExprseam added to the marker package so the parsed marker expression flows out of the internal package and is wrapped byrequirement/without an import cycle.version.NewSpecifiers(parenthesized(>=1.0)and multi-clause>=1.0,<2.0supported); extras normalized viaextras.Normalize;Namekept as-parsed (caller canonicalizes).errors.Is(err, ErrInvalidRequirement)while remaining distinguishable viaerrors.As.Notes
name>=1.0;marker(no space) is legal, but a URL requirement needswsp+/end before; marker.Identifierkind.Verification
Per commit:
go build,go vet,go test,gofmt -l(empty),golangci-lint run ./...(v2, 0 issues). Correctness anchored on packaging'stest_requirements.pycases ported as Go table tests, including the URL-with-;case, the grammar asymmetry, empty[]extras, parenthesized specifiers, error categories, and round-trips.