Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧Add more QA tools for parts of glotaran #739

Merged
merged 2 commits into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,48 @@ 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
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
Expand Down
Empty file.
Empty file.
8 changes: 4 additions & 4 deletions glotaran/deprecation/deprecation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,17 @@ 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(
deprecated_object,
"__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:
Expand Down Expand Up @@ -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(
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion glotaran/plugin_system/data_io_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion glotaran/plugin_system/model_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion glotaran/plugin_system/project_io_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 6 additions & 4 deletions glotaran/utils/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions glotaran/utils/test/test_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 13 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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