From 92cbb5745353e16dea1d0882fbea139c8dc365ba Mon Sep 17 00:00:00 2001 From: Sebastian Weigand Date: Fri, 22 Oct 2021 19:43:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=E2=99=BB=EF=B8=8F=20Remove=20param?= =?UTF-8?q?eter.py=20from=20linter=20exceptions=20(#862)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ๐Ÿ”ง๐Ÿ‘Œ Move up yesqa hook, to remove noqa's before linting * ๐Ÿ”งโ™ป๏ธ Moved pydocstyle config to tox.ini * ๐Ÿ”ง โ™ป๏ธ Moved up flake8 hook directly after yesqa hook * ๐Ÿ”งโฌ†๏ธ Updated pre-commit config * ๐Ÿ”งโ™ป๏ธ Run Doc linting tools via flake8 This allows a uniform usage of 'noqa's, which is also compatible with yesqa * ๐Ÿ”ง๐Ÿฉน Remove parameter.py from linter exceptions * ๐Ÿ”ง Fixed darglint version to 1.8.0 due to bug in 1.8.1 Ref: https://github.com/terrencepreilly/darglint/issues/180 --- .pre-commit-config.yaml | 70 ++++++------- glotaran/parameter/parameter.py | 130 ++++++++++++------------ glotaran/parameter/parameter_group.py | 28 ++--- glotaran/parameter/parameter_history.py | 2 +- setup.cfg | 3 - tox.ini | 6 ++ 6 files changed, 118 insertions(+), 121 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 12c35fa8a..7e82fbc4c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--remove] - repo: https://github.com/asottile/pyupgrade - rev: v2.19.4 + rev: v2.29.0 hooks: - id: pyupgrade types: [file] @@ -32,7 +32,7 @@ repos: types_or: [python, pyi] - repo: https://github.com/psf/black - rev: 21.6b0 + rev: 21.9b0 hooks: - id: black types: [file] @@ -40,7 +40,7 @@ repos: language_version: python3 - repo: https://github.com/PyCQA/isort - rev: 5.9.1 + rev: 5.9.3 hooks: - id: isort types: [file] @@ -48,19 +48,19 @@ repos: minimum_pre_commit_version: 2.9.0 - repo: https://github.com/asottile/setup-cfg-fmt - rev: v1.17.0 + rev: v1.18.0 hooks: - id: setup-cfg-fmt # Notebook tools - repo: https://github.com/kynan/nbstripout - rev: 0.4.0 + rev: 0.5.0 hooks: - id: nbstripout args: [--strip-empty-cells] - repo: https://github.com/nbQA-dev/nbQA - rev: 0.13.1 + rev: 1.1.1 hooks: - id: nbqa-black additional_dependencies: [black==21.6b0] @@ -75,26 +75,38 @@ repos: args: [--nbqa-mutate] # Linters + - repo: https://github.com/asottile/yesqa + rev: v1.2.3 + hooks: + - id: yesqa + types: [file] + types_or: [python, pyi] + additional_dependencies: [flake8-docstrings, flake8-print] - - repo: https://github.com/PyCQA/pydocstyle - rev: 6.1.1 + - repo: https://github.com/PyCQA/flake8 + rev: 4.0.1 hooks: - - id: pydocstyle - files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project)" - exclude: "docs|tests?/" - # this is needed due to the following issue: - # https://github.com/PyCQA/pydocstyle/issues/368 - args: [--ignore-decorators=wrap_func_as_method] + - id: flake8 + name: "flake8 lint code" + types: [file] + types_or: [python, pyi] + additional_dependencies: + [flake8-pyi, flake8-comprehensions, flake8-print] - - repo: https://github.com/terrencepreilly/darglint - rev: v1.8.0 + - repo: https://github.com/PyCQA/flake8 + rev: 4.0.1 hooks: - - id: darglint + - id: flake8 + alias: flake8-docs + args: + - "--select=D,DAR" + name: "flake8 lint docstrings" files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project)" exclude: "docs|tests?/" + additional_dependencies: [flake8-docstrings, darglint==1.8.0] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.910 + rev: v0.910-1 hooks: - id: mypy files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project)" @@ -102,30 +114,12 @@ repos: additional_dependencies: [types-all] - repo: https://github.com/econchick/interrogate - rev: 1.4.0 + rev: 1.5.0 hooks: - id: interrogate args: [-vv, --config=pyproject.toml, glotaran] pass_filenames: false - - repo: https://github.com/asottile/yesqa - rev: v1.2.3 - hooks: - - id: yesqa - types: [file] - types_or: [python, pyi] - additional_dependencies: [flake8-docstrings, flake8-print] - exclude: "parameter.py" - - - repo: https://github.com/PyCQA/flake8 - rev: 3.9.2 - hooks: - - id: flake8 - types: [file] - types_or: [python, pyi] - additional_dependencies: - [flake8-pyi, flake8-comprehensions, flake8-print] - - repo: https://github.com/myint/rstcheck rev: "3f92957478422df87bd730abde66f089cc1ee19b" hooks: @@ -137,7 +131,7 @@ repos: hooks: - id: rst-backticks - id: python-check-blanket-noqa - exclude: "parameter.py|docs|tests?" + exclude: "docs|tests?" - id: python-check-blanket-type-ignore exclude: "docs|tests?" - id: python-use-type-annotations diff --git a/glotaran/parameter/parameter.py b/glotaran/parameter/parameter.py index fac046a19..b42d30027 100644 --- a/glotaran/parameter/parameter.py +++ b/glotaran/parameter/parameter.py @@ -334,7 +334,6 @@ def transformed_expression(self) -> str | None: ------- str | None The transformed expression. - """ if self.expression is not None and self._transformed_expression is None: self._transformed_expression = PARAMETER_EXPRESION_REGEX.sub( @@ -343,15 +342,14 @@ def transformed_expression(self) -> str | None: return self._transformed_expression @property - def standard_error(self) -> float: # noqa D401 + def standard_error(self) -> float: """Standard error of the optimized parameter. Returns ------- float The standard error of the parameter. - """ - + """ # noqa: D401 return self._stderr @standard_error.setter @@ -411,7 +409,7 @@ def set_value_from_optimization(self, value: float): """ self.value = np.exp(value) if self.non_negative else value - def __getstate__(self): # noqa D400 + def __getstate__(self): """Get state for pickle.""" return ( self.label, @@ -425,7 +423,7 @@ def __getstate__(self): # noqa D400 self.vary, ) - def __setstate__(self, state): # noqa D400 + def __setstate__(self, state): """Set state from pickle.""" ( self.label, @@ -439,18 +437,18 @@ def __setstate__(self, state): # noqa D400 self.vary, ) = state - def __repr__(self): # noqa D400 + def __repr__(self): """Representation used by repl and tracebacks.""" return ( f"{type(self).__name__}(label={self.label!r}, value={self.value!r}," f" expression={self.expression!r}, vary={self.vary!r})" ) - def __array__(self): # noqa D400 - """array""" + def __array__(self): + """array""" # noqa: D400, D403 return np.array(float(self._value), dtype=float) - def __str__(self) -> str: # noqa D400 + def __str__(self) -> str: """Representation used by print and str.""" return ( f"__{self.label}__: _Value_: {self.value}, _StdErr_: {self.standard_error}, _Min_:" @@ -458,116 +456,116 @@ def __str__(self) -> str: # noqa D400 f" _Non-Negative_: {self.non_negative}, _Expr_: {self.expression}" ) - def __abs__(self): # noqa D400 - """abs""" + def __abs__(self): + """abs""" # noqa: D400, D403 return abs(self._value) - def __neg__(self): # noqa D400 - """neg""" + def __neg__(self): + """neg""" # noqa: D400, D403 return -self._value - def __pos__(self): # noqa D400 - """positive""" + def __pos__(self): + """positive""" # noqa: D400, D403 return +self._value - def __int__(self): # noqa D400 - """int""" + def __int__(self): + """int""" # noqa: D400, D403 return int(self._value) - def __float__(self): # noqa D400 - """float""" + def __float__(self): + """float""" # noqa: D400, D403 return float(self._value) - def __trunc__(self): # noqa D400 - """trunc""" + def __trunc__(self): + """trunc""" # noqa: D400, D403 return self._value.__trunc__() - def __add__(self, other): # noqa D400 - """+""" + def __add__(self, other): + """+""" # noqa: D400 return self._value + other - def __sub__(self, other): # noqa D400 - """-""" + def __sub__(self, other): + """-""" # noqa: D400 return self._value - other - def __truediv__(self, other): # noqa D400 - """/""" + def __truediv__(self, other): + """/""" # noqa: D400 return self._value / other - def __floordiv__(self, other): # noqa D400 - """//""" + def __floordiv__(self, other): + """//""" # noqa: D400 return self._value // other - def __divmod__(self, other): # noqa D400 - """divmod""" + def __divmod__(self, other): + """divmod""" # noqa: D400, D403 return divmod(self._value, other) - def __mod__(self, other): # noqa D400 - """%""" + def __mod__(self, other): + """%""" # noqa: D400 return self._value % other - def __mul__(self, other): # noqa D400 - """*""" + def __mul__(self, other): + """*""" # noqa: D400 return self._value * other - def __pow__(self, other): # noqa D400 - """**""" + def __pow__(self, other): + """**""" # noqa: D400 return self._value ** other - def __gt__(self, other): # noqa D400 - """>""" + def __gt__(self, other): + """>""" # noqa: D400 return self._value > other - def __ge__(self, other): # noqa D400 - """>=""" + def __ge__(self, other): + """>=""" # noqa: D400 return self._value >= other - def __le__(self, other): # noqa D400 - """<=""" + def __le__(self, other): + """<=""" # noqa: D400 return self._value <= other - def __lt__(self, other): # noqa D400 - """<""" + def __lt__(self, other): + """<""" # noqa: D400 return self._value < other - def __eq__(self, other): # noqa D400 - """==""" + def __eq__(self, other): + """==""" # noqa: D400 return self._value == other - def __ne__(self, other): # noqa D400 - """!=""" + def __ne__(self, other): + """!=""" # noqa: D400 return self._value != other - def __radd__(self, other): # noqa D400 - """+ (right)""" + def __radd__(self, other): + """+ (right)""" # noqa: D400 return other + self._value - def __rtruediv__(self, other): # noqa D400 - """/ (right)""" + def __rtruediv__(self, other): + """/ (right)""" # noqa: D400 return other / self._value - def __rdivmod__(self, other): # noqa D400 - """divmod (right)""" + def __rdivmod__(self, other): + """divmod (right)""" # noqa: D400, D403 return divmod(other, self._value) - def __rfloordiv__(self, other): # noqa D400 - """// (right)""" + def __rfloordiv__(self, other): + """// (right)""" # noqa: D400 return other // self._value - def __rmod__(self, other): # noqa D400 - """% (right)""" + def __rmod__(self, other): + """% (right)""" # noqa: D400 return other % self._value - def __rmul__(self, other): # noqa D400 - """* (right)""" + def __rmul__(self, other): + """* (right)""" # noqa: D400 return other * self._value - def __rpow__(self, other): # noqa D400 - """** (right)""" + def __rpow__(self, other): + """** (right)""" # noqa: D400 return other ** self._value - def __rsub__(self, other): # noqa D400 - """- (right)""" + def __rsub__(self, other): + """- (right)""" # noqa: D400 return other - self._value diff --git a/glotaran/parameter/parameter_group.py b/glotaran/parameter/parameter_group.py index a603ec3c1..db2fb2084 100644 --- a/glotaran/parameter/parameter_group.py +++ b/glotaran/parameter/parameter_group.py @@ -22,7 +22,7 @@ class ParameterNotFoundException(Exception): """Raised when a Parameter is not found in the Group.""" - def __init__(self, path, label): + def __init__(self, path, label): # noqa: D107 super().__init__(f"Cannot find parameter {'.'.join(path+[label])!r}") @@ -30,21 +30,23 @@ class ParameterGroup(dict): """Represents are group of parameters. Can contain other groups, creating a tree-like hierarchy. - - Parameters - ---------- - label : str - The label of the group. - root_group : ParameterGroup - The root group - - Raises - ------ - ValueError - Raised if the an invalid label is given. """ def __init__(self, label: str = None, root_group: ParameterGroup = None): + """Initialize a :class:`ParameterGroup` instance with ``label``. + + Parameters + ---------- + label : str + The label of the group. + root_group : ParameterGroup + The root group + + Raises + ------ + ValueError + Raised if the an invalid label is given. + """ if label is not None and not Parameter.valid_label(label): raise ValueError(f"'{label}' is not a valid group label.") self._label = label diff --git a/glotaran/parameter/parameter_history.py b/glotaran/parameter/parameter_history.py index 9ab64dd25..15b8f163f 100644 --- a/glotaran/parameter/parameter_history.py +++ b/glotaran/parameter/parameter_history.py @@ -10,7 +10,7 @@ class ParameterHistory: """A class representing a history of parameters.""" - def __init__(self): + def __init__(self): # noqa: D107 self._parameter_labels: list[str] = [] self._parameters: list[np.ndarray] = [] diff --git a/setup.cfg b/setup.cfg index b584563e6..794aa23ef 100644 --- a/setup.cfg +++ b/setup.cfg @@ -81,9 +81,6 @@ ignore_messages = xarraydoc docstring_style = numpy ignore_regex = test_.+|.*wrapper.*|inject_warn_into_call|.*dummy.*|__(.+?)__ -[pydocstyle] -convention = numpy - [mypy] ignore_missing_imports = True scripts_are_modules = True diff --git a/tox.ini b/tox.ini index 9972404d9..fb5dd6105 100644 --- a/tox.ini +++ b/tox.ini @@ -32,6 +32,12 @@ per-file-ignores = # Allow printing in test file test_*.py: T001 +[pydocstyle] +convention = numpy +# this is needed due to the following issue: +# https://github.com/PyCQA/pydocstyle/issues/368 +ignore_decorators = wrap_func_as_method + [testenv:docs] direct = true whitelist_externals = make