Skip to content

[feature] Implementation of a Unified Dependency and Version Management System #68894

@dwoz

Description

@dwoz

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

  1. salt/utils/versions.py: Added the core Requirement, Requirements, and Getters classes.
  2. 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).
  3. salt/utils/msgpack.py: Migrated to the new system to handle imports and exception aliasing more reliably.
  4. 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions