Skip to content

Commit 535f23a

Browse files
flake8, pylint, mypy, tests
1 parent f1706c9 commit 535f23a

12 files changed

+584
-280
lines changed

.codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ coverage:
1818
status:
1919
patch:
2020
default:
21-
target: 100%
21+
target: 98%
2222
pytest:
2323
target: 100%
2424
flags:
@@ -44,6 +44,6 @@ coverage:
4444
typing:
4545
flags:
4646
- MyPy
47-
target: 100%
47+
target: 98%
4848

4949
...

.flake8

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,9 @@ per-file-ignores =
110110
# additionally test docstrings don't need param lists (DAR, DCO020):
111111
tests/**.py: DAR, DCO020, S101, S105, S108, S404, S603, WPS202, WPS210, WPS430, WPS436, WPS441, WPS442, WPS450
112112

113-
src/awx_plugins/interfaces/_temporary_private_inject_api.py: ANN001,ANN201,B950,C901,CCR001,D103,E800,LN001,LN002,Q003,WPS110,WPS111,WPS118,WPS125,WPS204,WPS210,WPS211,WPS213,WPS221,WPS226,WPS231,WPS232,WPS319,WPS323,WPS336,WPS337,WPS361,WPS421,WPS429,WPS430,WPS431,WPS436,WPS442,WPS503,WPS507,WPS516,WPS226
114-
115-
116-
117-
118-
119-
120-
121-
122-
123-
124-
113+
tests/_temporary_private_inject_api_test.py: DAR, DCO020, S101, S105, S108, S404, S603, WPS202, WPS210, WPS226, WPS430, WPS436, WPS441, WPS442, WPS450, WPS201
125114

115+
src/awx_plugins/interfaces/_temporary_private_inject_api.py: ANN001,ANN201,B950,C901,CCR001,D103,E800,LN001,LN002,Q003,WPS110,WPS111,WPS118,WPS125,WPS204,WPS210,WPS211,WPS213,WPS221,WPS226,WPS231,WPS232,WPS319,WPS323,WPS336,WPS337,WPS361,WPS421,WPS429,WPS430,WPS431,WPS436,WPS442,WPS503,WPS507,WPS516,WPS226
126116

127117
# Count the number of occurrences of each error/warning code and print a report:
128118
statistics = true

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ repos:
196196
- lxml # dep of `--txt-report`, `--cobertura-xml-report` & `--html-report`
197197
- pytest
198198
- pytest-mock
199+
- types-Jinja2
200+
- types-PyYAML
199201
args:
200202
- --python-version=3.13
201203
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.13
@@ -214,6 +216,8 @@ repos:
214216
- lxml # dep of `--txt-report`, `--cobertura-xml-report` & `--html-report`
215217
- pytest
216218
- pytest-mock
219+
- types-Jinja2
220+
- types-PyYAML
217221
args:
218222
- --python-version=3.12
219223
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.12
@@ -232,6 +236,8 @@ repos:
232236
- lxml # dep of `--txt-report`, `--cobertura-xml-report` & `--html-report`
233237
- pytest
234238
- pytest-mock
239+
- types-Jinja2
240+
- types-PyYAML
235241
args:
236242
- --python-version=3.11
237243
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.11
@@ -255,5 +261,6 @@ repos:
255261
- pytest-mock # needed by pylint-pytest since it picks up pytest's args
256262
- pytest-xdist # needed by pylint-pytest since it picks up pytest's args
257263
- Sphinx # needed by the Sphinx extension stub
264+
- PyYaml # ModuleNotFoundError: No module named 'yaml' without this
258265

259266
...

.pylintrc.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ disable = [
422422
"useless-import-alias", # MyPy requires the opposite
423423
"wrong-import-order", # isort-handled: https://github.com/pylint-dev/pylint/issues/9977
424424
"wrong-import-position", # isort-handled: https://github.com/pylint-dev/pylint/issues/9977
425+
"relative-beyond-top-level", # Developer preference
425426
]
426427

427428
# Enable the message, report, category or checker with the given id(s). You can
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
from typing import Callable
22

3+
from awx_plugins.interfaces._temporary_private_api import ( # noqa: WPS436
4+
EnvVarsType,
5+
InjectorDefinitionType,
6+
InputDefinitionType,
7+
)
38
from awx_plugins.interfaces._temporary_private_credential_api import ( # noqa: WPS436
49
Credential,
5-
GenericOptionalPrimitiveType,
610
)
711

812

913
class ManagedCredentialType:
14+
namespace: str
15+
name: str
16+
kind: str
17+
inputs: InputDefinitionType
18+
injectors: InjectorDefinitionType = None
19+
managed: bool = False
20+
custom_injectors: Callable[
21+
[
22+
Credential,
23+
EnvVarsType, str,
24+
], str | None,
25+
] | None = None
26+
1027
def __init__(
1128
self,
1229
namespace: str,
1330
name: str,
1431
kind: str,
15-
inputs: dict[str, list[dict[str, bool | str] | str]],
16-
injectors: dict[str, dict[str, str]] | None = None,
32+
inputs: InputDefinitionType,
33+
injectors: InjectorDefinitionType = None,
1734
managed: bool = False,
18-
custom_injector: Callable[[Credential, dict[str, GenericOptionalPrimitiveType], str], str | None] | None = None,
35+
custom_injectors: Callable[['Credential', EnvVarsType, str], str | None] | None = None,
1936
): ...

docs/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,7 @@
212212
# Ref: https://stackoverflow.com/a/30624034/595220
213213
nitpick_ignore = [
214214
# temporarily listed ('role', 'reference') pairs that Sphinx cannot resolve
215+
('py:class', 'ExtraVarsType'),
216+
('py:class', 'EnvVarsType'),
217+
('py:class', 'jinja2.sandbox.ImmutableSandboxedEnvironment'),
215218
]

docs/spelling_wordlist.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
ansible
2+
ansible-playbook
13
Ansible
24
filesystem
35
hasn
46
namespace
57
Pre
8+
submodule
69
Submodules
710
Subpackages
11+
subprocess
812
VMware

src/awx_plugins/interfaces/_temporary_private_api.py

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
The hope is that it will be refactored into something more standardized.
55
"""
66

7-
from collections.abc import Callable
7+
from collections.abc import Callable, Mapping
8+
from typing import Union
89

910
from ._temporary_private_credential_api import ( # noqa: WPS436
1011
Credential as Credential,
11-
GenericOptionalPrimitiveType,
1212
)
1313

1414

15-
InputSchemaValueType = list[dict[str, str | bool]]
16-
InputSchemaType = dict[str, InputSchemaValueType]
15+
InputDefinitionValueType = list[dict[str, str | bool]]
16+
InputDefinitionType = dict[str, InputDefinitionValueType]
1717

18+
InjectorDefinitionBaseType = dict[str, dict[str, str]]
19+
InjectorDefinitionType = Union[InjectorDefinitionBaseType, None]
20+
21+
EnvVarsValueType = Mapping[str, 'EnvVarsType'] | list['EnvVarsType'] | str
22+
EnvVarsType = dict[str, EnvVarsValueType]
1823

1924
try:
2025
# pylint: disable-next=unused-import
@@ -37,10 +42,10 @@ class ManagedCredentialType: # type: ignore[no-redef] # noqa: WPS440
3742
kind: str
3843
"""Plugin category."""
3944

40-
inputs: InputSchemaType
45+
inputs: InputDefinitionType
4146
"""UI input fields schema."""
4247

43-
injectors: dict[str, dict[str, str]] | None = None
48+
injectors: InjectorDefinitionType = None
4449
"""Injector hook parameters."""
4550

4651
managed: bool = False
@@ -49,36 +54,9 @@ class ManagedCredentialType: # type: ignore[no-redef] # noqa: WPS440
4954
custom_injectors: Callable[
5055
[
5156
Credential,
52-
dict[str, GenericOptionalPrimitiveType], str,
57+
EnvVarsType, str,
5358
], str | None,
5459
] | None = None
5560
"""Function to call as an alternative to the templated injection."""
5661

57-
def inject_credential( # noqa: WPS211
58-
self: 'ManagedCredentialType',
59-
credential: Credential,
60-
env: dict[str, GenericOptionalPrimitiveType],
61-
safe_env: dict[str, GenericOptionalPrimitiveType],
62-
args: list[GenericOptionalPrimitiveType],
63-
private_data_dir: str,
64-
) -> None: # noqa: DAR101
65-
"""Transform credential data into runtime data.
66-
67-
This inject_credential is the entry point within this
68-
project. Outside of this project, in AWX, the standalone
69-
inject_credential is called directly. Once the above awx
70-
import hack is removed the duplication can be removed.
71-
"""
72-
from ._temporary_private_inject_api import ( # noqa: WPS433, WPS436
73-
inject_credential,
74-
)
75-
inject_credential(
76-
self,
77-
credential,
78-
env,
79-
safe_env,
80-
args,
81-
private_data_dir,
82-
)
83-
8462
__all__ = () # noqa: WPS410

src/awx_plugins/interfaces/_temporary_private_credential_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
GenericOptionalPrimitiveType = bool | str | int | float | None # noqa: WPS465
77
"""Generic type for input values."""
88

9+
CredentialInputType = dict[str, GenericOptionalPrimitiveType]
10+
911

1012
class Credential:
1113
"""Input supplied by the user.
@@ -16,9 +18,9 @@ class Credential:
1618

1719
def __init__(
1820
self: 'Credential',
19-
inputs: dict[str, GenericOptionalPrimitiveType] | None = None,
21+
inputs: CredentialInputType | None = None,
2022
) -> None:
21-
self._inputs: dict[str, GenericOptionalPrimitiveType] = inputs or {}
23+
self._inputs: CredentialInputType = inputs or {}
2224

2325
def get_input(
2426
self: 'Credential',

0 commit comments

Comments
 (0)