pype.process#
- class pype.process.DockerConfig(exec_path, runtime, cache_dir=None)[source]#
Bases:
objectConfiguration for Docker and container runtime environments.
This class manages container runtime configuration and provides properties to identify the runtime type (Docker, Singularity, uDocker).
- exec_path#
Path to the container runtime executable
- Type:
- cache_dir#
Optional cache directory, required for Singularity containers
- Type:
pathlib.Path | None
- class pype.process.OverlayVolume(path, original_dir, scratch_dir, bind_file, harvest=True)[source]#
Bases:
objectOverlay path mapping for an output registered via add_output().
Mirrors the role of Volume for docker (path → bind_file substitution and harvest tracking), but lives in self.overlay_volumes rather than self.volumes so it never interferes with container-specific logic.
- class pype.process.Volume(path, output=False, bind_prefix='/var/lib/pype')[source]#
Bases:
objectVolume binding configuration for containerized environments.
Handles the mounting of files and directories between host and container environments, managing read-only and read-write access modes.
- replace_bind_volume(bind_path)[source]#
Replaces the bind volume in the container environment with the specified bind path.
This is useful to manage binding point to multiple paths (defined in multiple Volume classes) that are subfolders of another bind volume in the host system.
- Parameters:
bind_path (str) – Binding point to replace instead of the current one randomly generated by the class.
- replace_bind_dirname(bind_path)[source]#
Replaces the bind volume in the container environment with the dirname of the specified bind path.
This is useful to give the same binding point to multiple paths (defined in multiple Volume classes) that are in the same folder in the host system.
- Parameters:
bind_path (str) – Binding point to replace instead of the current one randomly generated by the class.
- class pype.process.Command(cmd, log, profile, name='')[source]#
Bases:
objectHigh-level interface for executing commands with container support.
This class provides a unified interface for running commands locally or within containers (Docker, Singularity, uDocker). It handles: - Command execution and piping - Volume mounting and file access - Container runtime configuration - Environment modules integration - Input/output file tracking
- cmd#
Command to execute as list of arguments
- name#
Identifier for the command (used in logs)
- profile#
Configuration profile for the environment
- log#
Logger instance for command execution tracking
- docker#
Container runtime configuration
- inputs#
List of input files required by the command
- outputs#
List of output files produced by the command
- volumes#
List of volumes to mount in container environments
- normalize_volumes()[source]#
Normalize volumes to avoid duplicates for bind mounts.
- Returns:
List of unique volumes for bind mounts (deduplicated). Note: self.volumes is kept intact for path substitution.
- Return type:
- docker_run(local_script)[source]#
Execute command within a container environment.
Handles the complexities of running commands in containers including: - Volume mounting and path translation - User permissions - Working directory setup - Container-specific command modifications
- Parameters:
local_script (bool) – If True, indicates the command is a local script that needs to be mounted in the container
- Return type:
None
- module_run(local_script=False, capture_stderr=False)[source]#
Execute command with environment modules.
- conda_run(local_script=False, capture_stderr=False)[source]#
Execute command in conda environment.
Supports both name-based and path-based conda environments: - If program.path is set: uses -p <path>/<name> - Otherwise: uses -n <name>
- release_stdout()[source]#
Release stdout to terminal (for final commands in execution).
Use this for terminal commands where output should be visible to the user.
- Return type:
None
- capture_stdout()[source]#
Capture stdout for piping (for intermediate commands).
Use this to ensure stdout is captured in subprocess.PIPE for piping to another command.
- Return type:
None
- close(ignore_returncode=False)[source]#
Close command and return result with exit code.
- Parameters:
ignore_returncode (bool) – If False (default), raise exception on non-zero exit. If True, ignore exit code (legacy behavior).
- Returns:
Tuple of (communicate_result, returncode)
- Raises:
CommandError – If returncode != 0 and ignore_returncode is False
- Return type:
- replace_values_in_code(code_file)[source]#
Replace path mappings in a script file.
Processes self.volumes (docker container paths) first, then self.overlay_volumes (scratch paths). seen_paths ensures a path is only substituted once — for docker runs this means docker volumes take precedence and overlay entries for the same path are skipped.
- Parameters:
code_file (str)
- Return type:
None
- class pype.process.Namespace(program_dict, log, profile)[source]#
Bases:
objectEnvironment and dependency management system.
Manages different execution environments (path-based, environment modules, containers) and their dependencies. Supports: - Path-based program execution - Environment modules loading - Container image specification - Dependency resolution
The namespace format is ‘type@item’ where: - type: One of ‘path’, ‘env_module’, or ‘docker’ - item: The specific program/container/module to use
For example: - ‘docker@ubuntu:latest’ - ‘env_module@gcc/9.3.0’ - ‘path@/usr/local/bin/python’
- __init__(program_dict, log, profile)[source]#
Initialize namespace configuration.
Parses a program configuration and sets up namespace properties for command execution. Supports both dict and ProfileProgram object inputs.
- Parameters:
program_dict (Dict[str, Any] | Any) –
Program configuration as dict or ProfileProgram object with keys: - namespace: String in format ‘type@item’ where type is one of:
’docker’, ‘env_module’, or ‘path’
version: Program version (optional for path type)
dependencies: Optional list of dependent program names
log (Any) – Logger instance for namespace operations
profile (Any) – Environment profile containing program configurations
- Attributes set:
type: Namespace type (‘docker’, ‘env_module’, or ‘path’) namespace: Original namespace string (e.g., ‘docker@ubuntu’) str: Parsed namespace item (e.g., ‘ubuntu’) version: Program version string list: List of resolved namespace items (empty until processing) docker_extra_args: Extra arguments for docker/singularity commands