Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 5e08364

Browse files
committed
Add package invoke
1 parent be9db4c commit 5e08364

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

monkey_patch_invoke.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# type: ignore
2+
# pylint: disable=unused-argument
3+
import inspect
4+
import types
5+
from typing import Callable, Union
6+
7+
from invoke.tasks import NO_DEFAULT, Task
8+
9+
10+
def monkey_patch_invoke() -> None:
11+
12+
def patched_argspec(self: Task, body: Callable) -> tuple[list[str], dict[str, object]]:
13+
"""
14+
A monkey patching code for supporting python3
15+
from: https://github.com/pyinvoke/invoke/issues/357#issuecomment-1250744013
16+
"""
17+
func: Union[Callable,
18+
types.MethodWrapperType] = body if isinstance(body, types.FunctionType) else body.__call__
19+
sig = inspect.signature(func)
20+
arg_names = [k for k, _ in sig.parameters.items()]
21+
spec_dict: dict[str, object] = {}
22+
for key, value in sig.parameters.items():
23+
value = value.default if not value.default == sig.empty else NO_DEFAULT
24+
spec_dict.update({key: value})
25+
# Pop context argument
26+
try:
27+
context_arg = arg_names.pop(0)
28+
except IndexError as error:
29+
raise TypeError('Tasks must have an initial Context argument!') from error
30+
del spec_dict[context_arg]
31+
return arg_names, spec_dict
32+
33+
Task.argspec = types.MethodType(patched_argspec, Task)
34+
35+
36+
monkey_patch_invoke()

poetry.lock

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pytest-cov = "^4.0.0"
2121
pylint-quotes = "^0.2.3"
2222
unify = "^0.5"
2323
toml = "^0.10.2"
24+
invoke = "^1.7.3"
2425

2526
[build-system]
2627
requires = ["poetry-core>=1.0.0"]

0 commit comments

Comments
 (0)