From 0d2abd37e191c43be731344e48b7a98ed17381f8 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Sat, 26 Jun 2021 22:26:36 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A7=20Allowed=20mypy=20to=20run=20?= =?UTF-8?q?on=20a=20subset=20of=20glotaran?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit modules that will be checked are: - utils - plugin_system - deprecation --- .pre-commit-config.yaml | 10 ++++++++++ glotaran/builtin/io/yml/test/__init__.py | 0 glotaran/builtin/models/spectral/test/__init__.py | 0 glotaran/deprecation/deprecation_utils.py | 8 ++++---- glotaran/model/test/__init__.py | 0 glotaran/utils/test/test_ipython.py | 5 +++-- setup.cfg | 12 ++++++++++++ 7 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 glotaran/builtin/io/yml/test/__init__.py create mode 100644 glotaran/builtin/models/spectral/test/__init__.py create mode 100644 glotaran/model/test/__init__.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d9d09b6cf..aaefb9039 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -86,6 +86,16 @@ repos: # hooks: # - id: darglint + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910 + hooks: + - id: mypy + files: "^glotaran/(plugin_system|utils|deprecation)" + exclude: "docs" + args: [glotaran] + pass_filenames: false + additional_dependencies: [types-all] + - repo: https://github.com/econchick/interrogate rev: 1.4.0 hooks: diff --git a/glotaran/builtin/io/yml/test/__init__.py b/glotaran/builtin/io/yml/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/glotaran/builtin/models/spectral/test/__init__.py b/glotaran/builtin/models/spectral/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/glotaran/deprecation/deprecation_utils.py b/glotaran/deprecation/deprecation_utils.py index 08af03bbd..8f9c18db1 100644 --- a/glotaran/deprecation/deprecation_utils.py +++ b/glotaran/deprecation/deprecation_utils.py @@ -321,7 +321,7 @@ def inner_wrapper(*args: Any, **kwargs: Any) -> DecoratedCallable: def outer_wrapper(deprecated_object: DecoratedCallable) -> DecoratedCallable: """Wrap deprecated_object of all callable kinds.""" - if type(deprecated_object) is not type: + if not isinstance(deprecated_object, type): return cast(DecoratedCallable, inject_warn_into_call(deprecated_object)) setattr( @@ -329,9 +329,9 @@ def outer_wrapper(deprecated_object: DecoratedCallable) -> DecoratedCallable: "__new__", inject_warn_into_call(deprecated_object.__new__), # type: ignore [arg-type] ) - return deprecated_object + return deprecated_object # type: ignore[return-value] - return outer_wrapper + return cast(Callable[[DecoratedCallable], DecoratedCallable], outer_wrapper) def module_attribute(module_qual_name: str, attribute_name: str) -> Any: @@ -488,7 +488,7 @@ def deprecate_submodule( def warn_getattr(attribute_name: str): if attribute_name == "__file__": - return module_attribute(new_module, attribute_name) + return new_module.__file__ elif attribute_name in dir(new_module): return deprecate_module_attribute( diff --git a/glotaran/model/test/__init__.py b/glotaran/model/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/glotaran/utils/test/test_ipython.py b/glotaran/utils/test/test_ipython.py index 621aaf334..d8e574bf4 100644 --- a/glotaran/utils/test/test_ipython.py +++ b/glotaran/utils/test/test_ipython.py @@ -39,5 +39,6 @@ def test_display_file(tmp_path: Path): expected = MarkdownStr(file_content, syntax="yaml") tmp_file = tmp_path / "test.yml" tmp_file.write_text(file_content) - for path in (tmp_file, str(tmp_file)): - assert display_file(path, syntax="yaml") == expected + + assert display_file(tmp_file, syntax="yaml") == expected + assert display_file(str(tmp_file), syntax="yaml") == expected diff --git a/setup.cfg b/setup.cfg index c7c3d7c9f..f330b4fc5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -84,3 +84,15 @@ convention = numpy ignore_missing_imports = True scripts_are_modules = True show_error_codes = True + +[mypy-glotaran.*] +ignore_errors = True + +[mypy-glotaran.plugin_system.*] +ignore_errors = False + +[mypy-glotaran.utils.*] +ignore_errors = False + +[mypy-glotaran.deprecation.*] +ignore_errors = False From 52afbfc0313e15a1eb6e6f401f86ae980b3922dd Mon Sep 17 00:00:00 2001 From: s-weigand Date: Sun, 4 Jul 2021 17:39:10 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A7=20Partially=20activated=20docs?= =?UTF-8?q?tring=20QA=20tools=20and=20fixed=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 36 ++++++++++--------- .../plugin_system/data_io_registration.py | 2 +- glotaran/plugin_system/model_registration.py | 2 +- .../plugin_system/project_io_registration.py | 2 +- glotaran/utils/ipython.py | 10 +++--- setup.cfg | 2 +- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aaefb9039..1491a1924 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,34 +57,38 @@ repos: args: [--strip-empty-cells] - repo: https://github.com/nbQA-dev/nbQA - rev: 0.13.0 + rev: 0.13.1 hooks: - id: nbqa-black - additional_dependencies: [black==20.8b1] + additional_dependencies: [black==21.6b0] args: [--nbqa-mutate] - id: nbqa-pyupgrade - additional_dependencies: [pyupgrade==2.9.0] + additional_dependencies: [pyupgrade==2.19.4] args: [--nbqa-mutate, --py38-plus] - id: nbqa-flake8 - id: nbqa-check-ast - id: nbqa-isort - additional_dependencies: [isort==5.7.0] + additional_dependencies: [isort==5.9.1] args: [--nbqa-mutate] # Linters - # - repo: https://github.com/PyCQA/pydocstyle - # rev: 5.1.1 - # hooks: - # - id: pydocstyle - # 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] - # - repo: https://github.com/terrencepreilly/darglint - # rev: v1.5.5 - # hooks: - # - id: darglint + - repo: https://github.com/PyCQA/pydocstyle + rev: 6.1.1 + hooks: + - id: pydocstyle + files: "^glotaran/(plugin_system|utils|deprecation)" + 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] + + - repo: https://github.com/terrencepreilly/darglint + rev: v1.8.0 + hooks: + - id: darglint + files: "^glotaran/(plugin_system|utils|deprecation)" + exclude: "docs|tests?" - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.910 diff --git a/glotaran/plugin_system/data_io_registration.py b/glotaran/plugin_system/data_io_registration.py index 8f51686bd..732002254 100644 --- a/glotaran/plugin_system/data_io_registration.py +++ b/glotaran/plugin_system/data_io_registration.py @@ -302,7 +302,7 @@ def data_io_plugin_table(*, plugin_names: bool = False, full_names: bool = False Returns ------- - str + MarkdownStr Markdown table of data io plugins. """ table_data = methods_differ_from_baseclass_table( diff --git a/glotaran/plugin_system/model_registration.py b/glotaran/plugin_system/model_registration.py index 62bb91ea2..f8493292b 100644 --- a/glotaran/plugin_system/model_registration.py +++ b/glotaran/plugin_system/model_registration.py @@ -134,7 +134,7 @@ def model_plugin_table(*, plugin_names: bool = False, full_names: bool = False) Returns ------- - str + MarkdownStr Markdown table of modelnames. """ table_data = [] diff --git a/glotaran/plugin_system/project_io_registration.py b/glotaran/plugin_system/project_io_registration.py index b5f90545f..b2cb10110 100644 --- a/glotaran/plugin_system/project_io_registration.py +++ b/glotaran/plugin_system/project_io_registration.py @@ -488,7 +488,7 @@ def project_io_plugin_table( Returns ------- - str + MarkdownStr Markdown table of project io plugins. """ table_data = methods_differ_from_baseclass_table( diff --git a/glotaran/utils/ipython.py b/glotaran/utils/ipython.py index 9fefddb0b..d4e29cc38 100644 --- a/glotaran/utils/ipython.py +++ b/glotaran/utils/ipython.py @@ -9,8 +9,7 @@ class MarkdownStr(UserString): """String wrapper class for rich display integration of markdown in ipython.""" def __init__(self, wrapped_str: str, *, syntax: str = None): - """String class automatically displayed as markdown by ipython. - + """Initialize string class that is automatically displayed as markdown by ``ipython``. Parameters ---------- @@ -23,13 +22,16 @@ def __init__(self, wrapped_str: str, *, syntax: str = None): ---- Possible syntax highlighting values can e.g. be found here: https://support.codebasehq.com/articles/tips-tricks/syntax-highlighting-in-markdown + + + .. # noqa: DAR101 """ # This needs to be called data since ipython is looking for this attr self.data = str(wrapped_str) self.syntax = syntax def _repr_markdown_(self) -> str: - """Special method used by ``ipython`` to render markdown. + """Render markdown automatically when in a ``ipython`` context. See: https://ipython.readthedocs.io/en/latest/config/integrating.html?highlight=_repr_markdown_#rich-display @@ -64,7 +66,7 @@ def display_file(path: str | PathLike[str], *, syntax: str = None) -> MarkdownSt ---------- path : str | PathLike[str] Paths to the file - syntax : str, optional + syntax : str Syntax highlighting which should be applied, by default None Returns diff --git a/setup.cfg b/setup.cfg index f330b4fc5..d90957a3c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -75,7 +75,7 @@ ignore_messages = xarraydoc [darglint] docstring_style = numpy -ignore_regex = test_.+|.*wrapper.*|inject_warn_into_call|.*dummy.* +ignore_regex = test_.+|.*wrapper.*|inject_warn_into_call|.*dummy.*|__(str|eq)__ [pydocstyle] convention = numpy