Skip to content

Commit

Permalink
chore(anta): Add deprecation on deprecated method (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc authored Mar 5, 2025
1 parent b870e13 commit 083d51f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
15 changes: 4 additions & 11 deletions anta/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
from json import load as json_load
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal, Optional, Union
from warnings import warn

from pydantic import BaseModel, ConfigDict, RootModel, ValidationError, ValidationInfo, field_validator, model_serializer, model_validator
from pydantic.types import ImportString
from pydantic_core import PydanticCustomError
from typing_extensions import deprecated
from yaml import YAMLError, safe_dump, safe_load

from anta.logger import anta_log_exception
Expand Down Expand Up @@ -440,13 +440,12 @@ def merge_catalogs(cls, catalogs: list[AntaCatalog]) -> AntaCatalog:
combined_tests = list(chain(*(catalog.tests for catalog in catalogs)))
return cls(tests=combined_tests)

@deprecated(
"This method is deprecated, use `AntaCatalogs.merge_catalogs` class method instead. This will be removed in ANTA v2.0.0.", category=DeprecationWarning
)
def merge(self, catalog: AntaCatalog) -> AntaCatalog:
"""Merge two AntaCatalog instances.
Warning
-------
This method is deprecated and will be removed in ANTA v2.0. Use `AntaCatalog.merge_catalogs()` instead.
Parameters
----------
catalog
Expand All @@ -457,12 +456,6 @@ def merge(self, catalog: AntaCatalog) -> AntaCatalog:
AntaCatalog
A new AntaCatalog instance containing the tests of the two instances.
"""
# TODO: Use a decorator to deprecate this method instead. See https://github.com/aristanetworks/anta/issues/754
warn(
message="AntaCatalog.merge() is deprecated and will be removed in ANTA v2.0. Use AntaCatalog.merge_catalogs() instead.",
category=DeprecationWarning,
stacklevel=2,
)
return self.merge_catalogs([self, catalog])

def dump(self) -> AntaCatalogFile:
Expand Down
4 changes: 4 additions & 0 deletions anta/result_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ def filter(self, hide: set[AntaTestStatus]) -> ResultManager:
manager.results = self.get_results(possible_statuses - hide)
return manager

@deprecated("This method is deprecated. This will be removed in ANTA v2.0.0.", category=DeprecationWarning)
def filter_by_tests(self, tests: set[str]) -> ResultManager:
"""Get a filtered ResultManager that only contains specific tests.
Expand All @@ -333,6 +334,7 @@ def filter_by_tests(self, tests: set[str]) -> ResultManager:
manager.results = [result for result in self._result_entries if result.test in tests]
return manager

@deprecated("This method is deprecated. This will be removed in ANTA v2.0.0.", category=DeprecationWarning)
def filter_by_devices(self, devices: set[str]) -> ResultManager:
"""Get a filtered ResultManager that only contains specific devices.
Expand All @@ -350,6 +352,7 @@ def filter_by_devices(self, devices: set[str]) -> ResultManager:
manager.results = [result for result in self._result_entries if result.name in devices]
return manager

@deprecated("This method is deprecated. This will be removed in ANTA v2.0.0.", category=DeprecationWarning)
def get_tests(self) -> set[str]:
"""Get the set of all the test names.
Expand All @@ -360,6 +363,7 @@ def get_tests(self) -> set[str]:
"""
return {str(result.test) for result in self._result_entries}

@deprecated("This method is deprecated. This will be removed in ANTA v2.0.0.", category=DeprecationWarning)
def get_devices(self) -> set[str]:
"""Get the set of all the device names.
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ dependencies = [
"pydantic-extra-types>=2.3.0",
"PyYAML>=6.0",
"requests>=2.31.0",
"rich>=13.5.2,<14"
"rich>=13.5.2,<14",
"typing_extensions>=4.12" # required for deprecated before Python 3.13
]
keywords = ["test", "anta", "Arista", "network", "automation", "networking", "devops", "netdevops"]
classifiers = [
Expand Down

0 comments on commit 083d51f

Please sign in to comment.