Caution

This API is not finalised, and may change in a patch version.

installer.utils#

Utilities related to handling / interacting with wheel files.

installer.utils.parse_metadata_file(contents)#

Parse PEP 376 PKG-INFO-style metadata files.

METADATA and WHEEL files (as per PEP 427) use the same syntax and can also be parsed using this function.

Parameters

contents (str) – The entire contents of the file

Return type

email.message.Message

installer.utils.parse_wheel_filename(filename)#

Parse a wheel filename, into it’s various components.

Parameters

filename (str) – The filename to parse

Return type

installer.utils.WheelFilename

installer.utils.copyfileobj_with_hashing(source, dest, hash_algorithm)#

Copy a buffer while computing the content’s hash and size.

Copies the source buffer into the destination buffer while computing the hash of the contents. Adapted from shutil.copyfileobj.

Parameters
  • source (BinaryIO) – buffer holding the source data

  • dest (BinaryIO) – destination buffer

  • hash_algorithm (str) – hashing algorithm

Returns

size, hash digest of the contents

Return type

Tuple[str, int]

installer.utils.get_launcher_kind()#

Get the launcher kind for the current machine.

Return type

LauncherKind

installer.utils.fix_shebang(stream, interpreter)#

Replace #!python shebang in a stream with the correct interpreter.

Parameters
  • stream (BinaryIO) – stream to modify

  • interpreter (str) – “correct interpreter” to substitute the shebang with

Returns

A context manager, that provides an appropriately modified stream.

Return type

Iterator[BinaryIO]

installer.utils.construct_record_file(records, prefix_for_scheme=lambda _: ...)#

Construct a RECORD file.

Parameters
Returns

A stream that can be written to file. Must be closed by the caller.

Return type

BinaryIO

installer.utils.parse_entrypoints(text)#

Parse entry_points.txt-style files.

Parameters

text (str) – entire contents of the file

Returns

name of the script, module to use, attribute to call, kind of script (cli / gui)

Return type

Iterable[Tuple[str, str, str, ScriptSection]]

installer.utils.make_file_executable(path)#

Make the file at the provided path executable.

Parameters

path (Union[str, os.PathLike[str]]) –

Return type

None

class installer.utils.WheelFilename#

WheelFilename(distribution, version, build_tag, tag)

static __new__(_cls, distribution, version, build_tag, tag)#

Create new instance of WheelFilename(distribution, version, build_tag, tag)

build_tag#

Alias for field number 2

distribution#

Alias for field number 0

tag#

Alias for field number 3

version#

Alias for field number 1