Skip to content

Commit

Permalink
Remove custom command line interface
Browse files Browse the repository at this point in the history
The package shipped with its own CLI `aiida-s3`. The only function was
to provide a command that allowed creating new AiiDA profiles using any
of the storage backends. As of `aiida-core==2.5`, the command
`verdi profile setup` was added to `verdi` that dynamically creates a
subcommand for each storage plugin that is registered.

The requirement is updated to `aiida-core~=2.5`. The custom CLI is
removed entirely. The storage plugins remove the `_get_cli_options`
methods and adds the new pydantic model definition that replaces it.
  • Loading branch information
sphuber committed Apr 2, 2024
1 parent e7a0b29 commit edd81f1
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 427 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
'Topic :: Scientific/Engineering'
]
dependencies = [
'aiida-core~=2.4.0',
'aiida-core~=2.5.0',
'azure-storage-blob',
'boto3'
]
Expand Down
12 changes: 0 additions & 12 deletions src/aiida_s3/cli/__init__.py

This file was deleted.

92 changes: 0 additions & 92 deletions src/aiida_s3/cli/cmd_profile.py

This file was deleted.

60 changes: 23 additions & 37 deletions src/aiida_s3/storage/psql_aws_s3.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Implementation of :class:`aiida.orm.implementation.storage_backend.StorageBackend` using PostgreSQL + AWS S3."""
from __future__ import annotations

import typing as t
from aiida.storage.psql_dos import PsqlDosBackend
from pydantic import Field

from ..repository.aws_s3 import AwsS3RepositoryBackend
from .psql_dos import BasePsqlDosBackend
from .psql_s3 import PsqlS3StorageMigrator


Expand All @@ -26,48 +26,34 @@ def get_repository(self) -> AwsS3RepositoryBackend:
)


class PsqlAwsS3Storage(BasePsqlDosBackend):
class PsqlAwsS3Storage(PsqlDosBackend):
"""Storage backend using PostgresSQL and AWS S3."""

migrator = PsqlAwsS3StorageMigrator

class Configuration(PsqlDosBackend.Configuration):
"""Model describing required information to configure an instance of the storage."""

aws_access_key_id: str = Field(
title='AWS access key ID',
description='The AWS access key ID.',
)
aws_secret_access_key: str = Field(
title='AWS secret access key',
description='The AWS secret access key.',
)
aws_region_name: str = Field(
title='AWS region',
description='The AWS region name code, e.g., `eu-central-1`.',
)
aws_bucket_name: str = Field(
title='AWS bucket name',
description='The name of the AWS S3 bucket to use.',
)

def get_repository(self) -> AwsS3RepositoryBackend: # type: ignore[override]
"""Return the file repository backend instance.
:returns: The repository of the configured profile.
"""
return self.migrator(self.profile).get_repository()

@classmethod
def _get_cli_options(cls) -> dict[str, t.Any]:
"""Return the CLI options that would allow to create an instance of this class."""
options = super()._get_cli_options()
options.update(
**{
'aws_access_key_id': {
'required': True,
'type': str,
'prompt': 'AWS access key ID',
'help': 'The AWS access key ID.',
},
'aws_secret_access_key': {
'required': True,
'type': str,
'prompt': 'AWS secret access key',
'help': 'The AWS secret access key.',
},
'aws_region_name': {
'required': True,
'type': str,
'prompt': 'AWS region',
'help': 'The AWS region name code, e.g., `eu-central-1`.',
},
'aws_bucket_name': {
'required': True,
'type': str,
'prompt': 'AWS bucket name',
'help': 'The name of the AWS S3 bucket to use.',
},
}
)
return options
40 changes: 15 additions & 25 deletions src/aiida_s3/storage/psql_azure_blob.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Implementation of :class:`aiida.orm.implementation.storage_backend.StorageBackend` using PostgreSQL + Azure."""
from __future__ import annotations

import typing as t
from aiida.storage.psql_dos.backend import PsqlDosBackend
from pydantic import Field

from ..repository.azure_blob import AzureBlobStorageRepositoryBackend
from .psql_dos import BasePsqlDosBackend
from .psql_s3 import PsqlS3StorageMigrator


Expand All @@ -30,36 +30,26 @@ def get_repository(self) -> AzureBlobStorageRepositoryBackend: # type: ignore[o
)


class PsqlAzureBlobStorage(BasePsqlDosBackend):
class PsqlAzureBlobStorage(PsqlDosBackend):
"""Storage backend using PostgresSQL and Azure Blob Storage."""

migrator = PsqlAzureBlobStorageMigrator

class Configuration(PsqlDosBackend.Configuration):
"""Model describing required information to configure an instance of the storage."""

container_name: str = Field(
title='Container name',
description='The Azure Blob Storage container name.',
)
connection_string: str = Field(
title='Connection string',
description='The Azure Blob Storage connection string.',
)

def get_repository(self) -> AzureBlobStorageRepositoryBackend: # type: ignore[override]
"""Return the file repository backend instance.
:returns: The repository of the configured profile.
"""
return self.migrator(self.profile).get_repository()

@classmethod
def _get_cli_options(cls) -> dict[str, t.Any]:
"""Return the CLI options that would allow to create an instance of this class."""
options = super()._get_cli_options()
options.update(
**{
'container_name': {
'required': True,
'type': str,
'prompt': 'Container name',
'help': 'The Azure Blob Storage container name.',
},
'connection_string': {
'required': True,
'type': str,
'prompt': 'Connection string',
'help': 'The Azure Blob Storage connection string.',
},
}
)
return options
80 changes: 0 additions & 80 deletions src/aiida_s3/storage/psql_dos.py

This file was deleted.

Loading

0 comments on commit edd81f1

Please sign in to comment.