Public API

PEP 503 Python package repository generator.

Classes:

WheelFile(filename, wheel_hash[, …])

Represents a wheel file in the repository.

Functions:

generate_index(projects[, base_url])

Generate the simple repository index page, containing a list of all projects.

generate_project_page(name, files[, base_url])

Generate the repository page for a project.

make_simple(origin[, target, base_url, …])

Generate a simple repository of Python wheels.

namedtuple WheelFile(filename, wheel_hash, requires_python=None, metadata_hash=None)[source]

Bases: NamedTuple

Represents a wheel file in the repository.

Fields
  1.  filename (str) – The name of the wheel file.

  2.  wheel_hash (HASH) – The hash of the wheel file. Repositories SHOULD choose a hash function from one of the ones guaranteed to be available via the hashlib module in the Python standard library (currently md5, sha1, sha224, sha256, sha384, sha512). The current recommendation is to use sha256.

  3.  requires_python (Optional[str]) – The Requires-Python attribute from the wheel’s METADATA file. None if undefined.

  4.  metadata_hash (Union[HASH, Literal[True], None]) – The hash of the wheel’s METADATA file. None if the metadata file is not exposed. May be True if no hash is available.

__repr__()

Return a nicely formatted representation string

as_anchor(page, base_url='/')[source]

Generate an anchor tag in a airium.Airium document for this file.

Parameters
  • page (Airium)

  • base_url (Union[str, URL]) – The base URL of the Python package repository. Default '/'.

generate_index(projects, base_url='/')[source]

Generate the simple repository index page, containing a list of all projects.

Parameters
  • projects (Iterable[str]) – The list of projects to generate links for.

  • base_url (Union[str, URL]) – The base URL of the Python package repository. For example, with PyPI’s URL, a URL of /foo/ would be https://pypi.org/simple/foo/. Default '/'.

Return type

Airium

generate_project_page(name, files, base_url='/')[source]

Generate the repository page for a project.

Parameters
  • name (str) – The project name, e.g. domdf-python-tools.

  • files (Iterable[WheelFile]) – An iterable of files for the project, which will be linked to from the index page.

  • base_url (Union[str, URL]) – The base URL of the Python package repository. For example, with PyPI’s URL, a URL of /foo/ would be https://pypi.org/simple/foo/. Default '/'.

Return type

Airium

make_simple(origin, target=None, base_url='/', *, sort=False, copy=False, extract_metadata=True)[source]

Generate a simple repository of Python wheels.

Parameters
  • origin (Union[str, Path, PathLike]) – A directory containing wheels. The wheels may be arranged in subdirectories.

  • target (Union[str, Path, PathLike, None]) – The directory to create the repository in. The directory structure of origin will be recreated there. Defaults to origin.

  • base_url (Union[str, URL]) – The base URL of the simple repository. Default '/'.

  • sort (bool) – Sort the wheel files into per-project base directories. Default False.

  • copy (bool) – Copy files from the source to the destination, rather than moving them. Default False.

  • extract_metadata (bool) – Extract and serve METADATA files per PEP 658. Default True.

Return type

Dict[str, List[WheelFile]]

Returns

A mapping of (unnormalized) project names to a list of wheels for that project.

Changed in version 0.2.0: Now ignores wheels in the following directories: .git, .hg, .tox, .tox4, .nox, venv, .venv.

Changed in version 0.3.0:
  • Renamed the move option to sort to better reflect its behaviour.

  • Files are moved to the destination by default, unless the copy option is True.

Changed in version 0.4.0: Added the extract_metadata option.