Documentation
¶
Overview ¶
Package pypi is the format of PyPI repositories (decision 0037). It reads each distribution's core metadata, a wheel's METADATA or an sdist's or egg's PKG-INFO, indexes the file as a file of its project's version wherever it is stored (decision 0018), with the per-file records the simple index, the PEP 658 metadata files and the JSON API are built from, and keeps the pypi.* properties. Every write reaches it through the item service in the write's own transaction, so a file deployed by twine, by a REST deploy or by jf rt u, or landed by a copy, a move or a restore, can be installed as soon as the write answers.
A file of a distribution type whose content yields no Name and Version is indexed by its pypi.name and pypi.version properties when it carries both, as JFrog requires of manual uploads it cannot read; any other file is stored but not indexed.
Index ¶
- Constants
- Variables
- func CanonicalPath(name, version, file string) string
- func Description(text string) string
- func IsDistribution(p string) bool
- func IsPrerelease(version string) bool
- func Normalize(name string) string
- func NormalizeVersion(v string) string
- func Serves(t repo.PackageType) bool
- func UploadPath(inspected any, repository repo.Config, name, version string) (string, error)
- func ValidName(name string) bool
- type Dist
- type Fields
- type File
- type Handler
- func (h Handler) Admit(ctx context.Context, env format.Env, c repo.Config, w format.Write) (format.Write, error)
- func (Handler) Annotated(ctx context.Context, env format.Env, c repo.Config, it types.Item, ...) error
- func (Handler) Deleting(ctx context.Context, env format.Env, _ repo.Config, it types.Item) error
- func (h Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it types.Item) error
- func (Handler) Inspect(ctx context.Context, env format.Env, _ repo.Config, w format.Write) (any, error)
- func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error
- type Metadata
- type Settings
- type Type
Constants ¶
const ( PropName = "pypi.name" PropVersion = "pypi.version" PropSummary = "pypi.summary" PropNormalizedName = "pypi.normalized.name" PropRequiresPython = "pypi.requires.python" // PropYanked yanks the file when set to anything but "false", in any // case: "true" or no value is a yank without a reason, any other value // the reason. 7.x's project page query reads it (RTFACT-29892). [I] // The values 7.x writes are unknown (#216). PropYanked = "pypi.yanked" )
Properties the format keeps on an indexed file. Name, version, summary, normalised name and Requires-Python follow from the core metadata and are set by the format (pypi-repositories; RTFACT-29892); yanked is the state a user changes after an upload, and the index follows it.
const MaxMetadata = 1 << 20
MaxMetadata is the most of a core metadata file the format reads: a larger one leaves a wheel indexed without its copy, and a header block that does not end within it leaves the file unindexed (decision 0037).
Variables ¶
var ErrNotDist = errors.New("pypi: not a distribution the format can index")
ErrNotDist is content the format cannot index as a distribution: a file name of no distribution type, an archive it cannot read, no core metadata where its type keeps it, a header block past MaxMetadata, or a Name or Version the index cannot hold. Such a file is stored and, unless its properties name it, not indexed (decision 0037).
Functions ¶
func CanonicalPath ¶
CanonicalPath is where an upload through the upload API stores a file (decision 0037): <normalised name>/<Version as the metadata writes it>/<file name as sent>. 7.x stores a twine upload at <name>/<version>/<file> with "-" for "_" in the folder (RTFACT-20390, RTFACT-29973). [I] Its folder for a name with upper case or dots is unknown (#216).
func Description ¶
Description reads the body after the metadata headers, falling back to the legacy Description header. It shares the format's tolerant header parsing.
func IsDistribution ¶
IsDistribution reports whether the file at p has the name of a distribution type, the files the format reads and the enforcement settings check.
func IsPrerelease ¶
IsPrerelease reports a PEP 440 pre-release or development release. Invalid legacy versions have no recognised pre-release marker.
func Normalize ¶
Normalize is a project name as PEP 503 normalises it: lower case, with every run of ".", "-" and "_" one "-". The package index keeps each project under it, so files whose metadata names normalise alike are one project, as 7.x finds them by pypi.normalized.name (RTFACT-29892).
func NormalizeVersion ¶
NormalizeVersion is v in the normal form PEP 440 gives it, as the packaging library prints a Version: "1.0-ALPHA.1" is "1.0a1", "v1.0" is "1.0" and "1!2.0" keeps its epoch. A version PEP 440 cannot read is returned as written, as decision 0037 indexes it.
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether t is a package type of this format.
func UploadPath ¶
UploadPath resolves a legacy upload using the format's existing inspection, so admission and indexing reuse the same archive read. Form metadata may confirm the distribution's identity but cannot choose where it is stored.
Types ¶
type Dist ¶
type Dist struct {
// Name and Version are the metadata's as written: a valid project name
// and a version the index can hold.
Name, Version string
// Summary and RequiresPython are the metadata's, or empty.
Summary, RequiresPython string
// Metadata is the core metadata file as the index keeps it: the whole
// file when it is at most MaxMetadata bytes, else its header block,
// with any byte that is not UTF-8 replaced so it can be stored as text.
Metadata string
// Core reports that Metadata is a wheel's METADATA byte for byte,
// which PEP 658 serves (decision 0037): an sdist's PKG-INFO may list
// fields as Dynamic, which installing then fills.
Core bool
}
Dist is what the format reads from a distribution: its core metadata.
func ReadDist ¶
ReadDist reads the distribution named name in ra, of size bytes: its core metadata, from where its type keeps it. ErrNotDist when the format cannot index it; any other error is a failure to read the content.
func ReadStored ¶
ReadStored reads the stored content sha as the distribution named name; ok is false when the format cannot index it. The upload API reads what it stored with it, to find the canonical path.
type Fields ¶
Fields are the header fields of a core metadata file, by name in lower case, as the names are not case-sensitive; each holds its values in the order the file gives them, since Classifier, Requires-Dist and others are used more than once.
func ParseFields ¶
ParseFields reads the header fields of a whole core metadata file, as the JSON API needs them (decision 0037).
type File ¶
type File struct {
// Path is the file's repository-relative path; Name its file name.
Path string `json:"path"`
Name string `json:"filename"`
// SHA256 and MD5 are the stored content's, in hex, and Size its
// length.
SHA256 string `json:"sha256"`
MD5 string `json:"md5"`
Size int64 `json:"size"`
// Uploaded is when the file was last deployed, in UTC to the
// microsecond the stores keep: PEP 700's upload-time.
Uploaded time.Time `json:"uploaded"`
// RequiresPython is the metadata's Requires-Python, or, for a file
// indexed by its properties, its pypi.requires.python.
RequiresPython string `json:"requires_python,omitempty"`
// Yanked and YankedReason follow pypi.yanked.
Yanked bool `json:"yanked,omitempty"`
YankedReason string `json:"yanked_reason,omitempty"`
// Metadata is the key in Texts of the file's core metadata, empty for
// a file indexed by its properties alone.
Metadata string `json:"metadata,omitempty"`
// Core reports that the text under Metadata is the wheel's whole
// METADATA, which PEP 658 serves; its key is then the SHA-256 the
// pages advertise.
Core bool `json:"core,omitempty"`
}
File is one file of a version as the index keeps it.
type Handler ¶
type Handler struct {
// The generic format's deploy policy, which Admit adds the reserved
// namespaces and the enforcement settings to.
generic.Handler
// Settings are the server's PyPI options.
Settings Settings
}
Handler is the PyPI format.
func (Handler) Admit ¶
func (h Handler) Admit( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) (format.Write, error)
Admit applies the deploy policy of every package type, then refuses a write into the namespaces PyPI reserves, then applies the enforcement settings to an upload (decision 0037).
func (Handler) Annotated ¶
func (Handler) Annotated( ctx context.Context, env format.Env, c repo.Config, it types.Item, a format.Annotation, ) error
Annotated follows a change to an indexed file's pypi.yanked, by whichever route it came: the properties API, AQL, jf rt sp, or a deploy, copy, move or restore carrying it, so the pages follow at once. A file indexed by its properties alone follows its pypi.name, pypi.version and pypi.requires.python too, and one that gains the first two is indexed by them; the core metadata decides for a file that has it, so a change to those leaves it where it is.
func (Handler) Deleting ¶
Deleting drops the record of a file about to be removed from its version's metadata. The item service drops the file's link and prunes a version left without files.
func (Handler) Deployed ¶
Deployed indexes a distribution file stored where the index reads (pkgindex.Stored), wherever its path, as the file of its project's version, after setting the pypi.* properties its core metadata gives. A file that no longer belongs to the version it was indexed under, such as one overwritten with another version's content, leaves it.
func (Handler) Inspect ¶
func (Handler) Inspect( ctx context.Context, env format.Env, _ repo.Config, w format.Write, ) (any, error)
Inspect reads a distribution file's core metadata before the write's transaction. Other content needs no reading.
type Metadata ¶
type Metadata struct {
// Files are the version's files, ordered by file name, then path, the
// order the project page lists them in (decision 0037).
Files []File `json:"files"`
// Texts are the core metadata files of Files by their SHA-256, each
// kept once: a version's wheels mostly share one METADATA.
Texts map[string]string `json:"texts,omitempty"`
}
Metadata is a version's document in the package index (PackageVersion.Metadata, decision 0037): one record per file, from which the simple index, the PEP 658 metadata files and the JSON API are built, so a read needs neither the files nor their properties. Everything in it follows from the files, their stored checksums and their properties, so a reindex writes the same bytes.
func DecodeMetadata ¶
DecodeMetadata reads a version's Metadata.
type Settings ¶
type Settings struct {
// EnforceLayout is pypi.enforce_layout, 7.x's
// artifactory.pypi.enforce.layout: an upload whose file name does not
// begin with the metadata's Name and Version is refused (Admit).
EnforceLayout bool
// EnforceNamingNormalization is pypi.enforce_naming_normalization,
// 7.x's artifactory.pypi.enforce.naming.normalization: an upload whose
// file name's name segment holds a "-" is refused (Admit).
EnforceNamingNormalization bool
// SimpleJSON is pypi.simple_json, 7.x's "Enable simple json format":
// the simple index answers PEP 691 JSON to a client that asks for it.
SimpleJSON bool
// CoreMetadata is pypi.core_metadata, 7.x's PEP 658 system property:
// the simple index advertises, and serves, the wheels' core metadata.
CoreMetadata bool
}
Settings are the server's PyPI options (decision 0037), each off by default as its 7.x counterpart is, and read by every PyPI repository.
type Type ¶
type Type int
Type is a distribution's type, as its file name tells it.
const ( // TypeWheel is a built distribution, .whl; its core metadata is METADATA // in its .dist-info folder. TypeWheel Type = iota + 1 // TypeSdist is a source distribution, .tar.gz, .tgz, .tar.bz2, .tar or // .zip; its core metadata is PKG-INFO. TypeSdist // TypeEgg is a legacy built distribution, .egg; its core metadata is // EGG-INFO/PKG-INFO. TypeEgg )
Distribution types.