Skip to content

Plugin utilities


hatchling.builders.utils.get_reproducible_timestamp() -> int

Returns an int derived from the SOURCE_DATE_EPOCH environment variable; see https://reproducible-builds.org/specs/source-date-epoch/.

The default value will always be: 1580601600

Source code in backend/src/hatchling/builders/utils.py
def get_reproducible_timestamp() -> int:
    """
    Returns an `int` derived from the `SOURCE_DATE_EPOCH` environment variable; see
    https://reproducible-builds.org/specs/source-date-epoch/.

    The default value will always be: `1580601600`
    """
    return int(os.environ.get('SOURCE_DATE_EPOCH', '1580601600'))

BuilderConfig

directory: str property

ignore_vcs: bool property

reproducible: bool property

Whether or not the target should be built in a reproducible manner, defaulting to true.

dev_mode_dirs: list[str] property

Directories which must be added to Python's search path in dev mode.

versions: list[str] property

dependencies: list[str] property

default_include() -> list

default_exclude() -> list

default_packages() -> list

default_only_include() -> list

Application

The way output is displayed can be configured by users.

Important

Never import this directly; Hatch judiciously decides if a type of plugin requires the capabilities herein and will grant access via an attribute.

verbosity: int property

The verbosity level of the application, with 0 as the default.

abort(message: str = '', code: int = 1, **kwargs: Any) -> None

Terminate the program with the given return code.

display_debug(message: str = '', level: int = 1, **kwargs: Any) -> None

Meant to be used for messages that are not useful for most user experiences. The level option must be between 1 and 3 (inclusive).

display_error(message: str = '', **kwargs: Any) -> None

Meant to be used for messages indicating some unrecoverable error.

display_info(message: str = '', **kwargs: Any) -> None

Meant to be used for messages conveying basic information.

display_success(message: str = '', **kwargs: Any) -> None

Meant to be used for messages indicating some positive outcome.

display_waiting(message: str = '', **kwargs: Any) -> None

Meant to be used for messages shown before potentially time consuming operations.

display_warning(message: str = '', **kwargs: Any) -> None

Meant to be used for messages conveying important information.

Platform

default_shell: str property

Returns the default shell of the system.

On Windows systems first try the SHELL environment variable, if present, followed by the COMSPEC environment variable, defaulting to cmd. On all other platforms only the SHELL environment variable will be used, defaulting to bash.

modules: LazilyLoadedModules property

Accessor for lazily loading modules that either take multiple milliseconds to import (like shutil and subprocess) or are not used on all platforms (like shlex).

home: Path property

The user's home directory as a path-like object.

name: str property

One of the following:

  • linux
  • windows
  • macos

display_name: str property

One of the following:

  • Linux
  • Windows
  • macOS

windows: bool property

Indicates whether Hatch is running on Windows.

macos: bool property

Indicates whether Hatch is running on macOS.

linux: bool property

Indicates whether Hatch is running on neither Windows nor macOS.

format_for_subprocess(command: str | list[str], *, shell: bool) -> str | list[str]

Format the given command in a cross-platform manner for immediate consumption by subprocess utilities.

run_command(command: str | list[str], *, shell: bool = False, **kwargs: Any) -> CompletedProcess

Equivalent to the standard library's subprocess.run, with the command first being properly formatted.

check_command(command: str | list[str], *, shell: bool = False, **kwargs: Any) -> CompletedProcess

Equivalent to run_command, but non-zero exit codes will gracefully end program execution.

check_command_output(command: str | list[str], *, shell: bool = False, **kwargs: Any) -> str

Equivalent to the output from the process returned by capture_process, but non-zero exit codes will gracefully end program execution.

capture_process(command: str | list[str], *, shell: bool = False, **kwargs: Any) -> Popen

Equivalent to the standard library's subprocess.Popen, with all output captured by stdout and the command first being properly formatted.

exit_with_command(command: list[str]) -> None

Run the given command and exit with its exit code. On non-Windows systems, this uses the standard library's os.execvp.

EnvironmentContextFormatter

formatters()

This returns a mapping of supported field names to their respective formatting functions. Each function accepts 2 arguments:

  • the value that was passed to the format call, defaulting to None
  • the modifier data, defaulting to an empty string

FileSystemContext

This class represents a synchronized path between the local file system and a potentially remote environment.

env: EnvironmentInterface property

Returns the environment to which this context belongs.

local_path: Path property

Returns the local path to which this context refers as a path-like object.

env_path: str property

Returns the environment path to which this context refers as a string. The environment may not be on the local file system.

sync_local()

Synchronizes the local path as the source with the environment path as the source.

sync_env()

Synchronizes the environment path with the local path as the source.

join(relative_path: str) -> FileSystemContext

Returns a new instance of this class with the given relative path appended to the local and environment paths.

This method should not need overwriting.