python

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 21 Imported by: 0

README

Design Notes

Examples

Can download a package with pip download there to get there-0.0.12-py2.py3-none-any.whl.

Can upload to our GitLab with curl or twine

curl -v --request POST \
  --form 'content=@there-0.0.12-py2.py3-none-any.whl' \
  --form 'name=there' \
  --form 'version=0.0.12' \
  --user $ACT3_USERNAME:$ACT3_TOKEN \
  "https://git.act3-ace.com/api/v4/projects/796/packages/pypi?requires_python=3.7"
twine upload --repository-url "https://git.act3-ace.com/api/v4/projects/796/packages/pypi" -u $ACT3_USERNAME -p $ACT3_TOKEN there-0.0.12-py2.py3-none-any.whl --verbose

Docs

There is no accepted PEP for uploading a python distribution file. This PEP-694 is trying to make a standard and overcome deficiencies in the current API used by PyPI.org. An old and incomplete one does exist PEP-243.

Example Twine Upload Form Data

--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="name"

there
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="version"

0.0.12
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="filetype"

bdist_wheel
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="pyversion"

py2.py3
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="metadata_version"

2.1
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="summary"

Print current file and line number
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="home_page"


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="author"


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="author_email"

Matthias Bussonnier <bussonniermatthias@gmail.com>
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="maintainer"


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="maintainer_email"


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="license"


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="description"

OMMITED DESCRIPTION


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="keywords"


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="classifiers"

License :: OSI Approved :: MIT License
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="download_url"


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="comment"


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="sha256_digest"

de8d6eaf343f48635640b7d092c13a265b955e52f85d423f410cb57bd8436afe
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="project_urls"

Home, https://github.com/Carreau/there
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="requires_python"


--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="description_content_type"

text/markdown
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="md5_digest"

e14443174ebd71d5893327824d3f1e70
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="blake2_256_digest"

d431c2aa184c8579c478e12b4b4bbfef50a209a0d03c55b23040a2820db6eeff
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name=":action"

file_upload
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="protocol_version"

1
--4f042191a20e4a9d9179bf52aec96376
Content-Disposition: form-data; name="content"; filename="there-0.0.12-py2.py3-none-any.whl"
Content-Type: application/octet-stream

Documentation

Overview

Package python implements tools for dealing with python distribution packages

Index

Constants

View Source
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/

View Source
const MetadataSuffix = ".metadata"

MetadataSuffix for metadata requests, see PEP-658.

Variables

View Source
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 :).

View Source
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

func Normalize(s string) string

Normalize computes the normalized name as per https://peps.python.org/pep-0503/#normalized-names

func Upload

func Upload(ctx context.Context, client remote.Client, getContent func() (io.ReadCloser, error), pypi string, entry DistributionEntry) error

Upload will upload the package to pypi with contents cr and metadata from entry.

Types

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

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 Version

type Version string

Version is a Python distribution version.

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.

Jump to

Keyboard shortcuts

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