Skip to content

Commit

Permalink
DevOps: Update the mypy pre-commit dependency (#246)
Browse files Browse the repository at this point in the history
The requirement is updated to `mypy==0.930`. This allows us to move the
configuration from `tox.ini` to the `pyproject.toml` file. The config in
`.pre-commit-config.yaml` is also corrected as the include path did not
properly include the `src` starting folder.

The remaining configuration for `tox.ini` is also moved to the
`pyproject.toml` and deleted.
  • Loading branch information
sphuber authored Oct 31, 2022
1 parent fdf4c63 commit d9a200a
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 87 deletions.
11 changes: 7 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ repos:
additional_dependencies: ['toml']

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.790
rev: v0.982
hooks:
- id: mypy
args: [--config-file=tox.ini]
additional_dependencies: ['aio_pika~=6.6']
args: [--config-file=pyproject.toml]
additional_dependencies: [
'toml',
'types-pyyaml',
]
files: >
(?x)^(
plumpy/.*py|
src/plumpy/.*py|
)$
- repo: https://github.com/PyCQA/pylint
Expand Down
63 changes: 63 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pre-commit = [
'mypy==0.982',
'pre-commit~=2.2',
'pylint==2.12.2',
'types-pyyaml'
]
tests = [
'ipykernel==6.12.1',
Expand Down Expand Up @@ -83,6 +84,28 @@ include_trailing_comma = true
line_length = 120
multi_line_output = 3

[tool.mypy]
show_error_codes = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
warn_unused_ignores = true
warn_redundant_casts = true

[[tool.mypy.overrides]]
module = 'test.*'
check_untyped_defs = false

[[tool.mypy.overrides]]
module = [
'aio_pika.*',
'aiocontextvars.*',
'kiwipy.*',
'nest_asyncio.*',
'tblib.*',
]
ignore_missing_imports = true

[tool.pylint.format]
max-line-length = 120

Expand Down Expand Up @@ -118,3 +141,43 @@ column_limit = 120
dedent_closing_brackets = true
indent_dictionary_value = false
split_arguments_when_comma_terminated = true

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py37
[testenv]
usedevelop = true
[testenv:py{37,38,39,310}]
description = Run the unit tests
extras =
tests
commands = pytest {posargs}
[testenv:py{37,38,39,310}-pre-commit]
description = Run the style checks and formatting
extras =
pre-commit
tests
commands = pre-commit run {posargs}
[testenv:docs-{update,clean}]
description = Build the documentation
extras = docs
whitelist_externals = rm
commands =
clean: rm -rf docs/_build
sphinx-build -nW --keep-going -b {posargs:html} docs/source/ docs/_build/{posargs:html}
[testenv:docs-live]
description = Build the documentation and launch browser (with live updates)
extras = docs
deps = sphinx-autobuild
commands =
sphinx-autobuild \
--re-ignore _build/.* \
--port 0 --open-browser \
-n -b {posargs:html} docs/source/ docs/_build/{posargs:html}
"""
4 changes: 2 additions & 2 deletions src/plumpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# mypy: disable-error-code=name-defined
# pylint: disable=undefined-variable
# type: ignore[name-defined]
__version__ = '0.21.0'

import logging
Expand Down Expand Up @@ -33,7 +33,7 @@
# for more details
class NullHandler(logging.Handler):

def emit(self, record):
def emit(self, record: logging.LogRecord) -> None:
pass


Expand Down
10 changes: 5 additions & 5 deletions src/plumpy/base/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ def event(
"""A decorator to check for correct transitions, raising ``EventError`` on invalid transitions."""
if from_states != '*':
if inspect.isclass(from_states):
from_states = (from_states,) # type: ignore
from_states = (from_states,)
if not all(issubclass(state, State) for state in from_states): # type: ignore
raise TypeError(f'from_states: {from_states}')
if to_states != '*':
if inspect.isclass(to_states):
to_states = (to_states,) # type: ignore
to_states = (to_states,)
if not all(issubclass(state, State) for state in to_states): # type: ignore
raise TypeError(f'to_states: {to_states}')

Expand Down Expand Up @@ -111,7 +111,7 @@ def transition(self: Any, *a: Any, **kw: Any) -> Any:
return transition

if inspect.isfunction(from_states):
return wrapper(from_states) # type: ignore
return wrapper(from_states)

return wrapper

Expand Down Expand Up @@ -397,8 +397,8 @@ def _create_state_instance(self, state: Union[Hashable, State, Type[State]], *ar
return state_cls(self, *args, **kwargs)

def _ensure_state_class(self, state: Union[Hashable, Type[State]]) -> Type[State]:
if inspect.isclass(state) and issubclass(state, State): # type: ignore
return cast(Type[State], state)
if inspect.isclass(state) and issubclass(state, State):
return state

try:
return self.get_states_map()[cast(Hashable, state)] # pylint: disable=unsubscriptable-object
Expand Down
2 changes: 1 addition & 1 deletion src/plumpy/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def new_event_loop(*args: Any, **kwargs: Any) -> asyncio.AbstractEventLoop:
raise NotImplementedError('this method is not implemented because `plumpy` uses a single reentrant loop')


class PlumpyEventLoopPolicy(asyncio.DefaultEventLoopPolicy): # type: ignore
class PlumpyEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
"""Custom event policy that always returns the same event loop that is made reentrant by ``nest_asyncio``."""

_loop: Optional[asyncio.AbstractEventLoop] = None
Expand Down
2 changes: 1 addition & 1 deletion src/plumpy/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ContextMixin(persistence.Savable):
CONTEXT: str = '_context'

def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs) # type: ignore
super().__init__(*args, **kwargs)
self._context: Optional[AttributesDict] = AttributesDict()

@property
Expand Down
8 changes: 4 additions & 4 deletions src/plumpy/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _bundle_constructor(loader: yaml.Loader, data: Any) -> Generator[Bundle, Non


yaml.add_representer(Bundle, _bundle_representer)
yaml.add_constructor(_BUNDLE_TAG, _bundle_constructor)
yaml.add_constructor(_BUNDLE_TAG, _bundle_constructor) # type: ignore[arg-type]


class Persister(metaclass=abc.ABCMeta):
Expand Down Expand Up @@ -340,7 +340,7 @@ def delete_process_checkpoints(self, pid: PID_TYPE) -> None:
del self._checkpoints[pid]


SavableClsType = TypeVar('SavableClsType', bound='Type[Savable]')
SavableClsType = TypeVar('SavableClsType', bound='Type[Savable]') # type: ignore[name-defined]


def auto_persist(*members: str) -> Callable[[SavableClsType], SavableClsType]:
Expand Down Expand Up @@ -650,5 +650,5 @@ def load_instance_state(self, saved_state: SAVED_STATE_TYPE, load_context: LoadS
super().load_instance_state(saved_state, load_context)
if self._callbacks:
# typing says asyncio.Future._callbacks needs to be called, but in the python 3.7 code it is a simple list
for callback in self._callbacks: # type: ignore
self.remove_done_callback(callback)
for callback in self._callbacks:
self.remove_done_callback(callback) # type: ignore[arg-type]
5 changes: 4 additions & 1 deletion src/plumpy/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class ProcessStateMachineMeta(abc.ABCMeta, state_machine.StateMachineMeta):


# Make ProcessStateMachineMeta instances (classes) YAML - able
yaml.representer.Representer.add_representer(ProcessStateMachineMeta, yaml.representer.Representer.represent_name)
yaml.representer.Representer.add_representer(
ProcessStateMachineMeta,
yaml.representer.Representer.represent_name # type: ignore[arg-type]
)


def ensure_not_closed(func: Callable[..., Any]) -> Callable[..., Any]:
Expand Down
2 changes: 1 addition & 1 deletion src/plumpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def load_function(name: str, instance: Optional[Any] = None) -> Callable[..., An
obj = load_object(name)
if inspect.ismethod(obj):
if instance is not None:
return obj.__get__(instance, instance.__class__)
return obj.__get__(instance, instance.__class__) # type: ignore[attr-defined]

return obj

Expand Down
68 changes: 0 additions & 68 deletions tox.ini

This file was deleted.

0 comments on commit d9a200a

Please sign in to comment.