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.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.
Uses a single-pass regex alternation so substituted text is never re-matched (prevents double-substitution when a bind_file contains another overlay path as a prefix). Docker volumes take precedence over overlay volumes when the same path appears in both.
- Parameters:
code_file (str)
- Return type:
None
- class pype.process.Namespace(program, 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, log, profile)[source]#
Initialize namespace configuration from a ProfileProgram.
- Parameters:
- Attributes set:
name: Profile dict key — unique identifier for this program type: Namespace type (‘docker’, ‘env_module’, ‘conda’, or ‘path’) namespace: Original namespace string (e.g., ‘docker@sequenza/sequenza’) str: Parsed namespace item (e.g., ‘sequenza/sequenza’) version: Program version string list: List of resolved namespace items docker_extra_args: Extra arguments for container runtimes
- Raises:
CommandNamespaceError – For invalid namespace format or unsupported types
- Parameters: