How thombashi/subprocrunner works
Project type and purpose
• This is a Python wrapper library around the standard subprocess module, providing a higher-level API (SubprocessRunner), retry logic (Retry), command discovery (Which), error handling, and optional logging.
File structure
• Top‐level package: subprocrunner/
• _subprocess_runner.py → core runner implementation
• retry.py → Retry policy object
• _which.py → command lookup (Which)
• error.py → custom exceptions
• _logger/ → pluggable logger backend (real or null)
• Entry points: setup.py, pyproject.toml
• Tests and examples demonstrate usage but are not part of the runtime architecture.
README for insights
• Key components: SubprocessRunner API, Retry, Which, CalledProcessError, dry_run, history
• Dependencies: Python subprocess, optional loguru
Main components
a. Client application (user code)
b. Public API module (subprocrunner package)
• SubprocessRunner
• Retry
• Which
c. Internal modules
• _subprocess_runner.py
• retry.py
• _which.py
• error.py
• _logger/_logger.py and _null_logger.py
d. External services & libs
• Python subprocess stdlib
• OS shell/commands
• Optional loguru logger
Relationships & data flows
• Client calls SubprocessRunner(…)
• SubprocessRunner.run()
→ consults Retry (if provided)
→ invokes Python subprocess API via _subprocess_runner
→ captures stdout/stderr/returncode
→ may log via logger backend → either loguru or NullLogger
→ on error and check=True or raise_for_returncode(), throws CalledProcessError
• Which.is_exist() / abspath()
→ uses shutil.which or custom _which logic
Architectural patterns
• Facade: SubprocessRunner provides simplified interface over subprocess.
• Strategy: pluggable Retry policy.
• Adapter: Which adapts OS command lookup.
• Null Object: NullLogger vs real logger.
Elements
• Clear component names and package paths (e.g., subprocrunner._subprocess_runner)