Implementation of a Unified Dependency and Version Management System
Overview
This issue implements a centralized, declarative system for managing Salt's optional dependencies and their version-specific requirements. This replaces fragmented HAS_X checks and inconsistent __version__ comparisons across the codebase with a unified interface in salt/utils/versions.py.
Key Improvements
- Centralized Registry: A new
Requirements registry (salt.utils.versions.reqs) provides attribute-based access to dependency status and versions.
- Consistent Comparisons: The
Requirement class utilizes packaging.version for all comparisons (e.g., reqs.msgpack >= "1.0.0"), eliminating manual string parsing and LooseVersion inconsistencies.
- Declarative Dependency Mapping: A
DEPS_MAP defines how modules are imported and how their versions are retrieved, supporting custom getters for complex packages (e.g., handling msgpack vs. msgpack-pure fallbacks).
- Boilerplate Reduction: Simplifies module-level logic for handling missing dependencies or version-specific functionality.
Implementation Details
salt/utils/versions.py: Added the core Requirement, Requirements, and Getters classes.
salt/serializers/msgpack.py: Fully refactored to utilize the new registry, showcasing cleaner branching logic for different msgpack versions (1.0.0+, 0.2.0+, and legacy).
salt/utils/msgpack.py: Migrated to the new system to handle imports and exception aliasing more reliably.
- Extensibility: Initial support is implemented for
msgpack and gnupg, providing a standardized path for migrating all other optional dependencies.
Example Usage
import salt.utils.versions
# Check availability
if not salt.utils.versions.reqs.msgpack:
log.error("msgpack is required for this feature")
# Version comparison
if salt.utils.versions.reqs.msgpack >= "1.0.0":
# Use newer msgpack features
pass
Verification
- New Tests: Comprehensive unit tests added in
tests/pytests/unit/utils/test_versions.py.
- Regression Testing: All existing
msgpack and serializer tests have been verified to pass with the new logic.
- Platform Compatibility: Verified correct behavior for
msgpack fallback logic and cross-version comparison stability.
Implementation of a Unified Dependency and Version Management System
Overview
This issue implements a centralized, declarative system for managing Salt's optional dependencies and their version-specific requirements. This replaces fragmented
HAS_Xchecks and inconsistent__version__comparisons across the codebase with a unified interface insalt/utils/versions.py.Key Improvements
Requirementsregistry (salt.utils.versions.reqs) provides attribute-based access to dependency status and versions.Requirementclass utilizespackaging.versionfor all comparisons (e.g.,reqs.msgpack >= "1.0.0"), eliminating manual string parsing andLooseVersioninconsistencies.DEPS_MAPdefines how modules are imported and how their versions are retrieved, supporting custom getters for complex packages (e.g., handlingmsgpackvs.msgpack-purefallbacks).Implementation Details
salt/utils/versions.py: Added the coreRequirement,Requirements, andGettersclasses.salt/serializers/msgpack.py: Fully refactored to utilize the new registry, showcasing cleaner branching logic for differentmsgpackversions (1.0.0+, 0.2.0+, and legacy).salt/utils/msgpack.py: Migrated to the new system to handle imports and exception aliasing more reliably.msgpackandgnupg, providing a standardized path for migrating all other optional dependencies.Example Usage
Verification
tests/pytests/unit/utils/test_versions.py.msgpackandserializertests have been verified to pass with the new logic.msgpackfallback logic and cross-version comparison stability.