requirement

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func CanonicalizeName(name string) string

CanonicalizeName normalizes a project name per PEP 503.

Types

type Environment

type Environment map[string]string

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

func ParseMarker(s string) (Marker, error)

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 Parse

func Parse(s string) (*Requirement, error)

Parse parses a PEP 508 requirement string.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL