<#9909 refactor(core): Centralize virtualenv manag...
# meltano-repo-activity
g
#9909 refactor(core): Centralize virtualenv management into a new `VirtualEnvService` and delegate to `VenvBackend` implementations Pull request opened by edgarrmondragon Description This is a stepping stone towards further specialization of the virtualenv backends so they're easier to test in isolation, with special interest towards some version of #6416. Notes for reviewers The diff is bigger than it should be and it might be a bit hard to review because of things being moved around, but I tried to add pointers where that happened. It's probably better to view the diff in "Split" mode. Sourcery's security issue regarding
subprocess.run
seems like a false positive to me. Checklist • I have read the contribution guide Was generative AI tooling used to co-author this PR? • Yes (please specify the tool below) Related Issues • #6416 • #8447 • #8784 Summary by Sourcery Centralize virtual environment management behind a new VirtualEnvService that delegates to pluggable VenvBackend implementations for virtualenv and uv, while simplifying VirtualEnv behavior and updating call sites and tests accordingly. New Features: • Introduce a VirtualEnvService façade that manages plugin virtual environments via a configurable VenvBackend. • Add a VenvBackend abstraction with VirtualenvBackend and UvBackend implementations to support multiple venv backends. Enhancements: • Relax VirtualEnv platform handling and improve Python version detection for non-default interpreters. • Update plugin installation and invocation logic to use VirtualEnvService/VenvBackend instead of backend-specific service classes. • Refine logging and error handling around environment creation and pip installation, including optional forcing of Python version ignores. Tests: • Refactor venv-related tests to target VirtualEnvService and the new backend classes, adding MockBackend-based tests for plugin install and CLI add flows. Summary by Sourcery Centralize plugin virtual environment management behind a new VirtualEnvService that delegates to pluggable VenvBackend implementations while simplifying VirtualEnv behavior and updating call sites and tests to use the new abstraction. New Features: • Introduce VirtualEnvService as the façade for managing plugin virtual environments. • Add a VenvBackend abstraction with VirtualenvBackend and UvBackend implementations to support multiple virtualenv backends. Enhancements: • Relax VirtualEnv platform handling and improve Python version detection for non-default interpreters. • Refactor plugin installation and invocation logic to depend on VirtualEnvService/VenvBackend instead of backend-specific service classes, with improved logging and error handling around venv creation and pip installation. Tests: • Rework venv-related tests to target VirtualEnvService and the new backend classes, including MockBackend-based tests for plugin auto-install flows and CLI add behavior, and expand coverage of Python selection and cross-platform handling. Summary by Sourcery Centralize virtual environment management behind a new VirtualEnvService façade and pluggable VenvBackend implementations, while updating plugin installation and invocation to use the new abstraction. New Features: • Introduce VirtualEnvService as the main entry point for managing plugin virtual environments. • Add a VenvBackend abstraction with VirtualenvBackend and UvBackend implementations to support multiple venv backends. Enhancements: • Relax VirtualEnv platform handling and improve Python version detection for non-default interpreters. • Refine pip installation behavior to optionally ignore plugin-declared Python requirements via a force flag. • Simplify plugin execution environment setup by using VirtualEnv directly in PluginInvoker instead of venv-specific service classes. Tests: • Refactor venv-related tests to target VirtualEnvService and the new backend classes, including backend-agnostic test coverage. • Add MockBackend-based tests in plugin installation and CLI add flows to validate integration with the new VirtualEnvService without invoking subprocesses. meltano/meltano