Skip to content

Plugin utilities


hatchling.builders.utils.get_reproducible_timestamp()

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 hatchling/builders/utils.py
def get_reproducible_timestamp():
    """
    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() property

ignore_vcs() property

reproducible() property

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

dev_mode_dirs() property

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

versions() property

dependencies() property

default_include()

default_exclude()

default_packages()

Application

The way output is displayed can be configured by users.

abort(message = '', code = 1, **kwargs)

Terminate the program with the given return code.

display_debug(message = '', level = 1, **kwargs)

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 = '', **kwargs)

Meant to be used for messages indicating some unrecoverable error.

display_info(message = '', **kwargs)

Meant to be used for messages conveying basic information.

display_success(message = '', **kwargs)

Meant to be used for messages indicating some positive outcome.

display_waiting(message = '', **kwargs)

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

display_warning(message = '', **kwargs)

Meant to be used for messages conveying important information.

Platform

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

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

run_command(command: str | list[str], shell = False, **kwargs)

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

check_command(command: str | list[str], shell = False, **kwargs)

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

check_command_output(command: str | list[str], shell = False, **kwargs) -> 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 = False, **kwargs)

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])

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

default_shell() 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() 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).

name() property

One of the following:

  • linux
  • windows
  • macos

windows() property

Indicates whether Hatch is running on Windows.

macos() property

Indicates whether Hatch is running on macOS.

linux() property

Indicates whether Hatch is running on neither Windows nor macOS.

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

Last update: July 2, 2022