hatch.utils.platform.Platform¶
- class hatch.utils.platform.Platform(display_func: ~typing.Callable = <built-in function print>)¶
Bases:
object
- __init__(display_func: ~typing.Callable = <built-in function print>) None ¶
Methods
__init__
([display_func])capture_process
(command, *[, shell])Equivalent to the standard library's [subprocess.Popen](https://docs.python.org/3/library/subprocess.html#subprocess.Popen), with all output captured by stdout and the command first being [properly formatted](utilities.md#hatch.utils.platform.Platform.format_for_subprocess).
check_command
(command, *[, shell])Equivalent to [run_command](utilities.md#hatch.utils.platform.Platform.run_command), but non-zero exit codes will gracefully end program execution.
check_command_output
(command, *[, shell])Equivalent to the output from the process returned by [capture_process](utilities.md#hatch.utils.platform.Platform.capture_process), but non-zero exit codes will gracefully end program execution.
exit_with_code
(code)exit_with_command
(command)Run the given command and exit with its exit code.
format_for_subprocess
(command, *, shell)Format the given command in a cross-platform manner for immediate consumption by subprocess utilities.
populate_default_popen_kwargs
(kwargs, *, shell)run_command
(command, *[, shell])Equivalent to the standard library's [subprocess.run](https://docs.python.org/3/library/subprocess.html#subprocess.run), with the command first being [properly formatted](utilities.md#hatch.utils.platform.Platform.format_for_subprocess).
stream_process_output
(process)Attributes
Returns the default shell of the system.
One of the following:
format_file_uri
The user's home directory as a path-like object.
join_command_args
Indicates whether Hatch is running on neither Windows nor macOS.
Indicates whether Hatch is running on macOS.
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).
One of the following:
Indicates whether Hatch is running on Windows.
- capture_process(command: str | list[str], *, shell: bool = False, **kwargs: Any) Popen ¶
Equivalent to the standard library’s [subprocess.Popen](https://docs.python.org/3/library/subprocess.html#subprocess.Popen), with all output captured by stdout and the command first being [properly formatted](utilities.md#hatch.utils.platform.Platform.format_for_subprocess).
- check_command(command: str | list[str], *, shell: bool = False, **kwargs: Any) CompletedProcess ¶
Equivalent to [run_command](utilities.md#hatch.utils.platform.Platform.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](utilities.md#hatch.utils.platform.Platform.capture_process), but non-zero exit codes will gracefully end program execution.
- property default_shell: str¶
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.
- property display_name: str¶
One of the following:
Linux
Windows
macOS
- 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](https://docs.python.org/3/library/os.html#os.execvp).
- 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.
- property linux: bool¶
Indicates whether Hatch is running on neither Windows nor macOS.
- property macos: bool¶
Indicates whether Hatch is running on macOS.
- property modules: LazilyLoadedModules¶
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).
- property name: str¶
One of the following:
linux
windows
macos
- run_command(command: str | list[str], *, shell: bool = False, **kwargs: Any) CompletedProcess ¶
Equivalent to the standard library’s [subprocess.run](https://docs.python.org/3/library/subprocess.html#subprocess.run), with the command first being [properly formatted](utilities.md#hatch.utils.platform.Platform.format_for_subprocess).
- property windows: bool¶
Indicates whether Hatch is running on Windows.