ocebuild.sources.binary#

Binary helper functions.

Module Contents#

Functions#

get_binary_ext() → str)

Gets a platform-dependent extension for vendored binaries.

get_digest(→ str)

Gets a digest for a file or directory.

get_stream_digest(→ str)

Gets a digest for a stream.

wrap_binary(→ str)

Wraps a binary and returns stdout.

ocebuild.sources.binary.get_binary_ext(platform: Literal[Windows, Darwin, Linux] = system()) str[source]#

Gets a platform-dependent extension for vendored binaries.

ocebuild.sources.binary.get_digest(filepath, algorithm=sha256) str[source]#

Gets a digest for a file or directory.

Parameters:
  • filepath – The path to the file or directory.

  • algorithm – The hashlib algorithm to use. Defaults to SHA256.

Returns:

A hex digest of the file or directory.

ocebuild.sources.binary.get_stream_digest(stream, algorithm=sha256) str[source]#

Gets a digest for a stream.

Parameters:
  • stream – The stream to read.

  • algorithm – The hashlib algorithm to use. Defaults to SHA256.

Returns:

A hex digest of the stream.

ocebuild.sources.binary.wrap_binary(args: List[str], binary_path: str, persist: bool = True) str[source]#

Wraps a binary and returns stdout.

Parameters:
  • args – The arguments to pass to the binary.

  • binary_path – The path to the binary.

  • persist – Whether to persist the binary on disk.

Raises:

RuntimeError – If the binary returns a non-zero exit code.

Returns:

The stdout of the binary.