Skip to content

Commit

Permalink
♻️ REFACTOR: aiida.backends -> aiida.storage
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Feb 18, 2022
1 parent 8dc3d8a commit e58f51f
Show file tree
Hide file tree
Showing 397 changed files with 287 additions and 289 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ repos:
pass_filenames: true
files: >-
(?x)^(
aiida/backends/control.py|
aiida/backends/psql_dos/backend.py|
aiida/backends/psql_dos/orm/querybuilder/.*py|
aiida/backends/psql_dos/utils.py|
aiida/common/progress_reporter.py|
aiida/engine/.*py|
aiida/manage/manager.py|
Expand Down Expand Up @@ -103,6 +99,10 @@ repos:
aiida/plugins/entry_point.py|
aiida/plugins/factories.py|
aiida/repository/.*py|
aiida/storage/control.py|
aiida/storage/psql_dos/backend.py|
aiida/storage/psql_dos/orm/querybuilder/.*py|
aiida/storage/psql_dos/utils.py|
aiida/tools/graph/graph_traversers.py|
aiida/tools/groups/paths.py|
aiida/tools/archive/.*py|
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ Changes between 1.0 alpha/beta releases are not included - for those see the cha
- AiiDA now enforces UTF-8 encoding for text output in its files and databases. [[#2107]](https://github.com/aiidateam/aiida-core/pull/2107)

#### Backwards-incompatible changes (only a sub-set)
- Remove `aiida.tests` and obsolete `aiida.backends.tests.test_parsers` entry point group [[#2778]](https://github.com/aiidateam/aiida-core/pull/2778)
- Remove `aiida.tests` and obsolete `aiida.storage.tests.test_parsers` entry point group [[#2778]](https://github.com/aiidateam/aiida-core/pull/2778)
- Implement new link types [[#2220]](https://github.com/aiidateam/aiida-core/pull/2220)
- Rename the type strings of `Groups` and change the attributes `name` and `type` to `label` and `type_string` [[#2329]](https://github.com/aiidateam/aiida-core/pull/2329)
- Make various protected `Node` methods public [[#2544]](https://github.com/aiidateam/aiida-core/pull/2544)
Expand Down
2 changes: 1 addition & 1 deletion aiida/cmdline/commands/cmd_devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def devel_run_sql(sql):
"""Run a raw SQL command on the profile database (only available for 'psql_dos' storage)."""
from sqlalchemy import text

from aiida.backends.psql_dos.utils import create_sqlalchemy_engine
from aiida.storage.psql_dos.utils import create_sqlalchemy_engine
assert get_profile().storage_backend == 'psql_dos'
with create_sqlalchemy_engine(get_profile().storage_config).connect() as connection:
result = connection.execute(text(sql)).fetchall()
Expand Down
4 changes: 2 additions & 2 deletions aiida/cmdline/commands/cmd_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def storage_integrity():
@click.option('--statistics', is_flag=True, help='Provides more in-detail statistically relevant data.')
def storage_info(statistics):
"""Summarise the contents of the storage."""
from aiida.backends.control import get_repository_info
from aiida.cmdline.utils.common import get_database_summary
from aiida.orm import QueryBuilder
from aiida.storage.control import get_repository_info

with spinner():
data = {
Expand All @@ -119,7 +119,7 @@ def storage_info(statistics):
)
def storage_maintain(full, dry_run):
"""Performs maintenance tasks on the repository."""
from aiida.backends.control import repository_maintain
from aiida.storage.control import repository_maintain

if full:
echo.echo_warning(
Expand Down
2 changes: 0 additions & 2 deletions aiida/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
def get_new_uuid():
"""
Return a new UUID (typically to be used for new nodes).
It uses the UUID version specified in
aiida.backends.settings.AIIDANODES_UUID_VERSION
"""
import uuid
return str(uuid.uuid4())
Expand Down
2 changes: 1 addition & 1 deletion aiida/manage/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def load_documentation_profile():
"""
import tempfile

from aiida.backends.psql_dos.models.base import get_orm_metadata
from aiida.storage.psql_dos.models.base import get_orm_metadata

from .config import Config

Expand Down
2 changes: 1 addition & 1 deletion aiida/manage/configuration/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def set_storage(self, name: str, config: Dict[str, Any]) -> None:
def storage_cls(self) -> Type['Backend']:
"""Return the storage backend class for this profile."""
if self.storage_backend == 'psql_dos':
from aiida.backends.psql_dos.backend import PsqlDosBackend
from aiida.storage.psql_dos.backend import PsqlDosBackend
return PsqlDosBackend
if self.storage_backend == 'archive.sqlite':
from aiida.tools.archive.implementations.sqlite.backend import ArchiveReadOnlyBackend
Expand Down
2 changes: 1 addition & 1 deletion aiida/manage/tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def __init__(self, profile_name):
:param profile_name: Name of the profile to be loaded
"""
from aiida import load_profile
from aiida.backends.testbase import check_if_tests_can_run
from aiida.storage.testbase import check_if_tests_can_run

self._profile = None
try:
Expand Down
2 changes: 1 addition & 1 deletion aiida/repository/backend/disk_object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def maintain( # type: ignore[override] # pylint: disable=arguments-differ,too-ma
:param do_vacuum:flag for forcing the vacuuming of the internal database when cleaning the repository.
:return:a dictionary with information on the operations performed.
"""
from aiida.backends.control import MAINTAIN_LOGGER
from aiida.storage.control import MAINTAIN_LOGGER

logger = MAINTAIN_LOGGER.getChild('disk_object_store')

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import click
from sqlalchemy.util.compat import nullcontext

from aiida.backends.psql_dos.migrator import PsqlDostoreMigrator
from aiida.cmdline import is_verbose
from aiida.cmdline.params import options
from aiida.storage.psql_dos.migrator import PsqlDostoreMigrator


class AlembicRunner:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from sqlalchemy import table
from sqlalchemy.orm import Session, scoped_session, sessionmaker

from aiida.backends.psql_dos.migrator import REPOSITORY_UUID_KEY, PsqlDostoreMigrator
from aiida.backends.psql_dos.models import base
from aiida.common.exceptions import ClosedStorage, IntegrityError
from aiida.manage.configuration.profile import Profile
from aiida.orm import User
from aiida.orm.entities import EntityTypes
from aiida.orm.implementation.backends import Backend
from aiida.orm.implementation.entities import BackendEntity
from aiida.storage.psql_dos.migrator import REPOSITORY_UUID_KEY, PsqlDostoreMigrator
from aiida.storage.psql_dos.models import base

from .orm import authinfos, comments, computers, convert, groups, logs, nodes, querybuilder, users

Expand Down Expand Up @@ -100,7 +100,7 @@ def _initialise_session(self):
Multi-thread support is currently required by the REST API.
Although, in the future, we may want to move the multi-thread handling to higher in the AiiDA stack.
"""
from aiida.backends.psql_dos.utils import create_sqlalchemy_engine
from aiida.storage.psql_dos.utils import create_sqlalchemy_engine
engine = create_sqlalchemy_engine(self._profile.storage_config)
self._session_factory = scoped_session(sessionmaker(bind=engine, future=True, expire_on_commit=True))

Expand All @@ -125,8 +125,8 @@ def close(self) -> None:
self._session_factory = None

def _clear(self, recreate_user: bool = True) -> None:
from aiida.backends.psql_dos.models.settings import DbSetting
from aiida.backends.psql_dos.models.user import DbUser
from aiida.storage.psql_dos.models.settings import DbSetting
from aiida.storage.psql_dos.models.user import DbUser

super()._clear(recreate_user)

Expand Down Expand Up @@ -237,13 +237,13 @@ def _get_mapper_from_entity(entity_type: EntityTypes, with_pk: bool):
"""
from sqlalchemy import inspect

from aiida.backends.psql_dos.models.authinfo import DbAuthInfo
from aiida.backends.psql_dos.models.comment import DbComment
from aiida.backends.psql_dos.models.computer import DbComputer
from aiida.backends.psql_dos.models.group import DbGroup, DbGroupNode
from aiida.backends.psql_dos.models.log import DbLog
from aiida.backends.psql_dos.models.node import DbLink, DbNode
from aiida.backends.psql_dos.models.user import DbUser
from aiida.storage.psql_dos.models.authinfo import DbAuthInfo
from aiida.storage.psql_dos.models.comment import DbComment
from aiida.storage.psql_dos.models.computer import DbComputer
from aiida.storage.psql_dos.models.group import DbGroup, DbGroupNode
from aiida.storage.psql_dos.models.log import DbLog
from aiida.storage.psql_dos.models.node import DbLink, DbNode
from aiida.storage.psql_dos.models.user import DbUser
model = {
EntityTypes.AUTHINFO: DbAuthInfo,
EntityTypes.COMMENT: DbComment,
Expand Down Expand Up @@ -297,8 +297,8 @@ def bulk_update(self, entity_type: EntityTypes, rows: List[dict]) -> None: # py

def delete_nodes_and_connections(self, pks_to_delete: Sequence[int]) -> None: # pylint: disable=no-self-use
# pylint: disable=no-value-for-parameter
from aiida.backends.psql_dos.models.group import DbGroupNode
from aiida.backends.psql_dos.models.node import DbLink, DbNode
from aiida.storage.psql_dos.models.group import DbGroupNode
from aiida.storage.psql_dos.models.node import DbLink, DbNode

if not self.in_transaction:
raise AssertionError('Cannot delete nodes and links outside a transaction')
Expand Down Expand Up @@ -326,7 +326,7 @@ def get_backend_entity(self, model: base.Base) -> BackendEntity:
def set_global_variable(
self, key: str, value: Union[None, str, int, float], description: Optional[str] = None, overwrite=True
) -> None:
from aiida.backends.psql_dos.models.settings import DbSetting
from aiida.storage.psql_dos.models.settings import DbSetting

session = self.get_session()
with (nullcontext() if self.in_transaction else self.transaction()):
Expand All @@ -339,7 +339,7 @@ def set_global_variable(
session.add(DbSetting(key=key, val=value, description=description or ''))

def get_global_variable(self, key: str) -> Union[None, str, int, float]:
from aiida.backends.psql_dos.models.settings import DbSetting
from aiida.storage.psql_dos.models.settings import DbSetting

session = self.get_session()
with (nullcontext() if self.in_transaction else self.transaction()):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ def run_migrations_online():
"""

# pylint: disable=unused-import
from aiida.backends.psql_dos.models.authinfo import DbAuthInfo
from aiida.backends.psql_dos.models.base import Base
from aiida.backends.psql_dos.models.comment import DbComment
from aiida.backends.psql_dos.models.computer import DbComputer
from aiida.backends.psql_dos.models.group import DbGroup
from aiida.backends.psql_dos.models.log import DbLog
from aiida.backends.psql_dos.models.node import DbLink, DbNode
from aiida.backends.psql_dos.models.settings import DbSetting
from aiida.backends.psql_dos.models.user import DbUser
from aiida.common.exceptions import DbContentError
from aiida.storage.psql_dos.models.authinfo import DbAuthInfo
from aiida.storage.psql_dos.models.base import Base
from aiida.storage.psql_dos.models.comment import DbComment
from aiida.storage.psql_dos.models.computer import DbComputer
from aiida.storage.psql_dos.models.group import DbGroup
from aiida.storage.psql_dos.models.log import DbLog
from aiida.storage.psql_dos.models.node import DbLink, DbNode
from aiida.storage.psql_dos.models.settings import DbSetting
from aiida.storage.psql_dos.models.user import DbUser
config = context.config # pylint: disable=no-member

connection = config.attributes.get('connection', None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.sql import column, func, select, table, text

from aiida.backends.psql_dos.backend import CONTAINER_DEFAULTS
from aiida.backends.psql_dos.migrations.utils import utils
from aiida.cmdline.utils import echo
from aiida.common import exceptions
from aiida.common.progress_reporter import get_progress_reporter, set_progress_bar_tqdm, set_progress_reporter
from aiida.storage.psql_dos.backend import CONTAINER_DEFAULTS
from aiida.storage.psql_dos.migrations.utils import utils


def migrate_repository(connection, profile):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""Utilities for synchronizing the django and sqlalchemy schema."""
import alembic

from aiida.backends.psql_dos.migrations.utils import ReflectMigrations
from aiida.storage.psql_dos.migrations.utils import ReflectMigrations


def synchronize_schemas(alembic_op: alembic.op) -> None:
Expand All @@ -20,7 +20,7 @@ def synchronize_schemas(alembic_op: alembic.op) -> None:
2. Remove and recreate all unique constraints, with standard names.
3. Remove and recreate all foreign key constraints, with standard names and other rules.
Schema naming conventions are defined ``aiida/backends/sqlalchemy/models/base.py::naming_convention``.
Schema naming conventions are defined ``aiida/storage/sqlalchemy/models/base.py::naming_convention``.
Note we assume here that (a) all primary keys are already correct, and (b) there are no check constraints.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import sqlalchemy as sa
from sqlalchemy.sql import text

from aiida.backends.psql_dos.migrations.utils.dblog_update import export_and_clean_workflow_logs
from aiida.storage.psql_dos.migrations.utils.dblog_update import export_and_clean_workflow_logs

# revision identifiers, used by Alembic.
revision = '041a79fc615f'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.sql import column, func, select, table

from aiida.backends.psql_dos.migrations.utils.utils import load_numpy_array_from_repository
from aiida.storage.psql_dos.migrations.utils.utils import load_numpy_array_from_repository

# revision identifiers, used by Alembic.
revision = '12536798d4d3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""
from alembic import op

from aiida.backends.psql_dos.migrations.utils.legacy_workflows import export_workflow_data
from aiida.storage.psql_dos.migrations.utils.legacy_workflows import export_workflow_data

# revision identifiers, used by Alembic.
revision = '1b8ed3425af9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""
from alembic import op

from aiida.backends.psql_dos.migrations.utils.parity import synchronize_schemas
from aiida.storage.psql_dos.migrations.utils.parity import synchronize_schemas

revision = '1de112340b18'
down_revision = '1de112340b17'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def upgrade():
"""Migrations for the upgrade."""
from aiida.backends.psql_dos.migrations.utils.migrate_repository import migrate_repository
from aiida.storage.psql_dos.migrations.utils.migrate_repository import migrate_repository

migrate_repository(op.get_bind(), op.get_context().opts['aiida_profile'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def upgrade():
"""Migrations for the upgrade."""
from aiida.backends.psql_dos.migrations.utils import provenance_redesign
from aiida.storage.psql_dos.migrations.utils import provenance_redesign

# Migrate calculation nodes by inferring the process type from the type string
provenance_redesign.migrate_infer_calculation_entry_point(op)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

def upgrade():
"""Migrations for the upgrade."""
from aiida.backends.psql_dos.migrations.utils.duplicate_uuids import verify_uuid_uniqueness
from aiida.storage.psql_dos.migrations.utils.duplicate_uuids import verify_uuid_uniqueness
for table in tables:
verify_uuid_uniqueness(table, op.get_bind())
op.create_unique_constraint(f'{table}_uuid_key', table, ['uuid'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def upgrade():
"""Migrations for the upgrade."""
from aiida.backends.psql_dos.migrations.utils.duplicate_uuids import verify_uuid_uniqueness
from aiida.storage.psql_dos.migrations.utils.duplicate_uuids import verify_uuid_uniqueness
verify_uuid_uniqueness('db_dbnode', op.get_bind())
op.create_unique_constraint('db_dbnode_uuid_key', 'db_dbnode', ['uuid'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.sql import column, select, table, text

from aiida.backends.psql_dos.migrations.utils import utils
from aiida.storage.psql_dos.migrations.utils import utils

# revision identifiers, used by Alembic.
revision = 'ce56d84bcc35'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from alembic import op
import sqlalchemy as sa

from aiida.backends.psql_dos.migrations.utils import ReflectMigrations
from aiida.storage.psql_dos.migrations.utils import ReflectMigrations

revision = 'django_0003'
down_revision = 'django_0002'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from alembic import op
import sqlalchemy as sa

from aiida.backends.psql_dos.migrations.utils import ReflectMigrations
from aiida.storage.psql_dos.migrations.utils import ReflectMigrations

revision = 'django_0013'
down_revision = 'django_0012'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

def upgrade():
"""Migrations for the upgrade."""
from aiida.backends.psql_dos.migrations.utils.duplicate_uuids import verify_uuid_uniqueness
from aiida.storage.psql_dos.migrations.utils.duplicate_uuids import verify_uuid_uniqueness
verify_uuid_uniqueness('db_dbnode', op.get_bind())
op.create_unique_constraint('db_dbnode_uuid_62e0bf98_uniq', 'db_dbnode', ['uuid'])
op.drop_index('db_dbnode_uuid_62e0bf98', table_name='db_dbnode')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from aiida.backends.psql_dos.migrations.utils import ReflectMigrations
from aiida.backends.psql_dos.migrations.utils.duplicate_uuids import verify_uuid_uniqueness
from aiida.storage.psql_dos.migrations.utils import ReflectMigrations
from aiida.storage.psql_dos.migrations.utils.duplicate_uuids import verify_uuid_uniqueness

revision = 'django_0018'
down_revision = 'django_0017'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

def upgrade():
"""Migrations for the upgrade."""
from aiida.backends.psql_dos.migrations.utils import provenance_redesign
from aiida.storage.psql_dos.migrations.utils import provenance_redesign

# Migrate calculation nodes by inferring the process type from the type string
provenance_redesign.migrate_infer_calculation_entry_point(op)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""
from alembic import op

from aiida.backends.psql_dos.migrations.utils import ReflectMigrations
from aiida.storage.psql_dos.migrations.utils import ReflectMigrations

revision = 'django_0021'
down_revision = 'django_0020'
Expand Down
Loading

0 comments on commit e58f51f

Please sign in to comment.