System Module¶
The rite.system module provides system-level operations including process management, environment variables, and platform detection.
Overview¶
system ¶
System Module¶
System-level operations and utilities.
This module provides comprehensive utilities for system operations including process management, environment variables, platform detection, path operations, and shell command handling.
Submodules¶
- process: Process and subprocess management
- environment: Environment variable operations
- platform: Platform and OS detection
- path: Path operations and queries
- shell: Shell command utilities
Examples¶
from rite.system import process_run, env_get, platform_name code, out, err = process_run(["ls"], Path.cwd()) home = env_get("HOME") os_name = platform_name()
Notes¶
Legacy functions run_command and get_escaped_command_arg are still available for backward compatibility.
Modules¶
env_delete ¶
env_get ¶
Environment Get¶
Get environment variable value.
Examples¶
from rite.system.environment import env_get env_get("PATH")
Functions¶
env_get ¶
Get environment variable value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Environment variable name. |
required |
default
|
str | None
|
Default value if not found. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Variable value or default. |
Examples:
Notes
Returns None if not found and no default.
env_list ¶
env_set ¶
Environment Set¶
Set environment variable value.
Examples¶
from rite.system.environment import env_set env_set("MY_VAR", "value")
environment ¶
Environment Module¶
Environment variable operations.
This submodule provides utilities for reading and modifying environment variables.
Examples¶
from rite.system.environment import env_get, env_set env_set("MY_VAR", "value") env_get("MY_VAR") 'value'
Modules¶
env_delete ¶
env_get ¶
Environment Get¶
Get environment variable value.
Examples¶
from rite.system.environment import env_get env_get("PATH")
Get environment variable value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Environment variable name. |
required |
default
|
str | None
|
Default value if not found. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Variable value or default. |
Examples:
Notes
Returns None if not found and no default.
env_list ¶
env_set ¶
Environment Set¶
Set environment variable value.
Examples¶
from rite.system.environment import env_set env_set("MY_VAR", "value")
get_escaped_command_arg ¶
Command Argument Escaping¶
Escape command line arguments for safe shell usage.
path ¶
Path Module¶
Path operation utilities.
This submodule provides utilities for path operations and queries using pathlib.
Examples¶
from rite.system.path import path_exists, path_join path_exists("/tmp") True path_join("/tmp", "file.txt") '/tmp/file.txt'
Modules¶
path_absolute ¶
Path Absolute¶
Get absolute path.
Examples¶
from rite.system.path import path_absolute path_absolute(".") '/current/working/directory'
Get absolute path as string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Relative or absolute path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Absolute path string. |
Examples:
>>> path_absolute(".")
'/current/working/directory'
>>> path_absolute("../parent")
'/parent/directory'
Notes
Resolves symlinks and relative paths.
path_exists ¶
path_is_dir ¶
path_is_file ¶
path_join ¶
Path Join¶
Join path components.
Examples¶
from rite.system.path import path_join path_join("/tmp", "file.txt") '/tmp/file.txt'
Join path components into single path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*parts
|
str
|
Path components to join. |
()
|
Returns:
| Type | Description |
|---|---|
str
|
Joined path string. |
Examples:
>>> path_join("/tmp", "dir", "file.txt")
'/tmp/dir/file.txt'
>>> path_join(".", "file.txt")
'./file.txt'
Notes
Uses platform-specific separator.
path_absolute ¶
Path Absolute¶
Get absolute path.
Examples¶
from rite.system.path import path_absolute path_absolute(".") '/current/working/directory'
Functions¶
path_absolute ¶
Get absolute path as string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Relative or absolute path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Absolute path string. |
Examples:
>>> path_absolute(".")
'/current/working/directory'
>>> path_absolute("../parent")
'/parent/directory'
Notes
Resolves symlinks and relative paths.
path_exists ¶
path_is_dir ¶
path_is_file ¶
path_join ¶
Path Join¶
Join path components.
Examples¶
from rite.system.path import path_join path_join("/tmp", "file.txt") '/tmp/file.txt'
Functions¶
path_join ¶
Join path components into single path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*parts
|
str
|
Path components to join. |
()
|
Returns:
| Type | Description |
|---|---|
str
|
Joined path string. |
Examples:
>>> path_join("/tmp", "dir", "file.txt")
'/tmp/dir/file.txt'
>>> path_join(".", "file.txt")
'./file.txt'
Notes
Uses platform-specific separator.
platform ¶
Platform Module¶
Platform and OS detection utilities.
This submodule provides utilities for detecting the operating system, architecture, and platform information.
Examples¶
from rite.system.platform import platform_name, platform_is_linux platform_name() 'Linux' platform_is_linux() True
Modules¶
platform_architecture ¶
platform_is_linux ¶
platform_is_macos ¶
platform_is_windows ¶
platform_name ¶
platform_architecture ¶
platform_is_linux ¶
platform_is_macos ¶
platform_is_windows ¶
platform_name ¶
platform_python_version ¶
process ¶
Process Module¶
Process and subprocess management.
This submodule provides utilities for executing system commands and managing subprocess operations.
Examples¶
from rite.system.process import process_run code, out, err = process_run(["ls"], Path.cwd())
Modules¶
process_call ¶
Process Call¶
Execute command and wait for completion.
Examples¶
from rite.system.process import process_call exit_code = process_call(["ls", "-la"])
Execute command and return exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command as list of strings. |
required |
cwd
|
Path | str | None
|
Working directory. Defaults to current. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Command exit code. |
Examples:
Notes
Does not capture output. Output goes to terminal.
process_check_output ¶
Process Check Output¶
Execute command and return output.
Examples¶
from rite.system.process import process_check_output output = process_check_output(["echo", "hello"])
Execute command and return stdout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command as list of strings. |
required |
cwd
|
Path | str | None
|
Working directory. Defaults to current. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Command stdout as string. |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If command fails. |
Examples:
Notes
Raises exception on non-zero exit. Uses check_output for subprocess execution.
process_run ¶
Process Run Command¶
Execute command in subprocess.
Examples¶
from rite.system.process import process_run code, out, err = process_run(["ls", "-la"], Path.cwd())
process_run(cmd: list[str], cwd: Path | str | None = None, check: bool = False) -> tuple[int, str, str]
Run command in subprocess and return result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command as list of strings. |
required |
cwd
|
Path | str | None
|
Working directory. Defaults to current. |
None
|
check
|
bool
|
Raise exception on non-zero exit. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, str, str]
|
Tuple of (return_code, stdout, stderr). |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If check=True and command fails. |
Examples:
>>> process_run(["echo", "hello"])
(0, 'hello', '')
>>> process_run(["ls"], Path("/tmp"))
(0, '...', '')
Notes
Uses Popen for subprocess execution. Output is text mode with UTF-8 encoding.
process_call ¶
Process Call¶
Execute command and wait for completion.
Examples¶
from rite.system.process import process_call exit_code = process_call(["ls", "-la"])
Functions¶
process_call ¶
Execute command and return exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command as list of strings. |
required |
cwd
|
Path | str | None
|
Working directory. Defaults to current. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Command exit code. |
Examples:
Notes
Does not capture output. Output goes to terminal.
process_check_output ¶
Process Check Output¶
Execute command and return output.
Examples¶
from rite.system.process import process_check_output output = process_check_output(["echo", "hello"])
Functions¶
process_check_output ¶
Execute command and return stdout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command as list of strings. |
required |
cwd
|
Path | str | None
|
Working directory. Defaults to current. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Command stdout as string. |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If command fails. |
Examples:
Notes
Raises exception on non-zero exit. Uses check_output for subprocess execution.
process_run ¶
Process Run Command¶
Execute command in subprocess.
Examples¶
from rite.system.process import process_run code, out, err = process_run(["ls", "-la"], Path.cwd())
Functions¶
process_run ¶
process_run(cmd: list[str], cwd: Path | str | None = None, check: bool = False) -> tuple[int, str, str]
Run command in subprocess and return result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command as list of strings. |
required |
cwd
|
Path | str | None
|
Working directory. Defaults to current. |
None
|
check
|
bool
|
Raise exception on non-zero exit. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, str, str]
|
Tuple of (return_code, stdout, stderr). |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If check=True and command fails. |
Examples:
>>> process_run(["echo", "hello"])
(0, 'hello', '')
>>> process_run(["ls"], Path("/tmp"))
(0, '...', '')
Notes
Uses Popen for subprocess execution. Output is text mode with UTF-8 encoding.
run_command ¶
Command Execution¶
Execute system commands in subprocess.
Functions¶
run_command ¶
Run a command in a subprocess and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
The command to run. |
required |
cwd
|
Path
|
The working directory to run the command in. |
required |
check
|
bool
|
Whether to check the return code. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, str, str]
|
A tuple containing the return code, stdout, and stderr. |
shell ¶
Shell Module¶
Shell command utilities.
This submodule provides utilities for safely handling shell commands, arguments, and escaping.
Examples¶
from rite.system.shell import shell_escape, shell_split shell_escape("file name.txt") "'file name.txt'" shell_split("ls -la '/tmp/file.txt'") ['ls', '-la', '/tmp/file.txt']
Modules¶
shell_escape ¶
Shell Escape¶
Escape shell argument.
Examples¶
from rite.system.shell import shell_escape shell_escape("file name.txt") "'file name.txt'"
shell_join ¶
Shell Join¶
Join command arguments into shell string.
Examples¶
from rite.system.shell import shell_join shell_join(["ls", "-la", "file name.txt"]) "ls -la 'file name.txt'"
Join command arguments into shell string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
list[str]
|
List of command arguments. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Shell command string. |
Examples:
Notes
Uses shlex.join for proper escaping. Python 3.8+ required for shlex.join.
shell_split ¶
Shell Split¶
Split shell command string.
Examples¶
from rite.system.shell import shell_split shell_split("ls -la '/tmp/file name.txt'") ['ls', '-la', '/tmp/file name.txt']
Split shell command string into arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
Command string to split. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of command arguments. |
Examples:
>>> shell_split("ls -la")
['ls', '-la']
>>> shell_split("echo 'hello world'")
['echo', 'hello world']
Notes
Uses shlex.split for proper parsing. Handles quoted arguments correctly.
shell_escape ¶
Shell Escape¶
Escape shell argument.
Examples¶
from rite.system.shell import shell_escape shell_escape("file name.txt") "'file name.txt'"
shell_join ¶
Shell Join¶
Join command arguments into shell string.
Examples¶
from rite.system.shell import shell_join shell_join(["ls", "-la", "file name.txt"]) "ls -la 'file name.txt'"
Functions¶
shell_join ¶
Join command arguments into shell string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
list[str]
|
List of command arguments. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Shell command string. |
Examples:
Notes
Uses shlex.join for proper escaping. Python 3.8+ required for shlex.join.
shell_split ¶
Shell Split¶
Split shell command string.
Examples¶
from rite.system.shell import shell_split shell_split("ls -la '/tmp/file name.txt'") ['ls', '-la', '/tmp/file name.txt']
Functions¶
shell_split ¶
Split shell command string into arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
Command string to split. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of command arguments. |
Examples:
>>> shell_split("ls -la")
['ls', '-la']
>>> shell_split("echo 'hello world'")
['echo', 'hello world']
Notes
Uses shlex.split for proper parsing. Handles quoted arguments correctly.
Submodules¶
Process¶
Run and manage system processes.
Process Module¶
Process and subprocess management.
This submodule provides utilities for executing system commands and managing subprocess operations.
Examples¶
from rite.system.process import process_run code, out, err = process_run(["ls"], Path.cwd())
Modules¶
process_run ¶
Process Run Command¶
Execute command in subprocess.
Examples¶
from rite.system.process import process_run code, out, err = process_run(["ls", "-la"], Path.cwd())
Functions¶
process_run ¶
process_run(cmd: list[str], cwd: Path | str | None = None, check: bool = False) -> tuple[int, str, str]
Run command in subprocess and return result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command as list of strings. |
required |
cwd
|
Path | str | None
|
Working directory. Defaults to current. |
None
|
check
|
bool
|
Raise exception on non-zero exit. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, str, str]
|
Tuple of (return_code, stdout, stderr). |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If check=True and command fails. |
Examples:
>>> process_run(["echo", "hello"])
(0, 'hello', '')
>>> process_run(["ls"], Path("/tmp"))
(0, '...', '')
Notes
Uses Popen for subprocess execution. Output is text mode with UTF-8 encoding.
process_call ¶
Process Call¶
Execute command and wait for completion.
Examples¶
from rite.system.process import process_call exit_code = process_call(["ls", "-la"])
Functions¶
process_call ¶
Execute command and return exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command as list of strings. |
required |
cwd
|
Path | str | None
|
Working directory. Defaults to current. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Command exit code. |
Examples:
Notes
Does not capture output. Output goes to terminal.
process_check_output ¶
Process Check Output¶
Execute command and return output.
Examples¶
from rite.system.process import process_check_output output = process_check_output(["echo", "hello"])
Functions¶
process_check_output ¶
Execute command and return stdout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command as list of strings. |
required |
cwd
|
Path | str | None
|
Working directory. Defaults to current. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Command stdout as string. |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If command fails. |
Examples:
Notes
Raises exception on non-zero exit. Uses check_output for subprocess execution.
Environment¶
Manage environment variables.
Environment Module¶
Environment variable operations.
This submodule provides utilities for reading and modifying environment variables.
Examples¶
from rite.system.environment import env_get, env_set env_set("MY_VAR", "value") env_get("MY_VAR") 'value'
Modules¶
env_get ¶
Environment Get¶
Get environment variable value.
Examples¶
from rite.system.environment import env_get env_get("PATH")
Functions¶
env_get ¶
Get environment variable value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Environment variable name. |
required |
default
|
str | None
|
Default value if not found. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Variable value or default. |
Examples:
Notes
Returns None if not found and no default.
env_set ¶
Environment Set¶
Set environment variable value.
Examples¶
from rite.system.environment import env_set env_set("MY_VAR", "value")
env_delete ¶
Platform¶
Detect platform and system information.
Platform Module¶
Platform and OS detection utilities.
This submodule provides utilities for detecting the operating system, architecture, and platform information.
Examples¶
from rite.system.platform import platform_name, platform_is_linux platform_name() 'Linux' platform_is_linux() True
Modules¶
platform_name ¶
platform_architecture ¶
platform_is_windows ¶
platform_is_linux ¶
platform_is_macos ¶
Path¶
System path operations.
Path Module¶
Path operation utilities.
This submodule provides utilities for path operations and queries using pathlib.
Examples¶
from rite.system.path import path_exists, path_join path_exists("/tmp") True path_join("/tmp", "file.txt") '/tmp/file.txt'
Modules¶
path_exists ¶
path_is_file ¶
path_is_dir ¶
path_absolute ¶
Path Absolute¶
Get absolute path.
Examples¶
from rite.system.path import path_absolute path_absolute(".") '/current/working/directory'
Functions¶
path_absolute ¶
Get absolute path as string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Relative or absolute path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Absolute path string. |
Examples:
>>> path_absolute(".")
'/current/working/directory'
>>> path_absolute("../parent")
'/parent/directory'
Notes
Resolves symlinks and relative paths.
path_join ¶
Path Join¶
Join path components.
Examples¶
from rite.system.path import path_join path_join("/tmp", "file.txt") '/tmp/file.txt'
Functions¶
path_join ¶
Join path components into single path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*parts
|
str
|
Path components to join. |
()
|
Returns:
| Type | Description |
|---|---|
str
|
Joined path string. |
Examples:
>>> path_join("/tmp", "dir", "file.txt")
'/tmp/dir/file.txt'
>>> path_join(".", "file.txt")
'./file.txt'
Notes
Uses platform-specific separator.
Shell¶
Shell command utilities.
Shell Module¶
Shell command utilities.
This submodule provides utilities for safely handling shell commands, arguments, and escaping.
Examples¶
from rite.system.shell import shell_escape, shell_split shell_escape("file name.txt") "'file name.txt'" shell_split("ls -la '/tmp/file.txt'") ['ls', '-la', '/tmp/file.txt']
Modules¶
shell_escape ¶
Shell Escape¶
Escape shell argument.
Examples¶
from rite.system.shell import shell_escape shell_escape("file name.txt") "'file name.txt'"
shell_split ¶
Shell Split¶
Split shell command string.
Examples¶
from rite.system.shell import shell_split shell_split("ls -la '/tmp/file name.txt'") ['ls', '-la', '/tmp/file name.txt']
Functions¶
shell_split ¶
Split shell command string into arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
Command string to split. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of command arguments. |
Examples:
>>> shell_split("ls -la")
['ls', '-la']
>>> shell_split("echo 'hello world'")
['echo', 'hello world']
Notes
Uses shlex.split for proper parsing. Handles quoted arguments correctly.
shell_join ¶
Shell Join¶
Join command arguments into shell string.
Examples¶
from rite.system.shell import shell_join shell_join(["ls", "-la", "file name.txt"]) "ls -la 'file name.txt'"
Functions¶
shell_join ¶
Join command arguments into shell string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
list[str]
|
List of command arguments. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Shell command string. |
Examples:
Notes
Uses shlex.join for proper escaping. Python 3.8+ required for shlex.join.
Examples¶
from rite.system import (
process_run,
env_get,
platform_is_linux,
shell_escape
)
# Run process
result = process_run(["ls", "-la"])
# Get environment variable
home = env_get("HOME")
# Platform detection
if platform_is_linux():
print("Running on Linux")
# Escape shell argument
safe_arg = shell_escape("file with spaces.txt")