twine.package module

twine.package._safe_name(name: str) str[source]

Convert an arbitrary string to a standard distribution name.

Any runs of non-alphanumeric/. characters are replaced with a single ‘-‘.

Copied from pkg_resources.safe_name for compatibility with warehouse. See https://github.com/pypa/twine/issues/743.

class twine.package.PackageFile[source]
__init__(filename: str, comment: str | None, metadata: Distribution, python_version: str | None, filetype: str | None) None[source]
classmethod from_filename(filename: str, comment: str | None) PackageFile[source]
metadata_dictionary() Dict[str, str | None | Sequence[str] | Tuple[str, bytes]][source]

Merge multiple sources of metadata into a single dictionary.

Includes values from filename, PKG-INFO, hashers, and signature.

add_attestations(attestations: List[str]) None[source]
add_gpg_signature(signature_filepath: str, signature_filename: str) None[source]
sign(sign_with: str, identity: str | None) None[source]
classmethod run_gpg(gpg_args: Tuple[str, ...]) None[source]
class twine.package.Hexdigest[source]

Hexdigest(md5, sha2, blake2)

md5: str | None

Alias for field number 0

sha2: str | None

Alias for field number 1

blake2: str | None

Alias for field number 2

static __new__(_cls, md5: str | None, sha2: str | None, blake2: str | None)

Create new instance of Hexdigest(md5, sha2, blake2)

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('md5', 'sha2', 'blake2')
classmethod _make(iterable)

Make a new Hexdigest object from a sequence or iterable

_replace(**kwds)

Return a new Hexdigest object replacing specified fields with new values

class twine.package.HashManager[source]

Manage our hashing objects for simplicity.

This will also allow us to better test this logic.

__init__(filename: str) None[source]

Initialize our manager and hasher objects.

_md5_update(content: bytes) None[source]
_md5_hexdigest() str | None[source]
_sha2_update(content: bytes) None[source]
_sha2_hexdigest() str | None[source]
_blake_update(content: bytes) None[source]
_blake_hexdigest() str | None[source]
hash() None[source]

Hash the file contents.

hexdigest() Hexdigest[source]

Return the hexdigest for the file.