Skip to content

Commit

Permalink
Devops: Update pre-commit configuration
Browse files Browse the repository at this point in the history
* Drop `yapf`, `isort`, `pylint` and `pydocstyle` in favor of `ruff`
* Remove all encoding pragma, only necessary for Python 2
* Add temporary upper limit `aiida-core<2.4`
  • Loading branch information
sphuber authored Nov 14, 2023
1 parent 11c3968 commit 9e54d4d
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 171 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/validate_release_tag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Validate that the version in the tag label matches the version of the package."""
import argparse
import ast
Expand All @@ -17,8 +16,11 @@ def get_version_from_module(content: str) -> str:

try:
return next(
ast.literal_eval(statement.value) for statement in module.body if isinstance(statement, ast.Assign)
for target in statement.targets if isinstance(target, ast.Name) and target.id == '__version__'
ast.literal_eval(statement.value)
for statement in module.body
if isinstance(statement, ast.Assign)
for target in statement.targets
if isinstance(target, ast.Name) and target.id == '__version__'
)
except StopIteration as exception:
raise IOError('Unable to find the `__version__` attribute in the module.') from exception
Expand Down
88 changes: 36 additions & 52 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,40 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.5.0'
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: [--remove]
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace

- repo: https://github.com/ikamensh/flynt/
rev: '0.76'
hooks:
- id: flynt
- repo: https://github.com/ikamensh/flynt/
rev: '1.0.1'
hooks:
- id: flynt

- repo: https://github.com/pycqa/isort
rev: '5.12.0'
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.5'
hooks:
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.32.0
hooks:
- id: yapf
name: yapf
types: [python]
args: ['-i']
additional_dependencies: ['toml']

- repo: https://github.com/PyCQA/pylint
rev: v2.12.2
hooks:
- id: pylint
language: system

- repo: https://github.com/PyCQA/pydocstyle
rev: '6.1.1'
hooks:
- id: pydocstyle
additional_dependencies: ['toml']

- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
args: [--config-file=pyproject.toml]
language: python
types: [python]
require_serial: true
pass_filenames: true
files: >-
(?x)^(
src/.*py|
tests/.*py|
)$
- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
args: [--config-file=pyproject.toml]
language: python
types: [python]
require_serial: true
pass_filenames: true
files: >-
(?x)^(
src/.*py|
tests/.*py|
)$
68 changes: 24 additions & 44 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
keywords = ['aiida', 'workflows', 's3']
requires-python = '>=3.8'
dependencies = [
'aiida-core~=2.2',
'aiida-core~=2.2,<2.4',
'azure-storage-blob',
'boto3',
]
Expand All @@ -41,8 +41,6 @@ tracker = 'https://github.com/sphuber/aiida-s3/issues'
pre-commit = [
'mypy==0.981',
'pre-commit~=2.17',
'pylint~=2.12.2',
'pylint-aiida~=0.1.1',
'types-pyyaml',
]
tests = [
Expand Down Expand Up @@ -74,11 +72,28 @@ exclude = [
line-length = 120
fail-on-change = true

[tool.isort]
force_sort_within_sections = true
include_trailing_comma = true
line_length = 120
multi_line_output = 3
[tool.ruff]
line-length = 120
select = [
'E', # pydocstyle
'W', # pydocstyle
'F', # pyflakes
'I', # isort
'N', # pep8-naming
'D', # pydocstyle
'PLC', # pylint-convention
'PLE', # pylint-error
'PLR', # pylint-refactor
'PLW', # pylint-warning
'RUF', # ruff
]
ignore = [
'D203', # Incompatible with D211 `no-blank-line-before-class`
'D213', # Incompatible with D212 `multi-line-summary-second-line`
]

[tool.ruff.format]
quote-style = 'single'

[tool.mypy]
show_error_codes = true
Expand All @@ -88,14 +103,14 @@ warn_unused_ignores = true
warn_redundant_casts = true
no_warn_no_return = true
show_traceback = true
install-types = true

[[tool.mypy.overrides]]
module = 'aiida_s3.*'
check_untyped_defs = true

[[tool.mypy.overrides]]
module = [
'azure.*',
'boto3.*',
'botocore.*',
'moto.*',
Expand All @@ -105,45 +120,10 @@ module = [
]
ignore_missing_imports = true

[tool.pydocstyle]
ignore = [
'D104',
'D203',
'D213'
]

[tool.pylint.basic]
good-names = [
's3',
]

[tool.pylint.master]
load-plugins = ['pylint_aiida']

[tool.pylint.format]
max-line-length = 120

[tool.pylint.messages_control]
disable = [
'bad-continuation',
'duplicate-code',
'import-outside-toplevel',
'too-many-arguments',
]

[tool.pytest.ini_options]
filterwarnings = [
'ignore:Creating AiiDA configuration folder.*:UserWarning'
]
markers = [
'skip_if_azure_mocked: Skip if the Azure client is mocked, which is not supporte yet',
]

[tool.yapf]
align_closing_bracket_with_visual_indent = true
based_on_style = 'google'
coalesce_brackets = true
column_limit = 120
dedent_closing_brackets = true
indent_dictionary_value = false
split_arguments_when_comma_terminated = true
1 change: 0 additions & 1 deletion src/aiida_s3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
"""AiiDA plugin that provides a storage backend using an S3 object store as the file repository."""
__version__ = '0.2.0'
5 changes: 2 additions & 3 deletions src/aiida_s3/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
# pylint: disable=cyclic-import,wrong-import-position
"""Command line interface for ``aiida-s3``."""
from aiida.cmdline.groups.verdi import VerdiCommandGroup
import click
from aiida.cmdline.groups.verdi import VerdiCommandGroup


@click.group('aiida-s3', cls=VerdiCommandGroup)
def cmd_root():
"""Command line interface for ``aiida-s3``."""


from .cmd_profile import cmd_profile
from .cmd_profile import cmd_profile # noqa
13 changes: 6 additions & 7 deletions src/aiida_s3/cli/cmd_profile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""CLI commands to create profiles."""
from aiida.cmdline.groups import DynamicEntryPointCommandGroup

Expand All @@ -10,7 +9,7 @@ def cmd_profile():
"""Commands to create profiles."""


def create_profile(cls, non_interactive, **kwargs): # pylint: disable=unused-argument
def create_profile(cls, non_interactive, **kwargs):
"""Set up a new profile with an ``aiida-s3`` storage backend."""
import contextlib
import io
Expand All @@ -29,7 +28,7 @@ def create_profile(cls, non_interactive, **kwargs): # pylint: disable=unused-ar
'database_username': kwargs.pop('postgresql_username'),
'database_password': kwargs.pop('postgresql_password'),
'database_name': kwargs.pop('postgresql_database_name'),
}
},
},
'process_control': {
'backend': 'rabbitmq',
Expand All @@ -39,8 +38,8 @@ def create_profile(cls, non_interactive, **kwargs): # pylint: disable=unused-ar
'broker_password': 'guest',
'broker_host': '127.0.0.1',
'broker_port': 5672,
'broker_virtual_host': ''
}
'broker_virtual_host': '',
},
},
}

Expand All @@ -58,7 +57,7 @@ def create_profile(cls, non_interactive, **kwargs): # pylint: disable=unused-ar
try:
with contextlib.redirect_stdout(io.StringIO()):
profile.storage_cls.initialise(profile)
except Exception as exception: # pylint: disable=broad-except
except Exception as exception:
echo.echo_critical(
f'Storage backend initialisation failed, probably because connection details are incorrect:\n{exception}'
)
Expand All @@ -74,7 +73,7 @@ def create_profile(cls, non_interactive, **kwargs): # pylint: disable=unused-ar
cls=DynamicEntryPointCommandGroup,
command=create_profile,
entry_point_group='aiida.storage',
entry_point_name_filter=r's3\..*'
entry_point_name_filter=r's3\..*',
)
def cmd_profile_setup():
"""Set up a new profile with an ``aiida-s3`` storage backend."""
1 change: 1 addition & 0 deletions src/aiida_s3/repository/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Custom implementations of :class:`aiida.repository.backend.abstract.AbstractRepositoryBackend`."""
2 changes: 0 additions & 2 deletions src/aiida_s3/repository/aws_s3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Implementation of the :py:`aiida.repository.backend.abstract.AbstractRepositoryBackend` using AWS S3 as backend."""
from __future__ import annotations

Expand All @@ -24,7 +23,6 @@ def __init__(self, aws_access_key_id: str, aws_secret_access_key: str, region_na
:param region_name: The AWS region name to create the bucket in if it doesn't yet exist.
:param bucket_name: The name of the bucket to use.
"""
# pylint: disable=super-init-not-called
self._bucket_name = bucket_name
self._region_name = region_name
self._client = boto3.client(
Expand Down
15 changes: 6 additions & 9 deletions src/aiida_s3/repository/azure_blob.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Implementation of the :py:`aiida.repository.backend.abstract.AbstractRepositoryBackend` using Azure Blob Storage."""
from __future__ import annotations

Expand Down Expand Up @@ -122,7 +121,7 @@ def open(self, key: str) -> t.Iterator[t.IO[bytes]]: # type: ignore[override]
with tempfile.TemporaryFile(mode='w+b') as handle:
try:
self._container_client.download_blob(key).readinto(handle)
except Exception as exception: # pylint: disable=broad-except
except Exception as exception:
raise FileNotFoundError(f'object with key `{key}` does not exist.') from exception
handle.seek(0)
yield handle
Expand Down Expand Up @@ -160,16 +159,15 @@ def list_objects(self) -> t.Iterable[str]:
for name in self._container_client.list_blob_names():
yield name

def maintain( # type: ignore[override]
def maintain( # type: ignore[override] # noqa: PLR0913
self,
dry_run: bool = False,
live: bool = True,
pack_loose: bool = None,
do_repack: bool = None,
clean_storage: bool = None,
do_vacuum: bool = None,
pack_loose: bool | None = None,
do_repack: bool | None = None,
clean_storage: bool | None = None,
do_vacuum: bool | None = None,
) -> dict:
# pylint: disable=arguments-differ, unused-argument
"""Perform maintenance operations.
:param live: if True, will only perform operations that are safe to do while the repository is in use.
Expand All @@ -185,6 +183,5 @@ def get_info( # type: ignore[override]
self,
detailed=False,
) -> dict[str, int | str | dict[str, int] | dict[str, float]]:
# pylint: disable=arguments-differ, unused-argument
"""Return information on configuration and content of the repository."""
return {}
Loading

0 comments on commit 9e54d4d

Please sign in to comment.