Skip to content

Commit

Permalink
Testing: Add type annotations to did_meta_plugin_interface; #6588
Browse files Browse the repository at this point in the history
  • Loading branch information
rdimaio authored and bari12 committed Apr 17, 2024
1 parent 13ba29b commit 4b2ecaa
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions lib/rucio/core/did_meta_plugins/did_meta_plugin_interface.py
Expand Up @@ -13,15 +13,18 @@
# limitations under the License.

from abc import ABCMeta, abstractmethod
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Literal

from rucio.db.sqla.session import transactional_session

if TYPE_CHECKING:
from typing import Optional
from collections.abc import Iterator
from typing import Any, Optional, Union

from sqlalchemy.orm import Session

from rucio.common.types import InternalScope


class DidMetaPlugin(metaclass=ABCMeta):
"""
Expand All @@ -35,7 +38,13 @@ def __init__(self):
pass

@abstractmethod
def get_metadata(self, scope, name, *, session: "Optional[Session]" = None):
def get_metadata(
self,
scope: "InternalScope",
name: str,
*,
session: "Optional[Session]" = None
) -> "Any":
"""
Get data identifier metadata
Expand All @@ -46,7 +55,16 @@ def get_metadata(self, scope, name, *, session: "Optional[Session]" = None):
pass

@abstractmethod
def set_metadata(self, scope, name, key, value, recursive=False, *, session: "Optional[Session]" = None):
def set_metadata(
self,
scope: "InternalScope",
name: str,
key: str,
value: str,
recursive: bool = False,
*,
session: "Optional[Session]" = None
) -> None:
"""
Add metadata to data identifier.
Expand All @@ -61,7 +79,15 @@ def set_metadata(self, scope, name, key, value, recursive=False, *, session: "Op
pass

@transactional_session
def set_metadata_bulk(self, scope, name, meta, recursive=False, *, session: "Optional[Session]" = None):
def set_metadata_bulk(
self,
scope: "InternalScope",
name: str,
meta: dict[str, "Any"],
recursive: bool = False,
*,
session: "Optional[Session]" = None
) -> None:
"""
Add metadata to data identifier in bulk.
Expand All @@ -76,7 +102,14 @@ def set_metadata_bulk(self, scope, name, meta, recursive=False, *, session: "Opt
self.set_metadata(scope, name, key, value, recursive=recursive, session=session)

@abstractmethod
def delete_metadata(self, scope, name, key, *, session: "Session" = None):
def delete_metadata(
self,
scope: "InternalScope",
name: str,
key: str,
*,
session: "Optional[Session]" = None
) -> None:
"""
Deletes the metadata stored for the given key.
Expand All @@ -88,8 +121,19 @@ def delete_metadata(self, scope, name, key, *, session: "Session" = None):
pass

@abstractmethod
def list_dids(self, scope, filters, did_type='collection', ignore_case=False, limit=None,
offset=None, long=False, recursive=False, *, session: "Optional[Session]" = None):
def list_dids(
self,
scope: "InternalScope",
filters: dict[str, "Any"],
did_type: Literal['all', 'collection', 'dataset', 'container', 'file'] = 'collection',
ignore_case: bool = False,
limit: "Optional[int]" = None,
offset: "Optional[int]" = None,
long: bool = False,
recursive: bool = False,
*,
session: "Optional[Session]" = None
) -> "Iterator[Union[str, dict[str, Any]]]":
"""
Search data identifiers
Expand All @@ -106,7 +150,12 @@ def list_dids(self, scope, filters, did_type='collection', ignore_case=False, li
pass

@abstractmethod
def manages_key(self, key, *, session: "Optional[Session]" = None):
def manages_key(
self,
key: str,
*,
session: "Optional[Session]" = None
) -> bool:
"""
Returns whether key is managed by this plugin or not.
:param key: Key of the metadata.
Expand Down

0 comments on commit 4b2ecaa

Please sign in to comment.