Documentation
¶
Overview ¶
Package requirement parses Python dependency requirements as defined by PEP 508, including names, extras, version specifiers, direct URL references, and environment markers. It also reads requirements files in the pip format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanonicalizeName ¶
CanonicalizeName normalizes a project name per PEP 503.
Types ¶
type Environment ¶
Environment maps marker variables to values for evaluation.
func CurrentEnvironment ¶
func CurrentEnvironment(pythonVersion string) Environment
CurrentEnvironment builds an environment from the host, using the given target Python version for the python_version and related variables. The Python version is a caller input because gopip resolves for a chosen interpreter, not for the Go runtime.
type Marker ¶
type Marker interface {
Evaluate(env Environment) bool
String() string
}
Marker is an environment marker expression.
func ParseMarker ¶
ParseMarker parses a PEP 508 marker expression.
type Requirement ¶
type Requirement struct {
Name string
Extras []string
Specifier *version.SpecifierSet
URL string
Marker Marker
// contains filtered or unexported fields
}
Requirement is a single parsed dependency requirement.
func (*Requirement) AppliesTo ¶
func (r *Requirement) AppliesTo(env Environment) bool
AppliesTo reports whether this requirement is active in the given environment. A requirement with no marker always applies. When the requirement's marker mentions an extra, set env["extra"] to the extra being resolved.
func (*Requirement) CanonicalName ¶
func (r *Requirement) CanonicalName() string
CanonicalName returns the normalized project name per PEP 503: lowercase with runs of dot, hyphen, and underscore collapsed to a single hyphen.
func (*Requirement) String ¶
func (r *Requirement) String() string
String reconstructs the requirement in a normalized form.
type RequirementsFile ¶
type RequirementsFile struct {
Requirements []*Requirement
Includes []string // referenced with -r or --requirement
Constraints []string // referenced with -c or --constraint
Editables []string // referenced with -e or --editable
}
RequirementsFile is the parsed content of a pip requirements file.
func ParseRequirementsFile ¶
func ParseRequirementsFile(content string) (*RequirementsFile, error)
ParseRequirementsFile parses the text of a pip requirements file. It handles comments, blank lines, and backslash line continuations, and recognizes the common -r, -c, and -e options. Other global options are ignored.