Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependencies: version check on sqlite C-language #6567

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review applied
  • Loading branch information
khsrali committed Oct 10, 2024
commit d178a5b63ccf33ce1d950956180b9ce2b5133714
17 changes: 1 addition & 16 deletions src/aiida/cmdline/commands/cmd_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
from aiida.cmdline.commands.cmd_verdi import verdi
from aiida.cmdline.params import options
from aiida.cmdline.utils import echo
from aiida.common.exceptions import (
CorruptStorage,
IncompatibleExternalDependencies,
IncompatibleStorageSchema,
UnreachableStorage,
)
from aiida.common.exceptions import CorruptStorage, IncompatibleStorageSchema, UnreachableStorage
from aiida.common.log import override_log_level
from aiida.common.warnings import warn_deprecation

Expand Down Expand Up @@ -101,12 +96,6 @@ def verdi_status(print_traceback, no_rmq):
storage_cls = profile.storage_cls
storage_head_version = storage_cls.version_head()
storage_backend = storage_cls(profile)

if storage_cls.__name__ in ['SqliteZipBackend', 'SqliteDosStorage']:
from aiida.storage.sqlite_zip.backend import validate_sqlite_version

validate_sqlite_version()

except UnreachableStorage as exc:
message = "Unable to connect to profile's storage."
print_status(ServiceStatus.DOWN, 'storage', message, exception=exc, print_traceback=print_traceback)
Expand All @@ -122,10 +111,6 @@ def verdi_status(print_traceback, no_rmq):
message = 'Storage is corrupted.'
print_status(ServiceStatus.DOWN, 'storage', message, exception=exc, print_traceback=print_traceback)
exit_code = ExitCode.CRITICAL
except IncompatibleExternalDependencies as exc:
message = "Storage backend version doesn't satisfy the requirements of the installed AiiDA version. "
print_status(ServiceStatus.DOWN, 'storage', message, exception=exc)
exit_code = ExitCode.CRITICAL
except Exception as exc:
message = "Unable to instatiate profile's storage."
print_status(ServiceStatus.ERROR, 'storage', message, exception=exc, print_traceback=print_traceback)
Expand Down
4 changes: 4 additions & 0 deletions src/aiida/storage/sqlite_dos/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ def initialise(cls, profile: Profile, reset: bool = False) -> bool:

return super().initialise(profile, reset)

def __init__(self, profile: Profile) -> None:
validate_sqlite_version()
super().__init__(profile)

def __str__(self) -> str:
state = 'closed' if self.is_closed else 'open'
return f'SqliteDosStorage[{self.filepath_root}]: {state},'
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/storage/sqlite_zip/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def version_head(cls) -> str:
def create_profile(filepath: str | Path, options: dict | None = None) -> Profile:
"""Create a new profile instance for this backend, from the path to the zip file."""
profile_name = Path(filepath).name
validate_sqlite_version()
return Profile(
profile_name,
{
Expand Down Expand Up @@ -185,6 +184,7 @@ def migrate(cls, profile: Profile):
def __init__(self, profile: Profile):
from .migrator import validate_storage

validate_sqlite_version()
super().__init__(profile)
self._path = Path(profile.storage_config['filepath'])
validate_storage(self._path)
Expand Down
2 changes: 1 addition & 1 deletion tests/cmdline/commands/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_setup_with_validating_sqlite_version(
config_psql_dos, run_cli_command, isolated_config, tmp_path, entry_point, monkeypatch
):
"""Test the ``verdi profile setup`` command.
Same as `test_setup`, here we check the fucntionality to check sqlite versions, before setting up profiles.
Same as `test_setup`, here we check the functionality to check sqlite versions, before setting up profiles.
Note that this test should be run before the `test_delete_storage` test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just to know if profile setup is failing, then I won't check why test_delete_storage is failing.
(Only because test_delete_storage creates profiles, also with the sqlite backend.)
I've the habit of putting them in such order, maybe it doesn't matter that much...

I took the comment away, as this is not a most just easier to debug this way..

"""

Expand Down
15 changes: 0 additions & 15 deletions tests/storage/sqlite_zip/test_backend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tests for :mod:`aiida.storage.sqlite_zip.backend`."""

import pathlib
from unittest.mock import MagicMock

import pytest
from aiida.common.exceptions import IncompatibleExternalDependencies
Expand Down Expand Up @@ -81,17 +80,3 @@ def test_validate_sqlite_version(monkeypatch):
monkeypatch.setattr('sqlite3.sqlite_version', '100.0.0')
monkeypatch.setattr('aiida.storage.sqlite_zip.backend.SUPPORTED_VERSION', '0.0.0')
validate_sqlite_version()


def test_initialise_version_check(tmp_path, monkeypatch):
"""Test :meth:`aiida.storage.sqlite_zip.backend.SqliteZipBackend.create_profile`
only if calls on validate_sqlite_version."""

filepath_archive = tmp_path / 'archive.zip'

mock_ = MagicMock()
monkeypatch.setattr('aiida.storage.sqlite_zip.backend.validate_sqlite_version', mock_)
profile = SqliteZipBackend.create_profile(filepath_archive)
assert mock_.call_count == 1
SqliteZipBackend.initialise(profile)
assert mock_.call_count == 2
Loading