Documentation
¶
Overview ¶
Package python implements tools for dealing with python distribution packages
Index ¶
- Constants
- Variables
- func DistributionSatisfiesRequirement(entry DistributionEntry, dist Distribution, req Requirement) bool
- func Normalize(s string) string
- func Upload(ctx context.Context, client remote.Client, ...) error
- type Client
- type Distribution
- type DistributionEntry
- type Requirement
- type Requirements
- func (rr *Requirements) AddRequirement(req Requirement)
- func (rr *Requirements) AddRequirementString(requirement string) error
- func (rr *Requirements) IncludeExtras() error
- func (rr *Requirements) Indexes() []string
- func (rr *Requirements) ParseRequirementsFile(requirementsFile string) error
- func (rr *Requirements) Projects() []string
- func (rr *Requirements) RequirementsForProject(project string) []Requirement
- type Version
- type VersionClause
- type VersionSpecifier
Constants ¶
const ( MediaTypeSimpleJSON = "application/vnd.pypi.simple.v1+json" MediaTypeSimpleHTML = "application/vnd.pypi.simple.v1+html" MediaTypeSimpleLegacy = "text/html" )
MediaTypes as defined in https://peps.python.org/pep-0691/
const MetadataSuffix = ".metadata"
MetadataSuffix for metadata requests, see PEP-658.
Variables ¶
var ErrInvalidPythonDistributionFilename = errors.New("invalid python distribution filename")
ErrInvalidPythonDistributionFilename is an error to signify that the python filename is not valid or our parser needs updating :).
var ErrProjectNotFound = errors.New("python project not found")
ErrProjectNotFound indicated that the project was not found in the python package index.
Functions ¶
func DistributionSatisfiesRequirement ¶
func DistributionSatisfiesRequirement(entry DistributionEntry, dist Distribution, req Requirement) bool
DistributionSatisfiesRequirement returns true iff the given distribution meets the requirement provided.
func Normalize ¶
Normalize computes the normalized name as per https://peps.python.org/pep-0503/#normalized-names
Types ¶
type Client ¶
Client behaves like http.Client. Abstracting at this level allows auth and retries. Same as oras/remote.Client.
type Distribution ¶
type Distribution interface { // Project name Project() string // Version is the version string Version() string // Labels returns all the distribution information expanded as a set of labels if any of the labels.Set matches then // this distribution is compatible Labels() []labels.Set }
Distribution represents a python distribution package.
func NewDistribution ¶
func NewDistribution(filename string) (Distribution, error)
NewDistribution parses a DistributionEntry and returns the a Distribution useful for filtering.
type DistributionEntry ¶
type DistributionEntry struct { // URL of the distribution file URL string // Digest is the digest (if present) of the distribution file Digest digest.Digest // Filename is the filename which encodes lots of information. Filename string // RequiresPython is an optional specifier that denotes a ranges of python version this distribution supports RequiresPython string // Yanked if non-nil then the package has been yanked (should no longer be used). The value is the reason why it was yanked (may be empty). See https://peps.python.org/pep-0592/ Yanked *string // MetadataDigest is the digest (if present) of the metadata MetadataDigest digest.Digest }
DistributionEntry represents a raw distribution file reference entry for a project (minimally processed).
func RetrieveAllDistributions ¶
func RetrieveAllDistributions(ctx context.Context, client Client, pypis []string, project string) ([]DistributionEntry, error)
RetrieveAllDistributions get all the distributions from all Python package indexes. The distributions are deduplicated such that the first package index that provides a distribution file is used.
func RetrieveDistributions ¶
func RetrieveDistributions(ctx context.Context, client Client, pypi string, project string) ([]DistributionEntry, error)
RetrieveDistributions reads and parses the Python Package Index standard HTML for a Python project and returns the slice of Distribution objects and possibly an error.
func (*DistributionEntry) MetadataURL ¶
func (entry *DistributionEntry) MetadataURL() string
MetadataURL is the URL of the metadata (if present).
type Requirement ¶
type Requirement struct { // Name is the normalized name of the project Name string // VersionSpecifier is the version specifier string (e.g., "==4.5.3", ">=4.5,<5") VersionSpecifier VersionSpecifier // Extras are the extra packages to be installed with this requirement Extras []string // Constrains are the non-hash constraints (e.g., "python_version > 3.6 and sys_platform == win32") Constraints string // Digests are the digests of the distribution files that this requirement can match Digests map[digest.Digest]struct{} }
Requirement represents a Python package requirement.
func ParseRequirement ¶
func ParseRequirement(line string) (*Requirement, error)
ParseRequirement parses a Python requirement line currently only supports the pinned format produced by poetry.
func (*Requirement) String ¶
func (r *Requirement) String() string
String formats this requirement as a pip compatible requirements specifier.
type Requirements ¶
type Requirements struct { // IndexURL and ExtraIndexURLs are places to look for packages IndexURL string ExtraIndexURLs []string // contains filtered or unexported fields }
Requirements represents a set of requirements (including index urls, constraints, etc).
func (*Requirements) AddRequirement ¶
func (rr *Requirements) AddRequirement(req Requirement)
AddRequirement adds the requirement to the set.
func (*Requirements) AddRequirementString ¶
func (rr *Requirements) AddRequirementString(requirement string) error
AddRequirementString parses then adds a single requirement to the set.
func (*Requirements) IncludeExtras ¶
func (rr *Requirements) IncludeExtras() error
IncludeExtras pulls out all the extra packages specified already and adds them to this set of requirements.
func (*Requirements) Indexes ¶
func (rr *Requirements) Indexes() []string
Indexes is the list of ordered python package indexes to use.
func (*Requirements) ParseRequirementsFile ¶
func (rr *Requirements) ParseRequirementsFile(requirementsFile string) error
ParseRequirementsFile extracts all requirements from the given file.
func (*Requirements) Projects ¶
func (rr *Requirements) Projects() []string
Projects is a sorted list of project names referenced by these requirements.
func (*Requirements) RequirementsForProject ¶
func (rr *Requirements) RequirementsForProject(project string) []Requirement
RequirementsForProject returns a slice of requirements for a project. The caller should not modify the data pointed to by the slice.
type VersionClause ¶
type VersionClause struct { // Operator is the comparison operator (==, !=, ~=, etc.) Operator string // Value is the partial version string (1.2.*, 1.2, 1.2.3a4 ) Value string }
VersionClause is a single part of a VersionSpecifier.
func ParseVersionClause ¶
func ParseVersionClause(clauseSpec string) (*VersionClause, error)
ParseVersionClause parses the version clause, splitting out the operator from the value.
func (VersionClause) Matches ¶
func (vc VersionClause) Matches(version Version) bool
Matches returns true when the version matches the clause.
func (VersionClause) String ¶
func (vc VersionClause) String() string
String converts the clause back into the string representation.
type VersionSpecifier ¶
type VersionSpecifier []VersionClause
VersionSpecifier specifies a range of versions used in python requirement. The nil or length zero VersionSpecifier matches everything.
func ParseVersionSpecifier ¶
func ParseVersionSpecifier(versionSpec string) (VersionSpecifier, error)
ParseVersionSpecifier parses the version specifier from a requirement spec.
func (VersionSpecifier) Matches ¶
func (vs VersionSpecifier) Matches(version Version) bool
Matches returns true if the provided version is acceptable by this VersionSpecifier.
func (VersionSpecifier) String ¶
func (vs VersionSpecifier) String() string
String formats the VersionSpecifier in it's requirements compatible form.