From 54028cc7061a73b7f3604ef0c4dcc13e34609818 Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Mon, 10 Oct 2022 12:01:27 +0200 Subject: [PATCH] First round of review --- docs/source/design.rst | 4 ++-- src/aiida_pseudo/cli/family.py | 2 +- src/aiida_pseudo/cli/install.py | 2 +- src/aiida_pseudo/cli/params/types.py | 23 ++++++++++++----------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/docs/source/design.rst b/docs/source/design.rst index dacd21e..213a4b5 100644 --- a/docs/source/design.rst +++ b/docs/source/design.rst @@ -103,9 +103,9 @@ A pseudopotential family is only considered to be *established* when it has a co Only a pseudopotential family that is *established* will receive support for automated installs with its own class (e.g. :py:class:`~aiida_pseudo.groups.family.SsspFamily`/:py:class:`~aiida_pseudo.groups.family.PseudoDojoFamily`) and command line interface (CLI) commands (e.g. ``install sssp``/``install pseudo-dojo``). To make sure these families represent the official ones, they can only be installed with their supported CLI commands, and there are strict checks on the format of these files to make sure they correspond to the official ones. -Based on the same principle of preserving the integrity of these established pseudopotentials, the ``family cutoffs set`` command can not be used to set the recommended cutoffs of an established family. +Based on the same principle of preserving the integrity of these established pseudopotentials, the ``family cutoffs set`` command cannot be used to set the recommended cutoffs of an established family. -If users want to install the a set of *non-established* pseudopotentials and configure their recommended cutoffs, they have to install them from the archive using ``install family`` as a :py:class:`~aiida_pseudo.groups.family.CutoffsPseudoPotentialFamily` as described in the :ref:`corresponding how-to section `. +To install a set of *non-established* pseudopotentials and configure their recommended cutoffs, install them from the archive using ``install family`` as a :py:class:`~aiida_pseudo.groups.family.CutoffsPseudoPotentialFamily` as described in the :ref:`corresponding how-to section `. Recommended cutoffs =================== diff --git a/src/aiida_pseudo/cli/family.py b/src/aiida_pseudo/cli/family.py index bcda8e0..5438e73 100644 --- a/src/aiida_pseudo/cli/family.py +++ b/src/aiida_pseudo/cli/family.py @@ -57,7 +57,7 @@ def cmd_family_cutoffs(): @cmd_family_cutoffs.command('set') @arguments.PSEUDO_POTENTIAL_FAMILY( - type=types.PseudoPotentialFamilyParam(exclude=('pseudo.family.sssp', 'pseudo.family.pseudo_dojo')) + type=types.PseudoPotentialFamilyParam(blacklist=('pseudo.family.sssp', 'pseudo.family.pseudo_dojo')) ) @click.argument('cutoffs', type=click.File(mode='rb')) @options.STRINGENCY(required=True) diff --git a/src/aiida_pseudo/cli/install.py b/src/aiida_pseudo/cli/install.py index 3f52754..9d56b8a 100644 --- a/src/aiida_pseudo/cli/install.py +++ b/src/aiida_pseudo/cli/install.py @@ -28,7 +28,7 @@ def cmd_install(): @options_core.DESCRIPTION(help='Description for the family.') @options.ARCHIVE_FORMAT() @options.FAMILY_TYPE( - type=types.PseudoPotentialFamilyTypeParam(exclude=('pseudo.family.sssp', 'pseudo.family.pseudo_dojo')) + type=types.PseudoPotentialFamilyTypeParam(blacklist=('pseudo.family.sssp', 'pseudo.family.pseudo_dojo')) ) @options.PSEUDO_TYPE() @options.TRACEBACK() diff --git a/src/aiida_pseudo/cli/params/types.py b/src/aiida_pseudo/cli/params/types.py index 50d3875..1d9f45f 100644 --- a/src/aiida_pseudo/cli/params/types.py +++ b/src/aiida_pseudo/cli/params/types.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- # pylint: disable=no-self-use """Custom parameter types for command line interface commands.""" +from __future__ import annotations + import pathlib -import typing from aiida.cmdline.params.types import GroupParamType import click @@ -59,13 +60,13 @@ class PseudoPotentialFamilyParam(GroupParamType): name = 'pseudo_family' - def __init__(self, exclude: typing.Optional[typing.List[str]] = None, **kwargs): + def __init__(self, blacklist: list[str] | None = None, **kwargs): """Construct the parameter. - :param exclude: an optional list of values that should be considered invalid and will raise ``BadParameter``. + :param blacklist: an optional list of values that should be considered invalid and will raise ``BadParameter``. """ super().__init__(**kwargs) - self.exclude = exclude + self.blacklist = blacklist def convert(self, value, param, ctx): """Convert the entry point name to the corresponding class. @@ -76,7 +77,7 @@ def convert(self, value, param, ctx): """ family = super().convert(value, param, ctx) - if self.exclude and family.type_string in self.exclude: + if self.blacklist and family.type_string in self.blacklist: self.fail(f'The value `{family}` is not allowed for this parameter.', param, ctx) return family @@ -86,13 +87,13 @@ class PseudoPotentialFamilyTypeParam(click.ParamType): name = 'pseudo_family_type' - def __init__(self, exclude: typing.Optional[typing.List[str]] = None, **kwargs): + def __init__(self, blacklist: list[str] | None = None, **kwargs): """Construct the parameter. - :param exclude: an optional list of values that should be considered invalid and will raise ``BadParameter``. + :param blacklist: an optional list of values that should be considered invalid and will raise ``BadParameter``. """ super().__init__(**kwargs) - self.exclude = exclude + self.blacklist = blacklist def convert(self, value, _, __): """Convert the entry point name to the corresponding class. @@ -112,7 +113,7 @@ def convert(self, value, _, __): except exceptions.EntryPointError as exception: raise click.BadParameter(f'`{value}` is not an existing group plugin.') from exception - if self.exclude and value in self.exclude: + if self.blacklist and value in self.blacklist: raise click.BadParameter(f'`{value}` is not an accepted value for this option.') if not issubclass(family_type, PseudoPotentialFamily): @@ -137,7 +138,7 @@ class PathOrUrl(click.Path): name = 'PathOrUrl' - def convert(self, value, param, ctx) -> typing.Union[pathlib.Path, bytes]: + def convert(self, value, param, ctx) -> pathlib.Path | bytes: """Convert the string value to the desired value. If the ``value`` corresponds to a valid path on the local filesystem, return it as a ``pathlib.Path`` instance. @@ -161,7 +162,7 @@ class UnitParamType(click.ParamType): name = 'unit' - def __init__(self, quantity: typing.Optional[typing.List[str]] = None, **kwargs): + def __init__(self, quantity: list[str] | None = None, **kwargs): """Construct the parameter. :param quantity: The corresponding quantity of the unit.