Skip to content

Commit

Permalink
Update the pre-commit configuration (#113)
Browse files Browse the repository at this point in the history
The pre-commit is updated and improved in various ways:

 * Configuration is moved from tool specific configuration files to the
   standard `pyproject.toml`. This allows to remove `.style.yapf` and
   `pytest.ini`.
 * Update `yapf` requirement to `v0.31.0` which is necessary for the
   `pyproject.toml` support.
 * Add the `isort` hook to organize imports.
 * Add the `flynt` hook to automatically fix f-strings.
  • Loading branch information
sphuber authored Dec 9, 2021
1 parent 252c68f commit 9f54cd3
Show file tree
Hide file tree
Showing 44 changed files with 136 additions and 84 deletions.
28 changes: 18 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,44 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/ikamensh/flynt/
rev: '0.55'
rev: '0.66'
hooks:
- id: flynt
args: [
'--line-length=120',
'--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
8 changes: 0 additions & 8 deletions .style.yapf

This file was deleted.

4 changes: 2 additions & 2 deletions aiida_pseudo/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions aiida_pseudo/cli/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions aiida_pseudo/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion aiida_pseudo/cli/list.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions aiida_pseudo/cli/params/arguments.py
Original file line number Diff line number Diff line change
@@ -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',)
Expand Down
2 changes: 1 addition & 1 deletion aiida_pseudo/cli/params/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = (
Expand Down
6 changes: 4 additions & 2 deletions aiida_pseudo/cli/params/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions aiida_pseudo/cli/root.py
Original file line number Diff line number Diff line change
@@ -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']})
Expand Down
2 changes: 2 additions & 0 deletions aiida_pseudo/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
"""Module with common resources."""
2 changes: 2 additions & 0 deletions aiida_pseudo/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
"""Module with implementations of :class:`aiida.orm.nodes.data.Data` plugins."""
3 changes: 1 addition & 2 deletions aiida_pseudo/data/pseudo/pseudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions aiida_pseudo/groups/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
"""Module with implementations of :class:`aiida.orm.groups.Group` plugins."""
2 changes: 1 addition & 1 deletion aiida_pseudo/groups/family/pseudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions aiida_pseudo/groups/family/pseudo_dojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"""Subclass of `PseudoPotentialFamily` designed to represent a PseudoDojo configuration."""
import json
import os
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

Expand Down Expand Up @@ -285,7 +285,7 @@ def parse_djrepos_from_folder(cls, dirpath, pseudo_type):
continue

try:
with open(filepath, 'r') as handle:
with open(filepath, 'r', encoding='utf-8') as handle:
djrepo = json.load(handle)
except ParsingError as exception:
raise ParsingError(f'failed to parse `{filepath}`: {exception}') from exception
Expand Down
1 change: 1 addition & 0 deletions aiida_pseudo/groups/family/sssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions aiida_pseudo/groups/mixins/cutoffs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html

from reentry import manager

manager.scan()

# -- Path setup --------------------------------------------------------------
Expand All @@ -16,6 +17,7 @@
#
import os
import sys

sys.path.insert(0, os.path.abspath('../../'))

import aiida_pseudo
Expand Down
38 changes: 36 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
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'

with open(filename_setup_json, 'r') as handle:
with open(filename_setup_json, 'r', encoding='utf-8') as handle:
setup_json = json.load(handle)

with open(filename_description, 'r') as handle:
with open(filename_description, 'r', encoding='utf-8') as handle:
description = handle.read()

setup(
Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
"""Tests for the :mod:`aiida_pseudo` module."""
2 changes: 2 additions & 0 deletions tests/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
"""Tests for the :mod:`aiida_pseudo.cli` module."""
2 changes: 2 additions & 0 deletions tests/cli/params/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
"""Tests for the :mod:`aiida_pseudo.cli.params` module."""
Loading

0 comments on commit 9f54cd3

Please sign in to comment.