diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e6fa4ac..fe734bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/ikamensh/flynt/ - rev: '0.55' + rev: '0.66' hooks: - id: flynt args: [ @@ -17,28 +17,36 @@ repos: '--fail-on-change', ] +- repo: https://github.com/pycqa/isort + rev: 5.9.3 + hooks: + - id: isort + - repo: https://github.com/pre-commit/mirrors-yapf - rev: v0.30.0 + rev: v0.31.0 hooks: - id: yapf name: yapf types: [python] args: ['-i'] + additional_dependencies: ['toml'] exclude: &exclude_files > (?x)^( docs/.*| )$ -- repo: https://github.com/PyCQA/pylint - rev: pylint-2.6.0 - hooks: - - id: pylint - language: system - exclude: *exclude_files - - repo: https://github.com/PyCQA/pydocstyle rev: 5.0.2 hooks: - id: pydocstyle - args: ['--ignore=D104,D203,D213'] + additional_dependencies: ['toml'] + exclude: *exclude_files + +- repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + types: [python] + language: system exclude: *exclude_files diff --git a/.style.yapf b/.style.yapf deleted file mode 100644 index 0fcf35c..0000000 --- a/.style.yapf +++ /dev/null @@ -1,8 +0,0 @@ -[style] -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 diff --git a/aiida_pseudo/cli/__init__.py b/aiida_pseudo/cli/__init__.py index 0c70fb1..ea2c211 100644 --- a/aiida_pseudo/cli/__init__.py +++ b/aiida_pseudo/cli/__init__.py @@ -6,7 +6,7 @@ # Activate the completion of parameter types provided by the click_completion package click_completion.init() -from .root import cmd_root from .family import cmd_family -from .install import cmd_install, cmd_install_family, cmd_install_sssp, cmd_install_pseudo_dojo +from .install import cmd_install, cmd_install_family, cmd_install_pseudo_dojo, cmd_install_sssp from .list import cmd_list +from .root import cmd_root diff --git a/aiida_pseudo/cli/family.py b/aiida_pseudo/cli/family.py index 46c3d39..15ae363 100644 --- a/aiida_pseudo/cli/family.py +++ b/aiida_pseudo/cli/family.py @@ -2,10 +2,9 @@ """Commands to inspect or modify the contents of pseudo potential families.""" import json -import click - from aiida.cmdline.params import options as options_core from aiida.cmdline.utils import decorators, echo +import click from ..groups.mixins import RecommendedCutoffMixin from .params import arguments, options diff --git a/aiida_pseudo/cli/install.py b/aiida_pseudo/cli/install.py index 02348b2..b49f1ef 100644 --- a/aiida_pseudo/cli/install.py +++ b/aiida_pseudo/cli/install.py @@ -4,15 +4,15 @@ import pathlib import shutil import tempfile -import yaml +from aiida.cmdline.params import options as options_core +from aiida.cmdline.utils import decorators, echo import click import requests - -from aiida.cmdline.utils import decorators, echo -from aiida.cmdline.params import options as options_core +import yaml from aiida_pseudo.groups.family import PseudoDojoConfiguration, SsspConfiguration + from .params import options, types from .root import cmd_root @@ -103,6 +103,7 @@ def download_sssp( :return: Latest patch version of the requested minor version """ from aiida_pseudo.groups.family import SsspFamily + from .utils import attempt url_template = 'https://archive.materialscloud.org/record/file?filename={filename}&parent_id=19' @@ -156,6 +157,7 @@ def download_pseudo_dojo( :param traceback: boolean, if true, print the traceback when an exception occurs. """ from aiida_pseudo.groups.family import PseudoDojoFamily + from .utils import attempt label = PseudoDojoFamily.format_configuration_label(configuration) @@ -196,6 +198,7 @@ def cmd_install_sssp(version, functional, protocol, download_only, traceback): from aiida_pseudo import __version__ from aiida_pseudo.groups.family import SsspFamily + from .utils import attempt, create_family_from_archive configuration = SsspConfiguration(version, functional, protocol) @@ -274,8 +277,9 @@ def cmd_install_pseudo_dojo( # pylint: disable=too-many-locals,too-many-arguments,too-many-branches,too-many-statements from aiida.common.files import md5_file from aiida.orm import Group, QueryBuilder + from aiida_pseudo import __version__ - from aiida_pseudo.data.pseudo import JthXmlData, Psp8Data, PsmlData, UpfData + from aiida_pseudo.data.pseudo import JthXmlData, PsmlData, Psp8Data, UpfData from aiida_pseudo.groups.family import PseudoDojoFamily from .utils import attempt, create_family_from_archive diff --git a/aiida_pseudo/cli/list.py b/aiida_pseudo/cli/list.py index fa7fc8d..df38481 100644 --- a/aiida_pseudo/cli/list.py +++ b/aiida_pseudo/cli/list.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- """Commands to list instances of `PseudoPotentialFamily`.""" -import click from aiida.cmdline.params import options as options_core from aiida.cmdline.utils import decorators, echo +import click from .params import options from .root import cmd_root @@ -17,6 +17,7 @@ def get_families_builder(): :return: `QueryBuilder` instance """ from aiida.orm import QueryBuilder + from aiida_pseudo.groups.family import PseudoPotentialFamily builder = QueryBuilder().append(PseudoPotentialFamily) diff --git a/aiida_pseudo/cli/params/arguments.py b/aiida_pseudo/cli/params/arguments.py index 2b348b9..7aa2c3e 100644 --- a/aiida_pseudo/cli/params/arguments.py +++ b/aiida_pseudo/cli/params/arguments.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """Reusable arguments for CLI commands.""" from aiida.cmdline.params.arguments import OverridableArgument + from .types import PseudoPotentialFamilyParam __all__ = ('PSEUDO_POTENTIAL_FAMILY',) diff --git a/aiida_pseudo/cli/params/options.py b/aiida_pseudo/cli/params/options.py index a158ab3..f321a2f 100644 --- a/aiida_pseudo/cli/params/options.py +++ b/aiida_pseudo/cli/params/options.py @@ -2,9 +2,9 @@ """Reusable options for CLI commands.""" import shutil +from aiida.cmdline.params.options import OverridableOption import click -from aiida.cmdline.params.options import OverridableOption from .types import PseudoPotentialFamilyTypeParam, PseudoPotentialTypeParam, UnitParamType __all__ = ( diff --git a/aiida_pseudo/cli/params/types.py b/aiida_pseudo/cli/params/types.py index 59dfae4..d1d64e4 100644 --- a/aiida_pseudo/cli/params/types.py +++ b/aiida_pseudo/cli/params/types.py @@ -4,12 +4,12 @@ import pathlib import typing +from aiida.cmdline.params.types import GroupParamType import click import requests -from aiida.cmdline.params.types import GroupParamType -from ..utils import attempt from ...common.units import U +from ..utils import attempt __all__ = ('PseudoPotentialFamilyTypeParam', 'PseudoPotentialFamilyParam', 'PseudoPotentialTypeParam') @@ -28,6 +28,7 @@ def convert(self, value, _, __): """ from aiida.common import exceptions from aiida.plugins import DataFactory + from aiida_pseudo.data.pseudo import PseudoPotentialData try: @@ -80,6 +81,7 @@ def convert(self, value, _, __): """ from aiida.common import exceptions from aiida.plugins import GroupFactory + from aiida_pseudo.groups.family import PseudoPotentialFamily try: diff --git a/aiida_pseudo/cli/root.py b/aiida_pseudo/cli/root.py index 52f0ad8..b0c7e2b 100644 --- a/aiida_pseudo/cli/root.py +++ b/aiida_pseudo/cli/root.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- """Command line interface `aiida-pseudo`.""" -import click - from aiida.cmdline.params import options, types +import click @click.group('aiida-pseudo', context_settings={'help_option_names': ['-h', '--help']}) diff --git a/aiida_pseudo/data/pseudo/pseudo.py b/aiida_pseudo/data/pseudo/pseudo.py index abe4d0f..dd6ee5e 100644 --- a/aiida_pseudo/data/pseudo/pseudo.py +++ b/aiida_pseudo/data/pseudo/pseudo.py @@ -4,8 +4,7 @@ import pathlib import typing -from aiida import orm -from aiida import plugins +from aiida import orm, plugins from aiida.common.constants import elements from aiida.common.exceptions import StoringNotAllowed from aiida.common.files import md5_from_filelike diff --git a/aiida_pseudo/groups/family/pseudo.py b/aiida_pseudo/groups/family/pseudo.py index b8de2bc..b5a4c3b 100644 --- a/aiida_pseudo/groups/family/pseudo.py +++ b/aiida_pseudo/groups/family/pseudo.py @@ -2,7 +2,7 @@ """Subclass of ``Group`` that serves as a base class for representing pseudo potential families.""" import os import re -from typing import Union, List, Tuple, Mapping +from typing import List, Mapping, Tuple, Union from aiida.common import exceptions from aiida.common.lang import classproperty, type_check diff --git a/aiida_pseudo/groups/family/pseudo_dojo.py b/aiida_pseudo/groups/family/pseudo_dojo.py index 916f72b..fdad1f1 100644 --- a/aiida_pseudo/groups/family/pseudo_dojo.py +++ b/aiida_pseudo/groups/family/pseudo_dojo.py @@ -3,14 +3,15 @@ import json import os import re +from pathlib import Path +import re from typing import NamedTuple, Sequence import warnings -from pathlib import Path - from aiida.common.exceptions import ParsingError -from aiida_pseudo.data.pseudo import UpfData, PsmlData, Psp8Data, JthXmlData +from aiida_pseudo.data.pseudo import JthXmlData, PsmlData, Psp8Data, UpfData + from ..mixins import RecommendedCutoffMixin from .pseudo import PseudoPotentialFamily diff --git a/aiida_pseudo/groups/family/sssp.py b/aiida_pseudo/groups/family/sssp.py index 152b60f..c2efbcc 100644 --- a/aiida_pseudo/groups/family/sssp.py +++ b/aiida_pseudo/groups/family/sssp.py @@ -3,6 +3,7 @@ from typing import NamedTuple, Optional, Sequence from aiida_pseudo.data.pseudo import UpfData + from ..mixins import RecommendedCutoffMixin from .pseudo import PseudoPotentialFamily diff --git a/aiida_pseudo/groups/mixins/cutoffs.py b/aiida_pseudo/groups/mixins/cutoffs.py index b13ab20..d5c94dc 100644 --- a/aiida_pseudo/groups/mixins/cutoffs.py +++ b/aiida_pseudo/groups/mixins/cutoffs.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- """Mixin that adds support of recommended cutoffs to a ``Group`` subclass, using its extras.""" -import warnings - from typing import Optional +import warnings from aiida.common.lang import type_check from aiida.plugins import DataFactory diff --git a/docs/source/conf.py b/docs/source/conf.py index 1c93ae5..f75be40 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -6,6 +6,7 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html from reentry import manager + manager.scan() # -- Path setup -------------------------------------------------------------- @@ -16,6 +17,7 @@ # import os import sys + sys.path.insert(0, os.path.abspath('../../')) import aiida_pseudo diff --git a/pyproject.toml b/pyproject.toml index f60c80d..5a05edb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,22 @@ [build-system] -requires = ['setuptools>=40.8.0', 'wheel', 'reentry~=1.3', 'fastentrypoints~=0.12'] -build-backend = 'setuptools.build_meta:__legacy__' +requires = ['setuptools>=40.8.0', 'wheel', 'fastentrypoints~=0.12'] +build-backend = 'setuptools.build_meta' + +[tool.isort] +force_sort_within_sections = true +include_trailing_comma = true +line_length = 120 +multi_line_output = 3 + +[tool.pydocstyle] +ignore = [ + 'D104', + 'D203', + 'D213', +] + +[tool.pylint.master] +load-plugins = ['pylint_aiida'] [tool.pylint.format] max-line-length = 120 @@ -12,3 +28,21 @@ disable = [ 'import-outside-toplevel', 'too-many-arguments', ] + +[tool.pytest.ini_options] +filterwarnings = [ + 'ignore::DeprecationWarning:distutils:', + 'ignore::DeprecationWarning:frozendict:', + 'ignore::DeprecationWarning:sqlalchemy_utils:', + 'ignore::DeprecationWarning:reentry:', + 'ignore::DeprecationWarning:pkg_resources:', +] + +[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 diff --git a/setup.json b/setup.json index 4f1c015..ca7f4ae 100644 --- a/setup.json +++ b/setup.json @@ -46,7 +46,8 @@ "extras_require": { "pre-commit": [ "pre-commit~=2.2", - "pylint~=2.6.0" + "pylint~=2.6", + "pylint-aiida~=0.1" ], "tests": [ "pgtest~=1.3", diff --git a/setup.py b/setup.py index 0b97d2d..85e3abc 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,8 @@ def setup_package(): """Install the `aiida-pseudo` package.""" import json - from setuptools import setup, find_packages + + from setuptools import find_packages, setup filename_setup_json = 'setup.json' filename_description = 'README.md' diff --git a/tests/cli/test_family.py b/tests/cli/test_family.py index 67508ea..230e3bb 100644 --- a/tests/cli/test_family.py +++ b/tests/cli/test_family.py @@ -3,13 +3,12 @@ """Tests for the command `aiida-pseudo family`.""" import json +from aiida.orm import Group from numpy.testing import assert_almost_equal import pytest -from aiida.orm import Group - from aiida_pseudo.cli.family import cmd_family_cutoffs_set, cmd_family_show -from aiida_pseudo.groups.family import PseudoPotentialFamily, CutoffsPseudoPotentialFamily +from aiida_pseudo.groups.family import CutoffsPseudoPotentialFamily, PseudoPotentialFamily @pytest.mark.usefixtures('clear_db') diff --git a/tests/cli/test_install.py b/tests/cli/test_install.py index bbd0425..c2e69a1 100644 --- a/tests/cli/test_install.py +++ b/tests/cli/test_install.py @@ -4,16 +4,14 @@ import json import pathlib -import pytest - from aiida.orm import QueryBuilder +import pytest -from aiida_pseudo.cli import install -from aiida_pseudo.cli import cmd_install_family, cmd_install_sssp, cmd_install_pseudo_dojo +from aiida_pseudo.cli import cmd_install_family, cmd_install_pseudo_dojo, cmd_install_sssp, install from aiida_pseudo.data.pseudo.upf import UpfData from aiida_pseudo.groups.family import PseudoPotentialFamily -from aiida_pseudo.groups.family.pseudo_dojo import PseudoDojoFamily, PseudoDojoConfiguration -from aiida_pseudo.groups.family.sssp import SsspFamily, SsspConfiguration +from aiida_pseudo.groups.family.pseudo_dojo import PseudoDojoConfiguration, PseudoDojoFamily +from aiida_pseudo.groups.family.sssp import SsspConfiguration, SsspFamily @pytest.fixture diff --git a/tests/conftest.py b/tests/conftest.py index 509d6c3..9cbb1b6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,13 +6,12 @@ import re import shutil +from aiida.plugins import DataFactory import click import pytest -from aiida.plugins import DataFactory - from aiida_pseudo.data.pseudo import PseudoPotentialData -from aiida_pseudo.groups.family import PseudoPotentialFamily, CutoffsPseudoPotentialFamily +from aiida_pseudo.groups.family import CutoffsPseudoPotentialFamily, PseudoPotentialFamily pytest_plugins = ['aiida.manage.tests.pytest_fixtures'] # pylint: disable=invalid-name @@ -51,6 +50,7 @@ def _run_cli_command(command, options=None, raises=None): :param raises: optionally an exception class that is expected to be raised """ import traceback + from click.testing import CliRunner runner = CliRunner() diff --git a/tests/data/pseudo/test_common.py b/tests/data/pseudo/test_common.py index 54288f1..1478f61 100644 --- a/tests/data/pseudo/test_common.py +++ b/tests/data/pseudo/test_common.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- # pylint: disable=redefined-outer-name """Tests that are common to all data plugins in the :py:mod:`~aiida_pseudo.data.pseudo` module.""" -import pytest - from aiida import plugins +import pytest def get_entry_point_names(): diff --git a/tests/data/pseudo/test_jthxml.py b/tests/data/pseudo/test_jthxml.py index 35333a4..afc480f 100644 --- a/tests/data/pseudo/test_jthxml.py +++ b/tests/data/pseudo/test_jthxml.py @@ -5,9 +5,9 @@ import os import pathlib +from aiida.common.exceptions import ModificationNotAllowed import pytest -from aiida.common.exceptions import ModificationNotAllowed from aiida_pseudo.data.pseudo import JthXmlData diff --git a/tests/data/pseudo/test_pseudo.py b/tests/data/pseudo/test_pseudo.py index b9411c7..2c9dea7 100644 --- a/tests/data/pseudo/test_pseudo.py +++ b/tests/data/pseudo/test_pseudo.py @@ -4,12 +4,11 @@ import io import pathlib -import pytest - -from aiida.common.files import md5_from_filelike from aiida.common.exceptions import ModificationNotAllowed, StoringNotAllowed +from aiida.common.files import md5_from_filelike from aiida.common.links import LinkType from aiida.orm import CalcJobNode +import pytest from aiida_pseudo.data.pseudo import PseudoPotentialData, UpfData diff --git a/tests/data/pseudo/test_psf.py b/tests/data/pseudo/test_psf.py index 5b52634..f7ecd59 100644 --- a/tests/data/pseudo/test_psf.py +++ b/tests/data/pseudo/test_psf.py @@ -5,9 +5,9 @@ import os import pathlib +from aiida.common.exceptions import ModificationNotAllowed import pytest -from aiida.common.exceptions import ModificationNotAllowed from aiida_pseudo.data.pseudo import PsfData from aiida_pseudo.data.pseudo.psf import parse_element diff --git a/tests/data/pseudo/test_psml.py b/tests/data/pseudo/test_psml.py index 7039852..cdb5b26 100644 --- a/tests/data/pseudo/test_psml.py +++ b/tests/data/pseudo/test_psml.py @@ -5,9 +5,9 @@ import os import pathlib +from aiida.common.exceptions import ModificationNotAllowed import pytest -from aiida.common.exceptions import ModificationNotAllowed from aiida_pseudo.data.pseudo import PsmlData diff --git a/tests/data/pseudo/test_psp8.py b/tests/data/pseudo/test_psp8.py index e9b166a..d45c1e2 100644 --- a/tests/data/pseudo/test_psp8.py +++ b/tests/data/pseudo/test_psp8.py @@ -5,9 +5,9 @@ import os import pathlib +from aiida.common.exceptions import ModificationNotAllowed import pytest -from aiida.common.exceptions import ModificationNotAllowed from aiida_pseudo.data.pseudo import Psp8Data diff --git a/tests/data/pseudo/test_upf.py b/tests/data/pseudo/test_upf.py index 0e19b7c..dc1aebd 100644 --- a/tests/data/pseudo/test_upf.py +++ b/tests/data/pseudo/test_upf.py @@ -5,9 +5,9 @@ import os import pathlib +from aiida.common.exceptions import ModificationNotAllowed import pytest -from aiida.common.exceptions import ModificationNotAllowed from aiida_pseudo.data.pseudo import UpfData from aiida_pseudo.data.pseudo.upf import parse_z_valence diff --git a/tests/data/pseudo/test_vps.py b/tests/data/pseudo/test_vps.py index f47ccd6..7efb692 100644 --- a/tests/data/pseudo/test_vps.py +++ b/tests/data/pseudo/test_vps.py @@ -5,11 +5,11 @@ import os import pathlib +from aiida.common.exceptions import ModificationNotAllowed import pytest -from aiida.common.exceptions import ModificationNotAllowed from aiida_pseudo.data.pseudo import VpsData -from aiida_pseudo.data.pseudo.vps import parse_z_valence, parse_xc_type +from aiida_pseudo.data.pseudo.vps import parse_xc_type, parse_z_valence @pytest.fixture diff --git a/tests/groups/family/test_pseudo.py b/tests/groups/family/test_pseudo.py index a98c0f7..d5923d6 100644 --- a/tests/groups/family/test_pseudo.py +++ b/tests/groups/family/test_pseudo.py @@ -4,10 +4,9 @@ import distutils.dir_util import os -import pytest - from aiida.common import exceptions from aiida.orm import QueryBuilder +import pytest from aiida_pseudo.data.pseudo import PseudoPotentialData from aiida_pseudo.groups.family.pseudo import PseudoPotentialFamily diff --git a/tests/groups/family/test_pseudo_dojo.py b/tests/groups/family/test_pseudo_dojo.py index d2e52be..ae21f03 100644 --- a/tests/groups/family/test_pseudo_dojo.py +++ b/tests/groups/family/test_pseudo_dojo.py @@ -3,7 +3,7 @@ """Tests for the `PseudoDojoFamily` class.""" import pytest -from aiida_pseudo.data.pseudo import UpfData, Psp8Data, PsmlData, JthXmlData +from aiida_pseudo.data.pseudo import JthXmlData, PsmlData, Psp8Data, UpfData from aiida_pseudo.groups.family import PseudoDojoConfiguration, PseudoDojoFamily diff --git a/tests/pytest.ini b/tests/pytest.ini deleted file mode 100644 index c893b07..0000000 --- a/tests/pytest.ini +++ /dev/null @@ -1,7 +0,0 @@ -[pytest] -filterwarnings = - ignore::DeprecationWarning:distutils: - ignore::DeprecationWarning:frozendict: - ignore::DeprecationWarning:sqlalchemy_utils: - ignore::DeprecationWarning:reentry: - ignore::DeprecationWarning:pkg_resources: