Skip to content

Commit

Permalink
♻️ REFACTOR: backends.Backend -> storage_backend.StorageBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Feb 18, 2022
1 parent e58f51f commit 18e1515
Show file tree
Hide file tree
Showing 26 changed files with 105 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ repos:
aiida/manage/database/delete/nodes.py|
aiida/orm/querybuilder.py|
aiida/orm/implementation/entities.py|
aiida/orm/implementation/backends.py|
aiida/orm/implementation/storage_backend.py|
aiida/orm/implementation/authinfos.py|
aiida/orm/implementation/comments.py|
aiida/orm/implementation/computers.py|
Expand Down
4 changes: 2 additions & 2 deletions aiida/manage/configuration/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .settings import DAEMON_DIR, DAEMON_LOG_DIR

if TYPE_CHECKING:
from aiida.orm.implementation.backends import Backend
from aiida.orm.implementation import StorageBackend

__all__ = ('Profile',)

Expand Down Expand Up @@ -121,7 +121,7 @@ def set_storage(self, name: str, config: Dict[str, Any]) -> None:
self._attributes[self.KEY_STORAGE][self.KEY_STORAGE_CONFIG] = config

@property
def storage_cls(self) -> Type['Backend']:
def storage_cls(self) -> Type['StorageBackend']:
"""Return the storage backend class for this profile."""
if self.storage_backend == 'psql_dos':
from aiida.storage.psql_dos.backend import PsqlDosBackend
Expand Down
8 changes: 4 additions & 4 deletions aiida/manage/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from aiida.engine.runners import Runner
from aiida.manage.configuration.config import Config
from aiida.manage.configuration.profile import Profile
from aiida.orm.implementation import Backend
from aiida.orm.implementation import StorageBackend

__all__ = ('get_manager',)

Expand Down Expand Up @@ -64,7 +64,7 @@ class Manager:
def __init__(self) -> None:
# note: the config currently references the global variables
self._profile: Optional['Profile'] = None
self._profile_storage: Optional['Backend'] = None
self._profile_storage: Optional['StorageBackend'] = None
self._daemon_client: Optional['DaemonClient'] = None
self._communicator: Optional['RmqThreadCommunicator'] = None
self._process_controller: Optional['RemoteProcessThreadController'] = None
Expand Down Expand Up @@ -193,7 +193,7 @@ def get_option(self, option_name: str) -> Any:
option = get_option(option_name)
return option.default

def get_backend(self) -> 'Backend':
def get_backend(self) -> 'StorageBackend':
"""Return the current profile's storage backend, loading it if necessary.
Deprecated: use `get_profile_storage` instead.
Expand All @@ -202,7 +202,7 @@ def get_backend(self) -> 'Backend':
warn('get_backend() is deprecated, use get_profile_storage() instead', AiidaDeprecationWarning)
return self.get_profile_storage()

def get_profile_storage(self) -> 'Backend':
def get_profile_storage(self) -> 'StorageBackend':
"""Return the current profile's storage backend, loading it if necessary."""
from aiida.common import ConfigurationError
from aiida.common.log import configure_logging
Expand Down
4 changes: 2 additions & 2 deletions aiida/orm/authinfos.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

if TYPE_CHECKING:
from aiida.orm import Computer, User
from aiida.orm.implementation import Backend, BackendAuthInfo
from aiida.orm.implementation import BackendAuthInfo, StorageBackend
from aiida.transports import Transport

__all__ = ('AuthInfo',)
Expand Down Expand Up @@ -51,7 +51,7 @@ def objects(cls: Type['AuthInfo']) -> AuthInfoCollection: # type: ignore[misc]

PROPERTY_WORKDIR = 'workdir'

def __init__(self, computer: 'Computer', user: 'User', backend: Optional['Backend'] = None) -> None:
def __init__(self, computer: 'Computer', user: 'User', backend: Optional['StorageBackend'] = None) -> None:
"""Create an `AuthInfo` instance for the given computer and user.
:param computer: a `Computer` instance
Expand Down
6 changes: 4 additions & 2 deletions aiida/orm/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

if TYPE_CHECKING:
from aiida.orm import Node, User
from aiida.orm.implementation import Backend, BackendComment
from aiida.orm.implementation import BackendComment, StorageBackend

__all__ = ('Comment',)

Expand Down Expand Up @@ -72,7 +72,9 @@ class Comment(entities.Entity['BackendComment']):
def objects(cls: Type['Comment']) -> CommentCollection: # type: ignore[misc] # pylint: disable=no-self-argument
return CommentCollection.get_cached(cls, get_manager().get_profile_storage())

def __init__(self, node: 'Node', user: 'User', content: Optional[str] = None, backend: Optional['Backend'] = None):
def __init__(
self, node: 'Node', user: 'User', content: Optional[str] = None, backend: Optional['StorageBackend'] = None
):
"""Create a Comment for a given node and user
:param node: a Node instance
Expand Down
4 changes: 2 additions & 2 deletions aiida/orm/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

if TYPE_CHECKING:
from aiida.orm import AuthInfo, User
from aiida.orm.implementation import Backend, BackendComputer
from aiida.orm.implementation import BackendComputer, StorageBackend
from aiida.schedulers import Scheduler
from aiida.transports import Transport

Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__( # pylint: disable=too-many-arguments
transport_type: str = '',
scheduler_type: str = '',
workdir: str = None,
backend: Optional['Backend'] = None,
backend: Optional['StorageBackend'] = None,
) -> None:
"""Construct a new computer."""
backend = backend or get_manager().get_profile_storage()
Expand Down
20 changes: 10 additions & 10 deletions aiida/orm/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from aiida.manage import get_manager

if TYPE_CHECKING:
from aiida.orm.implementation import Backend, BackendEntity
from aiida.orm.implementation import BackendEntity, StorageBackend
from aiida.orm.querybuilder import FilterType, OrderByType, QueryBuilder

__all__ = ('Entity', 'Collection', 'EntityAttributesMixin', 'EntityExtrasMixin', 'EntityTypes')
Expand Down Expand Up @@ -56,28 +56,28 @@ def _entity_base_cls() -> Type[EntityType]:

@classmethod
@lru_cache(maxsize=100)
def get_cached(cls, entity_class: Type[EntityType], backend: 'Backend'):
def get_cached(cls, entity_class: Type[EntityType], backend: 'StorageBackend'):
"""Get the cached collection instance for the given entity class and backend.
:param backend: the backend instance to get the collection for
"""
from aiida.orm.implementation import Backend
type_check(backend, Backend)
from aiida.orm.implementation import StorageBackend
type_check(backend, StorageBackend)
return cls(entity_class, backend=backend)

def __init__(self, entity_class: Type[EntityType], backend: Optional['Backend'] = None) -> None:
def __init__(self, entity_class: Type[EntityType], backend: Optional['StorageBackend'] = None) -> None:
""" Construct a new entity collection.
:param entity_class: the entity type e.g. User, Computer, etc
:param backend: the backend instance to get the collection for, or use the default
"""
from aiida.orm.implementation import Backend
type_check(backend, Backend, allow_none=True)
from aiida.orm.implementation import StorageBackend
type_check(backend, StorageBackend, allow_none=True)
assert issubclass(entity_class, self._entity_base_cls())
self._backend = backend or get_manager().get_profile_storage()
self._entity_type = entity_class

def __call__(self: CollectionType, backend: 'Backend') -> CollectionType:
def __call__(self: CollectionType, backend: 'StorageBackend') -> CollectionType:
"""Get or create a cached collection using a new backend."""
if backend is self._backend:
return self
Expand All @@ -89,7 +89,7 @@ def entity_type(self) -> Type[EntityType]:
return self._entity_type

@property
def backend(self) -> 'Backend':
def backend(self) -> 'StorageBackend':
"""Return the backend."""
return self._backend

Expand Down Expand Up @@ -244,7 +244,7 @@ def is_stored(self) -> bool:
return self._backend_entity.is_stored

@property
def backend(self) -> 'Backend':
def backend(self) -> 'StorageBackend':
"""Get the backend for this entity"""
return self._backend_entity.backend

Expand Down
4 changes: 2 additions & 2 deletions aiida/orm/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

if TYPE_CHECKING:
from aiida.orm import Node, User
from aiida.orm.implementation import Backend, BackendGroup
from aiida.orm.implementation import BackendGroup, StorageBackend

__all__ = ('Group', 'AutoGroup', 'ImportGroup', 'UpfFamily')

Expand Down Expand Up @@ -127,7 +127,7 @@ def __init__(
user: Optional['User'] = None,
description: str = '',
type_string: Optional[str] = None,
backend: Optional['Backend'] = None
backend: Optional['StorageBackend'] = None
):
"""
Create a new group. Either pass a dbgroup parameter, to reload
Expand Down
4 changes: 2 additions & 2 deletions aiida/orm/implementation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
# pylint: disable=wildcard-import

from .authinfos import *
from .backends import *
from .comments import *
from .computers import *
from .entities import *
from .groups import *
from .logs import *
from .nodes import *
from .querybuilder import *
from .storage_backend import *
from .users import *
from .utils import *

__all__ = (
'Backend',
'BackendAuthInfo',
'BackendAuthInfoCollection',
'BackendCollection',
Expand All @@ -47,6 +46,7 @@
'BackendUser',
'BackendUserCollection',
'EntityType',
'StorageBackend',
'clean_value',
'validate_attribute_extra_key',
)
Expand Down
10 changes: 5 additions & 5 deletions aiida/orm/implementation/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import TYPE_CHECKING, Any, ClassVar, Dict, Generic, Iterable, List, Tuple, Type, TypeVar

if TYPE_CHECKING:
from aiida.orm.implementation import Backend
from aiida.orm.implementation import StorageBackend

__all__ = ('BackendEntity', 'BackendCollection', 'EntityType', 'BackendEntityExtrasMixin')

Expand All @@ -22,11 +22,11 @@
class BackendEntity(abc.ABC):
"""An first-class entity in the backend"""

def __init__(self, backend: 'Backend', **kwargs: Any): # pylint: disable=unused-argument
def __init__(self, backend: 'StorageBackend', **kwargs: Any): # pylint: disable=unused-argument
self._backend = backend

@property
def backend(self) -> 'Backend':
def backend(self) -> 'StorageBackend':
"""Return the backend this entity belongs to
:return: the backend instance
Expand Down Expand Up @@ -74,15 +74,15 @@ class BackendCollection(Generic[EntityType]):

ENTITY_CLASS: ClassVar[Type[EntityType]] # type: ignore[misc]

def __init__(self, backend: 'Backend'):
def __init__(self, backend: 'StorageBackend'):
"""
:param backend: the backend this collection belongs to
"""
assert issubclass(self.ENTITY_CLASS, BackendEntity), 'Must set the ENTRY_CLASS class variable to an entity type'
self._backend = backend

@property
def backend(self) -> 'Backend':
def backend(self) -> 'StorageBackend':
"""Return the backend."""
return self._backend

Expand Down
8 changes: 4 additions & 4 deletions aiida/orm/implementation/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from aiida.orm.entities import EntityTypes

if TYPE_CHECKING:
from aiida.orm.implementation import Backend
from aiida.orm.implementation import StorageBackend

__all__ = ('BackendQueryBuilder',)

Expand Down Expand Up @@ -80,12 +80,12 @@ class QueryDictType(TypedDict):
class BackendQueryBuilder(abc.ABC):
"""Backend query builder interface"""

def __init__(self, backend: 'Backend'):
def __init__(self, backend: 'StorageBackend'):
"""
:param backend: the backend
"""
from . import backends
type_check(backend, backends.Backend)
from .storage_backend import StorageBackend
type_check(backend, StorageBackend)
self._backend = backend

@abc.abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
)
from aiida.repository.backend.abstract import AbstractRepositoryBackend

__all__ = ('Backend',)
__all__ = ('StorageBackend',)

TransactionType = TypeVar('TransactionType')


class Backend(abc.ABC): # pylint: disable=too-many-public-methods
class StorageBackend(abc.ABC): # pylint: disable=too-many-public-methods
"""Abstraction for a backend to read/write persistent data for a profile's provenance graph.
AiiDA splits data storage into two sources:
Expand Down
4 changes: 2 additions & 2 deletions aiida/orm/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

if TYPE_CHECKING:
from aiida.orm import Node
from aiida.orm.implementation import Backend, BackendLog
from aiida.orm.implementation import BackendLog, StorageBackend
from aiida.orm.querybuilder import FilterType, OrderByType

__all__ = ('Log', 'OrderSpecifier', 'ASCENDING', 'DESCENDING')
Expand Down Expand Up @@ -142,7 +142,7 @@ def __init__(
dbnode_id: int,
message: str = '',
metadata: Optional[Dict[str, Any]] = None,
backend: Optional['Backend'] = None
backend: Optional['StorageBackend'] = None
): # pylint: disable=too-many-arguments
"""Construct a new log
Expand Down
Loading

0 comments on commit 18e1515

Please sign in to comment.