Skip to content

Commit 1571e65

Browse files
authored
Merge pull request #1821 from eve-mem/deprecation_warning_for_PluginRequirement
Add a deprecation warning for PluginRequirement
2 parents 9fd7347 + 3ce515b commit 1571e65

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

volatility3/framework/__init__.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import traceback
1414
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, TypeVar
1515

16-
from volatility3.framework import constants, interfaces
16+
from volatility3.framework import constants, interfaces, versionutils
1717

1818
if (
1919
sys.version_info.major != constants.REQUIRED_PYTHON_VERSION[0]
@@ -48,19 +48,13 @@ def interface_version() -> Tuple[int, int, int]:
4848

4949
def require_interface_version(*args) -> None:
5050
"""Checks the required version of a plugin."""
51-
if len(args):
52-
if args[0] != interface_version()[0]:
53-
raise RuntimeError(
54-
f"Framework interface version {interface_version()[0]} is incompatible with required version {args[0]}"
51+
if not versionutils.matches_required(args, interface_version()):
52+
raise RuntimeError(
53+
"Framework interface version {} is incompatible with required version {}".format(
54+
".".join(str(x) for x in interface_version()[0:2]),
55+
".".join(str(x) for x in args[0:2]),
5556
)
56-
if len(args) > 1:
57-
if args[1] > interface_version()[1]:
58-
raise RuntimeError(
59-
"Framework interface version {} is an older revision than the required version {}".format(
60-
".".join(str(x) for x in interface_version()[0:2]),
61-
".".join(str(x) for x in args[0:2]),
62-
)
63-
)
57+
)
6458

6559

6660
class NonInheritable:

volatility3/framework/configuration/requirements.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from typing import Any, ClassVar, Dict, List, Optional, Set, Tuple, Type
1515
from urllib import parse, request
1616

17-
from volatility3.framework import constants, interfaces
17+
from volatility3.framework import constants, interfaces, deprecation, versionutils
1818

1919
vollog = logging.getLogger(__name__)
2020

@@ -551,7 +551,7 @@ def unsatisfied(
551551
) -> Dict[str, interfaces.configuration.RequirementInterface]:
552552
# Mypy doesn't appreciate our classproperty implementation, self._plugin.version has no type
553553
config_path = interfaces.configuration.path_join(config_path, self.name)
554-
if not self.matches_required(self._version, self._component.version):
554+
if not versionutils.matches_required(self._version, self._component.version):
555555
return {config_path: self}
556556

557557
recurse = True
@@ -593,13 +593,14 @@ def unsatisfied(
593593
def matches_required(
594594
cls, required: Tuple[int, ...], version: Tuple[int, int, int]
595595
) -> bool:
596-
if len(required) > 0 and version[0] != required[0]:
597-
return False
598-
if len(required) > 1 and version[1] < required[1]:
599-
return False
600-
return True
596+
return versionutils.matches_required(required, version)
601597

602598

599+
@deprecation.renamed_class(
600+
deprecated_class_name="PluginRequirement",
601+
removal_date="2026-06-01",
602+
message="PluginRequirement is to be deprecated. Use VersionRequirement instead.",
603+
)
603604
class PluginRequirement(VersionRequirement):
604605
def __init__(
605606
self,

volatility3/framework/deprecation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
from typing import Callable, Tuple
1212

13-
from volatility3.framework import interfaces, exceptions
14-
from volatility3.framework.configuration import requirements
13+
from volatility3.framework import interfaces, exceptions, versionutils
1514

1615

1716
def method_being_removed(message: str, removal_date: str):
@@ -70,7 +69,7 @@ def wrapper(*args, **kwargs):
7069
interfaces.configuration.VersionableInterface,
7170
):
7271
# SemVer check
73-
if not requirements.VersionRequirement.matches_required(
72+
if not versionutils.matches_required(
7473
replacement_version, replacement_base_class.version
7574
):
7675
raise exceptions.VersionMismatchException(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file is Copyright 2025 Volatility Foundation and licensed under the Volatility Software License 1.0
2+
# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0
3+
#
4+
5+
from typing import Tuple
6+
7+
8+
def matches_required(required: Tuple[int, ...], version: Tuple[int, int, int]) -> bool:
9+
"""
10+
Checks if a version tuple satisfies the required version major and minor constraints.
11+
12+
Parameters:
13+
required (Tuple[int, ...]): A tuple containing required major and optionally minor version numbers.
14+
version (Tuple[int, int, int]): A tuple containing the full version (major, minor, patch).
15+
16+
Returns:
17+
bool: True if the version matches the required constraints, False otherwise.
18+
"""
19+
if len(required) > 0 and version[0] != required[0]:
20+
return False
21+
if len(required) > 1 and version[1] < required[1]:
22+
return False
23+
return True

0 commit comments

Comments
 (0)