Skip to content

Commit a934d29

Browse files
committed
fix check-task issues
1 parent 416057e commit a934d29

File tree

6 files changed

+79
-36
lines changed

6 files changed

+79
-36
lines changed

.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
[flake8]
33
max-line-length = 88
44
extend-ignore = E203
5+

.pre-commit-config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ repos:
2121
rev: 19.3b0
2222
hooks:
2323
- id: black
24+
language_version: python3
25+
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Classes for describing plugins"""
2-
from typing import Optional, Sequence
2+
from typing import Optional, List
33

44
from cmem_plugin_base.dataintegration.plugins import WorkflowPlugin, TransformPlugin
55

@@ -11,11 +11,18 @@ class PluginParameter:
1111
:param label: A human-readable label of the parameter
1212
:param description: A human-readable description of the parameter
1313
:param default_value: The parameter default value (optional)
14-
:param advanced: True, if this is an advanced parameter that should only be changed by experienced users
14+
:param advanced: True, if this is an advanced parameter that should only be
15+
changed by experienced users
1516
"""
1617

17-
def __init__(self, name: str, label: str = "", description: str = "",
18-
default_value: Optional[str] = None, advanced: bool = False) -> None:
18+
def __init__(
19+
self,
20+
name: str,
21+
label: str = "",
22+
description: str = "",
23+
default_value: Optional[str] = None,
24+
advanced: bool = False,
25+
) -> None:
1926
self.name = name
2027
self.label = label
2128
self.description = description
@@ -34,44 +41,75 @@ class PluginDescription:
3441
:param parameters: Available plugin parameters
3542
"""
3643

37-
def __init__(self, plugin_class, label: str, description: str = "", documentation: str = "",
38-
categories: Sequence[str] = [], parameters: Sequence[PluginParameter] = []) -> None:
39-
# Set the type of the plugin. Same as the class name of the plugin base class, e.g., 'WorkflowPlugin'.
44+
def __init__(
45+
self,
46+
plugin_class,
47+
label: str,
48+
description: str = "",
49+
documentation: str = "",
50+
categories: List[str] = None,
51+
parameters: List[PluginParameter] = None,
52+
) -> None:
53+
# Set the type of the plugin. Same as the class name of the plugin
54+
# base class, e.g., 'WorkflowPlugin'.
4055
if issubclass(plugin_class, WorkflowPlugin):
4156
self.plugin_type = "WorkflowPlugin"
4257
elif issubclass(plugin_class, TransformPlugin):
4358
self.plugin_type = "TransformPlugin"
4459
else:
45-
raise ValueError(f"Class {plugin_class.__name__} does not implement a supported plugin base class"
46-
f" (e.g., WorkflowPlugin).")
60+
raise ValueError(
61+
f"Class {plugin_class.__name__} does not implement a supported"
62+
f"plugin base class (e.g., WorkflowPlugin)."
63+
)
4764

4865
self.plugin_class = plugin_class
4966
self.module_name = plugin_class.__module__
5067
self.class_name = plugin_class.__name__
51-
self.categories = categories
68+
if categories is None:
69+
self.categories = []
70+
else:
71+
self.categories = categories
5272
self.label = label
5373
self.description = description
5474
self.documentation = documentation
55-
self.parameters = parameters
75+
if parameters is None:
76+
self.parameters = []
77+
else:
78+
self.parameters = parameters
5679

5780

5881
class Plugin:
82+
"""Annotate classes with plugin descriptions."""
5983
plugins: list[PluginDescription] = []
6084

61-
def __init__(self, label: str, description: str = "", documentation: str = "",
62-
categories: Sequence[str] = [], parameters: Sequence[PluginParameter] = []):
85+
def __init__(
86+
self,
87+
label: str,
88+
description: str = "",
89+
documentation: str = "",
90+
categories: List[str] = None,
91+
parameters: List[PluginParameter] = None,
92+
):
6393
self.label = label
6494
self.description = description
6595
self.documentation = documentation
66-
self.categories = categories
67-
self.parameters = parameters
96+
if categories is None:
97+
self.categories = []
98+
else:
99+
self.categories = categories
100+
if parameters is None:
101+
self.parameters = []
102+
else:
103+
self.parameters = parameters
68104

69105
def __call__(self, func):
70-
plugin_desc = PluginDescription(plugin_class=func,
71-
label=self.label,
72-
description=self.description,
73-
documentation=self.documentation,
74-
categories=self.categories,
75-
parameters=self.parameters)
106+
plugin_desc = PluginDescription(
107+
plugin_class=func,
108+
label=self.label,
109+
description=self.description,
110+
documentation=self.documentation,
111+
categories=self.categories,
112+
parameters=self.parameters,
113+
)
76114
Plugin.plugins.append(plugin_desc)
77115
return func

cmem_plugin_base/dataintegration/discovery.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,32 @@
33
import importlib.util
44
import json
55
import pkgutil
6-
from subprocess import check_output
7-
from typing import Dict, List
6+
from subprocess import check_output # nosec
87
from typing import Sequence
98

109
from cmem_plugin_base.dataintegration.description import PluginDescription, Plugin
1110

1211

13-
def get_packages() -> List[Dict]:
12+
def get_packages():
1413
"""Get installed python packages.
1514
1615
Returns a list of dict with the following keys:
1716
- name - package name
1817
- version - package version
1918
"""
20-
return json.loads(
21-
check_output(
22-
["pip", "list", "--format", "json"],
23-
shell=False
24-
)
25-
)
19+
return json.loads(check_output(["pip", "list", "--format", "json"], shell=False))
2620

2721

2822
def discover_plugins(package_name: str = "cmem") -> Sequence[PluginDescription]:
2923
"""Finds all plugins within a base package.
3024
31-
:param package_name: The base package. Will recurse into all submodules of this package.
25+
:param package_name: The base package. Will recurse into all submodules
26+
of this package.
3227
"""
3328

3429
def import_submodules(package):
35-
for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
36-
full_name = package.__name__ + '.' + name
30+
for _loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
31+
full_name = package.__name__ + "." + name
3732
module = importlib.import_module(full_name)
3833
if is_pkg:
3934
import_submodules(module)

cmem_plugin_base/dataintegration/plugins.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class TransformPlugin:
2828
def transform(self, inputs: Sequence[Sequence[str]]) -> Sequence[str]:
2929
"""
3030
Transforms a collection of values.
31-
:param inputs: A sequence which contains as many elements as there are input operators for this transformation.
32-
For each input operator it contains a sequence of values.
31+
:param inputs: A sequence which contains as many elements as there are input
32+
operators for this transformation.
33+
For each input operator it contains a sequence of values.
3334
:return: The transformed values.
3435
"""
35-
pass

pyproject.toml

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ defusedxml = "^0.7.1"
3939
requires = ["poetry-core>=1.0.0"]
4040
build-backend = "poetry.core.masonry.api"
4141

42+
[tool.isort]
43+
profile = "black"
44+
4245
[tool.pylint.MASTER]
4346
load-plugins="pylint_junit"
4447

@@ -55,10 +58,14 @@ disable = "C0330, C0326, R0903"
5558

5659
[tool.pylint.format]
5760
max-line-length = "88"
61+
disable = "C0330, C0326"
62+
max-args = "8"
63+
max-attributes = "9"
5864

5965
[tool.mypy]
6066
warn_return_any = true
6167
ignore_missing_imports = true
6268

6369
[tool.pytest.ini_options]
6470
addopts = ""
71+

0 commit comments

Comments
 (0)