clabe.apps ¶
AsyncExecutor ¶
Bases: Protocol
Protocol for asynchronous command execution.
Defines the interface for executing commands asynchronously using async/await patterns. Implementations should handle asynchronous process execution, output capture, and error handling.
Example
run_async
async
¶
run_async(command: Command) -> CommandResult
Command ¶
Command(
cmd: list[str],
output_parser: _OutputParser[TOutput],
inputs: dict[str, Path] | None = None,
)
Bases: Generic[TOutput]
Represents a command to be executed with customizable output parsing.
Encapsulates command execution logic, result management, and output parsing. Supports both synchronous and asynchronous execution patterns with type-safe output parsing.
Commands are provided as a list of strings, which is consistent with subprocess and executed directly without shell interpretation. This approach: - Avoids shell injection vulnerabilities - Handles arguments with spaces correctly without manual quoting - Is more portable across platforms
Attributes:
| Name | Type | Description |
|---|---|---|
cmd |
list[str]
|
The command to execute as a list of strings |
result |
CommandResult
|
The result of command execution (available after execution) |
Example
# Create a command
cmd = Command(cmd=["python", "-c", "print('hello')"], output_parser=identity_parser)
# Execute with a synchronous executor
executor = LocalExecutor()
result = cmd.execute(executor)
# Create a command with custom output parser
def parse_json(result: CommandResult) -> dict:
return json.loads(result.stdout)
cmd = Command(cmd=["get-data", "--json"], output_parser=parse_json)
data = cmd.execute(executor)
Initialize the Command instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
The command to execute as a list of strings. The first element is the program to run, followed by its arguments. |
required |
output_parser
|
_OutputParser[TOutput]
|
Function to parse the command result into desired output type |
required |
inputs
|
dict[str, Path] | None
|
Local files the command reads, keyed by name, whose paths appear in |
None
|
Source code in src/clabe/apps/_base.py
inputs
property
¶
Local files the command reads, keyed by name, whose paths appear in cmd.
append_arg ¶
Append arguments to the command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
str | list[str]
|
Argument(s) to append. Can be a single string or list of strings. Empty strings are filtered out. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
Example
Source code in src/clabe/apps/_base.py
execute ¶
execute(executor: Executor) -> TOutput
Execute using a synchronous executor.
Source code in src/clabe/apps/_base.py
execute_async
async
¶
execute_async(executor: AsyncExecutor) -> TOutput
Execute using an async executor.
Source code in src/clabe/apps/_base.py
CommandError ¶
Bases: Exception
Exception raised when a command execution fails.
This exception is raised by CommandResult.check_returncode() when a command exits with a non-zero exit code. It includes detailed information about the command execution failure.
Attributes:
| Name | Type | Description |
|---|---|---|
exit_code |
The non-zero exit code returned by the command |
|
stdout |
Standard output from the command (may be None) |
|
stderr |
Standard error from the command (may be None) |
|
message |
Human-readable error message |
Example
Initialize the CommandError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exit_code
|
int
|
The non-zero exit code from the command |
required |
stdout
|
str | None
|
Standard output from the command |
None
|
stderr
|
str | None
|
Standard error from the command |
None
|
Source code in src/clabe/apps/_base.py
CommandResult ¶
Bases: BaseModel
Represents the result of a process execution.
started_at and ended_at are when the command was handed to its executor and when its result came back,
as timezone-aware UTC times of the machine running the launcher (also for a command run on another machine).
They are set by Command.execute / execute_async, and are None for a result built by hand.
check_returncode ¶
Raise CommandError if the exit code indicates failure.
Raises:
| Type | Description |
|---|---|
CommandError
|
If exit_code is non-zero, includes exit_code, stdout, and stderr |
Example
Source code in src/clabe/apps/_base.py
ExecutableApp ¶
Bases: Protocol
Protocol defining the interface for executable applications.
Any class implementing this protocol must provide a command property that
returns a Command object, enabling standardized execution across different
application types.
Example
Executor ¶
Bases: Protocol
Protocol for synchronous command execution.
Defines the interface for executing commands synchronously and obtaining results. Implementations should handle process execution, output capture, and error handling.
Example
StdCommand ¶
Bases: Command[CommandResult]
Standard command that returns the raw CommandResult.
A convenience class that creates a Command with the identity_parser, returning the raw CommandResult without transformation.
Source code in src/clabe/apps/_base.py
inputs
property
¶
Local files the command reads, keyed by name, whose paths appear in cmd.
append_arg ¶
Append arguments to the command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
str | list[str]
|
Argument(s) to append. Can be a single string or list of strings. Empty strings are filtered out. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
Example
Source code in src/clabe/apps/_base.py
execute ¶
execute(executor: Executor) -> TOutput
Execute using a synchronous executor.
Source code in src/clabe/apps/_base.py
execute_async
async
¶
execute_async(executor: AsyncExecutor) -> TOutput
Execute using an async executor.
Source code in src/clabe/apps/_base.py
AindBehaviorServicesBonsaiApp ¶
AindBehaviorServicesBonsaiApp(
workflow: PathLike,
*,
temp_directory: PathLike | None = None,
rig: Rig | None = None,
session: Session | None = None,
task: Task | None = None,
**kwargs,
)
Bases: BonsaiApp
Specialized Bonsai application for AIND behavior services integration.
This class extends the base BonsaiApp to provide specific functionality for AIND behavior experiments, including automatic configuration of task, session, and rig paths for the Bonsai workflow.
Example
Initializes the AIND behavior services Bonsai app with automatic model configuration.
Automatically configures RigPath, SessionPath, and TaskPath properties for the Bonsai workflow by saving provided models to temporary files and passing their paths as externalized properties.
Attention: This class requires a local executor since it saves temporary files. Args: workflow: Path to the Bonsai workflow file launcher: The launcher instance for saving temporary models rig: Optional rig model to configure. Defaults to None session: Optional session model to configure. Defaults to None task: Optional task model to configure. Defaults to None **kwargs: Additional keyword arguments passed to BonsaiApp (executable, is_editor_mode, is_start_flag, additional_properties, cwd, timeout, additional_externalized_properties)
Example
from aind_behavior_services import (
Rig,
Session,
Task
)
# Create models
rig = Rig(...)
session = Session(...)
task = Task(...)
# Create app with automatic configuration
app = AindBehaviorServicesBonsaiApp(
workflow="behavior_workflow.bonsai",
launcher=my_launcher,
rig=rig,
session=session,
task=task
)
app.run()
# The workflow will receive:
# -p:"RigPath"="/tmp/rig_temp.json"
# -p:"SessionPath"="/tmp/session_temp.json"
# -p:"TaskPath"="/tmp/task_temp.json"
Source code in src/clabe/apps/_bonsai.py
run ¶
run(
executor_kwargs: dict[str, Any] | None = None,
*,
executor: Executor | None = None,
) -> CommandResult
Execute the command and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to the local executor. |
None
|
executor
|
Executor | None
|
Executor to run the command with, e.g. a |
None
|
Source code in src/clabe/apps/_executors.py
run_async
async
¶
run_async(
executor_kwargs: dict[str, Any] | None = None,
*,
executor: AsyncExecutor | None = None,
) -> CommandResult
Execute the command asynchronously and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to the local executor. |
None
|
executor
|
AsyncExecutor | None
|
Executor to run the command with, e.g. a |
None
|
Source code in src/clabe/apps/_executors.py
validate ¶
Validates the Bonsai application configuration.
Checks that the Bonsai executable and workflow file exist. Issues a warning if editor mode is enabled, as it may prevent proper completion detection.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the executable or workflow file is not found |
Example
Source code in src/clabe/apps/_bonsai.py
BonsaiApp ¶
BonsaiApp(
workflow: PathLike,
*,
executable: PathLike | None = None,
is_editor_mode: bool = True,
is_start_flag: bool = True,
additional_externalized_properties: dict[str, str]
| None = None,
skip_validation: bool = False,
)
Bases: ExecutableApp, _DefaultExecutorMixin
A class to manage the execution of Bonsai workflows.
Handles Bonsai workflow execution, configuration management, and process monitoring for behavioral experiments.
Methods:
| Name | Description |
|---|---|
run |
Executes the Bonsai workflow |
get_result |
Retrieves the result of the Bonsai execution |
add_app_settings |
Adds or updates application settings |
validate |
Validates the Bonsai application configuration |
Initializes the BonsaiApp instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
PathLike
|
Path to the Bonsai workflow file |
required |
executable
|
PathLike | None
|
Path to the Bonsai executable. Defaults to None, which will trigger automatic discovery |
None
|
is_editor_mode
|
bool
|
Whether to run in editor mode. Defaults to True |
True
|
is_start_flag
|
bool
|
Whether to use the start flag. Defaults to True |
True
|
additional_externalized_properties
|
dict[str, str] | None
|
Additional externalized properties. Defaults to None |
None
|
Example
Source code in src/clabe/apps/_bonsai.py
run ¶
run(
executor_kwargs: dict[str, Any] | None = None,
*,
executor: Executor | None = None,
) -> CommandResult
Execute the command and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to the local executor. |
None
|
executor
|
Executor | None
|
Executor to run the command with, e.g. a |
None
|
Source code in src/clabe/apps/_executors.py
run_async
async
¶
run_async(
executor_kwargs: dict[str, Any] | None = None,
*,
executor: AsyncExecutor | None = None,
) -> CommandResult
Execute the command asynchronously and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to the local executor. |
None
|
executor
|
AsyncExecutor | None
|
Executor to run the command with, e.g. a |
None
|
Source code in src/clabe/apps/_executors.py
validate ¶
Validates the Bonsai application configuration.
Checks that the Bonsai executable and workflow file exist. Issues a warning if editor mode is enabled, as it may prevent proper completion detection.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the executable or workflow file is not found |
Example
Source code in src/clabe/apps/_bonsai.py
CurriculumApp ¶
CurriculumApp(
settings: CurriculumSettings,
*,
python_script_app_kwargs: dict[str, Any] | None = None,
)
Bases: ExecutableApp, _DefaultExecutorMixin
A curriculum application that manages the execution of behavior curriculum scripts.
Facilitates running curriculum modules within a managed Python environment, handling trainer state input/output and data directory management. The app processes session data through curriculum logic and generates suggestions for subsequent training stages.
Attributes:
| Name | Type | Description |
|---|---|---|
command |
Command
|
The underlying command that will be executed |
Example
# Create and run curriculum app
settings = CurriculumSettings(
input_trainer_state="/path/to/trainer_state.json",
data_directory="/data/session_123"
)
app = CurriculumApp(settings)
app.run()
suggestion = app.process_suggestion()
# Access the updated trainer state
new_state = suggestion.trainer_state
metrics = suggestion.metrics
Initializes the CurriculumApp with the specified settings.
Configures the curriculum application by setting up the Python script runner with appropriate arguments for data directory, trainer state input, and optional curriculum selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
CurriculumSettings
|
Configuration settings for the curriculum application |
required |
python_script_app_kwargs
|
dict[str, Any] | None
|
Optional keyword arguments to pass to PythonScriptApp |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If input_trainer_state or data_directory is not set in settings |
Example
Source code in src/clabe/apps/_curriculum.py
run ¶
run(
executor_kwargs: dict[str, Any] | None = None,
*,
executor: Executor | None = None,
) -> CommandResult
Execute the command and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to the local executor. |
None
|
executor
|
Executor | None
|
Executor to run the command with, e.g. a |
None
|
Source code in src/clabe/apps/_executors.py
run_async
async
¶
run_async(
executor_kwargs: dict[str, Any] | None = None,
*,
executor: AsyncExecutor | None = None,
) -> CommandResult
Execute the command asynchronously and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to the local executor. |
None
|
executor
|
AsyncExecutor | None
|
Executor to run the command with, e.g. a |
None
|
Source code in src/clabe/apps/_executors.py
process_suggestion ¶
process_suggestion() -> CurriculumSuggestion
Process and parse the curriculum command output into a CurriculumSuggestion.
Extracts the trainer state, metrics, and version information from the command execution stdout.
Returns:
| Name | Type | Description |
|---|---|---|
CurriculumSuggestion |
CurriculumSuggestion
|
Parsed curriculum suggestion with trainer state and metrics |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no stdout is available from command execution or if parsing fails |
Example
Source code in src/clabe/apps/_curriculum.py
CurriculumOutcome ¶
CurriculumSettings ¶
Bases: ServiceSettings
Settings for the CurriculumApp.
Configuration for curriculum execution including script path, project directory, trainer state input, data handling, and curriculum selection.
Attributes:
| Name | Type | Description |
|---|---|---|
script |
list[str]
|
The curriculum script/command to execute. Defaults to "curriculum run" |
project_directory |
PathLike
|
Root directory of the curriculum project. Defaults to current directory |
input_trainer_state |
PathLike | None
|
Path to the input trainer state file |
data_directory |
PathLike | None
|
Directory containing session data for curriculum processing |
curriculum |
str | None
|
Optional specific curriculum name to use |
Example
# Basic settings
settings = CurriculumSettings(
input_trainer_state="/path/to/trainer_state.json",
data_directory="/data/session"
)
# Settings with custom curriculum
settings = CurriculumSettings(
script="curriculum run",
project_directory="/path/to/curricula",
input_trainer_state="/path/to/trainer_state.json",
data_directory="/data/session",
curriculum="advanced_training"
)
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]
Customizes the settings sources to include the safe YAML settings source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_cls
|
type[BaseSettings]
|
The settings class |
required |
init_settings
|
PydanticBaseSettingsSource
|
The initial settings source |
required |
env_settings
|
PydanticBaseSettingsSource
|
The environment settings source |
required |
dotenv_settings
|
PydanticBaseSettingsSource
|
The dotenv settings source |
required |
file_secret_settings
|
PydanticBaseSettingsSource
|
The file secret settings source |
required |
Returns:
| Type | Description |
|---|---|
tuple[PydanticBaseSettingsSource, ...]
|
Tuple[PydanticBaseSettingsSource, ...]: A tuple of settings sources |
Source code in src/clabe/settings.py
CurriculumSuggestion ¶
Bases: BaseModel
Model representing a curriculum suggestion with trainer state and metrics.
This model encapsulates the output from a curriculum run, including the updated trainer state, performance metrics, and version information.
Attributes:
| Name | Type | Description |
|---|---|---|
trainer_state |
SerializeAsAny[TrainerState]
|
The updated trainer state after curriculum processing |
metrics |
SerializeAsAny[Metrics]
|
Performance metrics from the curriculum run |
version |
str
|
Version of the curriculum |
dsl_version |
str
|
Version of the domain-specific language package used (aind-behavior-curriculum) |
AsyncLocalExecutor ¶
AsyncLocalExecutor(
cwd: PathLike | None = None,
env: dict[str, str] | None = None,
timeout: float | None = None,
)
Bases: AsyncExecutor
Asynchronous executor for running commands on the local system.
Executes commands asynchronously using asyncio subprocess functions with configurable working directory and environment variables. Ideal for long-running processes or when multiple commands need to run concurrently.
Commands are executed directly without shell interpretation, which avoids shell injection vulnerabilities and handles arguments with spaces correctly.
Attributes:
| Name | Type | Description |
|---|---|---|
cwd |
Working directory for command execution |
|
env |
Environment variables for the subprocess |
|
timeout |
Maximum execution time in seconds |
Example
# Create async executor
executor = AsyncLocalExecutor()
# Execute a command asynchronously
cmd = Command(cmd=["echo", "hello"], output_parser=identity_parser)
result = await executor.run_async(cmd)
# Run multiple commands concurrently
executor = AsyncLocalExecutor(cwd="/workdir")
cmd1 = Command(cmd=["task1"], output_parser=identity_parser)
cmd2 = Command(cmd=["task2"], output_parser=identity_parser)
results = await asyncio.gather(
executor.run_async(cmd1),
executor.run_async(cmd2)
)
Initialize the asynchronous local executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cwd
|
PathLike | None
|
Working directory for command execution |
None
|
env
|
dict[str, str] | None
|
Environment variables for the subprocess |
None
|
timeout
|
float | None
|
Maximum execution time in seconds |
None
|
Source code in src/clabe/apps/_executors.py
run_async
async
¶
run_async(command: Command) -> CommandResult
Execute the command asynchronously and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Command
|
The command to execute (as a list of strings) |
required |
Returns:
| Type | Description |
|---|---|
CommandResult
|
CommandResult with stdout, stderr, and exit code |
Raises:
| Type | Description |
|---|---|
CommandError
|
If the command exits with non-zero exit code |
TimeoutError
|
If the command exceeds the timeout |
Example
Source code in src/clabe/apps/_executors.py
LocalDetachedExecutor ¶
Bases: Executor
Fire-and-forget executor that spawns a subprocess and returns immediately.
Launches the command via subprocess.Popen without waiting for it to
finish. stdout and stderr are redirected to DEVNULL so that no pipe
handles are left open. The returned CommandResult is a placeholder
with exit_code=0 and no captured output; callers must not rely on it
to reflect the actual process outcome.
Attributes:
| Name | Type | Description |
|---|---|---|
cwd |
Working directory for command execution |
|
env |
Environment variables for the subprocess |
Example
Initialize the detached executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cwd
|
PathLike | None
|
Working directory for command execution |
None
|
env
|
dict[str, str] | None
|
Environment variables for the subprocess |
None
|
Source code in src/clabe/apps/_executors.py
run ¶
run(command: Command[Any]) -> CommandResult
Spawn the command and return immediately without waiting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Command[Any]
|
The command to execute (as a list of strings) |
required |
Returns:
| Type | Description |
|---|---|
CommandResult
|
A placeholder |
CommandResult
|
The actual process exit code is never captured. |
Example
Source code in src/clabe/apps/_executors.py
LocalExecutor ¶
LocalExecutor(
cwd: PathLike | None = None,
env: dict[str, str] | None = None,
timeout: float | None = None,
)
Bases: Executor
Synchronous executor for running commands on the local system.
Executes commands using subprocess.run with configurable working directory and environment variables. Captures both stdout and stderr, and enforces return code checking.
Commands are executed directly without shell interpretation (shell=False), which avoids shell injection vulnerabilities and handles arguments with spaces correctly.
Attributes:
| Name | Type | Description |
|---|---|---|
cwd |
Working directory for command execution |
|
env |
Environment variables for the subprocess |
|
timeout |
Maximum execution time in seconds |
Example
# Create executor with default settings
executor = LocalExecutor()
# Create executor with custom working directory
executor = LocalExecutor(cwd="/path/to/workdir")
# Create executor with custom environment
executor = LocalExecutor(env={"KEY": "value"})
# Execute a command
cmd = Command(cmd=["echo", "hello"], output_parser=identity_parser)
result = executor.run(cmd)
Initialize the local executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cwd
|
PathLike | None
|
Working directory for command execution |
None
|
env
|
dict[str, str] | None
|
Environment variables for the subprocess |
None
|
timeout
|
float | None
|
Maximum execution time in seconds |
None
|
Source code in src/clabe/apps/_executors.py
run ¶
run(command: Command[Any]) -> CommandResult
Execute the command and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Command[Any]
|
The command to execute (as a list of strings) |
required |
Returns:
| Type | Description |
|---|---|
CommandResult
|
CommandResult with stdout, stderr, and exit code |
Raises:
| Type | Description |
|---|---|
CommandError
|
If the command exits with non-zero exit code |
Example
Source code in src/clabe/apps/_executors.py
PythonScriptApp ¶
PythonScriptApp(
script: str | list[str],
additional_arguments: list[str] | None = None,
project_directory: PathLike = Path("."),
extra_uv_arguments: str = "",
optional_toml_dependencies: list[str] | None = None,
append_python_exe: bool = False,
skip_validation: bool = False,
)
Bases: ExecutableApp, _DefaultExecutorMixin
Application class for running Python scripts within a managed uv environment.
Facilitates running Python scripts with automatic virtual environment management, dependency handling, and script execution. Uses the uv tool for environment and dependency management, ensuring isolated and reproducible Python environments.
The app automatically validates uv installation, creates virtual environments if needed, and constructs proper uv run commands with all necessary flags and arguments.
Attributes:
| Name | Type | Description |
|---|---|---|
command |
Command[CommandResult]
|
The underlying command that will be executed |
Example
# Simple script execution
app = PythonScriptApp(script="analyze_data.py")
result = app.run()
# With project dependencies
app = PythonScriptApp(
script="process.py",
project_directory="/path/to/project",
optional_toml_dependencies=["data", "viz"]
)
# Module execution with arguments
app = PythonScriptApp(
script="-m pytest",
additional_arguments="tests/ -v --cov",
extra_uv_arguments="-q"
)
# Async execution
result = await app.run_async()
Initializes the PythonScriptApp with the specified parameters.
Automatically validates the presence of uv and creates a virtual environment if one doesn't exist (unless skip_validation is True). Constructs the full uv run command with all specified arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
str | list[str]
|
The Python script command to be executed (e.g., "my_module.py" or "my_package run") |
required |
additional_arguments
|
list[str] | None
|
Additional arguments to pass to the script. Defaults to None |
None
|
project_directory
|
PathLike
|
The directory where the project resides. Defaults to current directory |
Path('.')
|
extra_uv_arguments
|
str
|
Extra arguments to pass to the uv command (e.g., "-q" for quiet). Defaults to empty string |
''
|
optional_toml_dependencies
|
list[str] | None
|
Additional TOML dependency groups to include (e.g., ["dev", "test"]). Defaults to None |
None
|
append_python_exe
|
bool
|
Whether to append "python" before the script command. Defaults to False |
False
|
skip_validation
|
bool
|
Skip uv validation and environment checks. Defaults to False |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If uv is not installed (unless skip_validation=True) |
Example
# Basic script execution
app = PythonScriptApp(script="test.py")
app.run()
# Script with module syntax
app = PythonScriptApp(script="-m pytest tests/")
# With dependencies and arguments
app = PythonScriptApp(
script="my_module.py",
additional_arguments="--verbose --output results.json",
optional_toml_dependencies=["dev", "test"]
)
# With Python explicitly prepended
app = PythonScriptApp(
script="script.py",
append_python_exe=True,
project_directory="/path/to/project"
)
Source code in src/clabe/apps/_python_script.py
run ¶
run(
executor_kwargs: dict[str, Any] | None = None,
*,
executor: Executor | None = None,
) -> CommandResult
Execute the command and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to the local executor. |
None
|
executor
|
Executor | None
|
Executor to run the command with, e.g. a |
None
|
Source code in src/clabe/apps/_executors.py
run_async
async
¶
run_async(
executor_kwargs: dict[str, Any] | None = None,
*,
executor: AsyncExecutor | None = None,
) -> CommandResult
Execute the command asynchronously and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to the local executor. |
None
|
executor
|
AsyncExecutor | None
|
Executor to run the command with, e.g. a |
None
|
Source code in src/clabe/apps/_executors.py
create_environment
classmethod
¶
create_environment(
project_directory: PathLike,
run_kwargs: dict[str, Any] | None = None,
) -> CompletedProcess
Creates a Python virtual environment using the uv tool.
Executes 'uv venv' to create a .venv directory in the specified project directory. This method is automatically called during initialization if no virtual environment is detected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_directory
|
PathLike
|
Directory where the virtual environment will be created |
required |
run_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments for subprocess.run. Defaults to None |
None
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
subprocess.CompletedProcess: The result of the environment creation process |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If the environment creation fails |
Example
Source code in src/clabe/apps/_python_script.py
identity_parser ¶
identity_parser(result: CommandResult) -> CommandResult