Skip to content

Commit

Permalink
flake8, pylint, mypy, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismeyersfsu committed Dec 16, 2024
1 parent f1706c9 commit 535f23a
Show file tree
Hide file tree
Showing 12 changed files with 584 additions and 280 deletions.
4 changes: 2 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ coverage:
status:
patch:
default:
target: 100%
target: 98%
pytest:
target: 100%
flags:
Expand All @@ -44,6 +44,6 @@ coverage:
typing:
flags:
- MyPy
target: 100%
target: 98%

...
14 changes: 2 additions & 12 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,9 @@ per-file-ignores =
# additionally test docstrings don't need param lists (DAR, DCO020):
tests/**.py: DAR, DCO020, S101, S105, S108, S404, S603, WPS202, WPS210, WPS430, WPS436, WPS441, WPS442, WPS450

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











tests/_temporary_private_inject_api_test.py: DAR, DCO020, S101, S105, S108, S404, S603, WPS202, WPS210, WPS226, WPS430, WPS436, WPS441, WPS442, WPS450, WPS201

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

# Count the number of occurrences of each error/warning code and print a report:
statistics = true
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ repos:
- lxml # dep of `--txt-report`, `--cobertura-xml-report` & `--html-report`
- pytest
- pytest-mock
- types-Jinja2
- types-PyYAML
args:
- --python-version=3.13
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.13
Expand All @@ -214,6 +216,8 @@ repos:
- lxml # dep of `--txt-report`, `--cobertura-xml-report` & `--html-report`
- pytest
- pytest-mock
- types-Jinja2
- types-PyYAML
args:
- --python-version=3.12
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.12
Expand All @@ -232,6 +236,8 @@ repos:
- lxml # dep of `--txt-report`, `--cobertura-xml-report` & `--html-report`
- pytest
- pytest-mock
- types-Jinja2
- types-PyYAML
args:
- --python-version=3.11
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.11
Expand All @@ -255,5 +261,6 @@ repos:
- pytest-mock # needed by pylint-pytest since it picks up pytest's args
- pytest-xdist # needed by pylint-pytest since it picks up pytest's args
- Sphinx # needed by the Sphinx extension stub
- PyYaml # ModuleNotFoundError: No module named 'yaml' without this

...
1 change: 1 addition & 0 deletions .pylintrc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ disable = [
"useless-import-alias", # MyPy requires the opposite
"wrong-import-order", # isort-handled: https://github.com/pylint-dev/pylint/issues/9977
"wrong-import-position", # isort-handled: https://github.com/pylint-dev/pylint/issues/9977
"relative-beyond-top-level", # Developer preference
]

# Enable the message, report, category or checker with the given id(s). You can
Expand Down
25 changes: 21 additions & 4 deletions _type_stubs/awx/main/models/credential.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
from typing import Callable

from awx_plugins.interfaces._temporary_private_api import ( # noqa: WPS436
EnvVarsType,
InjectorDefinitionType,
InputDefinitionType,
)
from awx_plugins.interfaces._temporary_private_credential_api import ( # noqa: WPS436
Credential,
GenericOptionalPrimitiveType,
)


class ManagedCredentialType:
namespace: str
name: str
kind: str
inputs: InputDefinitionType
injectors: InjectorDefinitionType = None
managed: bool = False
custom_injectors: Callable[
[
Credential,
EnvVarsType, str,
], str | None,
] | None = None

def __init__(
self,
namespace: str,
name: str,
kind: str,
inputs: dict[str, list[dict[str, bool | str] | str]],
injectors: dict[str, dict[str, str]] | None = None,
inputs: InputDefinitionType,
injectors: InjectorDefinitionType = None,
managed: bool = False,
custom_injector: Callable[[Credential, dict[str, GenericOptionalPrimitiveType], str], str | None] | None = None,
custom_injectors: Callable[['Credential', EnvVarsType, str], str | None] | None = None,
): ...
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,7 @@
# Ref: https://stackoverflow.com/a/30624034/595220
nitpick_ignore = [
# temporarily listed ('role', 'reference') pairs that Sphinx cannot resolve
('py:class', 'ExtraVarsType'),
('py:class', 'EnvVarsType'),
('py:class', 'jinja2.sandbox.ImmutableSandboxedEnvironment'),
]
4 changes: 4 additions & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
ansible
ansible-playbook
Ansible
filesystem
hasn
namespace
Pre
submodule
Submodules
Subpackages
subprocess
VMware
46 changes: 12 additions & 34 deletions src/awx_plugins/interfaces/_temporary_private_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
The hope is that it will be refactored into something more standardized.
"""

from collections.abc import Callable
from collections.abc import Callable, Mapping
from typing import Union

from ._temporary_private_credential_api import ( # noqa: WPS436
Credential as Credential,
GenericOptionalPrimitiveType,
)


InputSchemaValueType = list[dict[str, str | bool]]
InputSchemaType = dict[str, InputSchemaValueType]
InputDefinitionValueType = list[dict[str, str | bool]]
InputDefinitionType = dict[str, InputDefinitionValueType]

InjectorDefinitionBaseType = dict[str, dict[str, str]]
InjectorDefinitionType = Union[InjectorDefinitionBaseType, None]

EnvVarsValueType = Mapping[str, 'EnvVarsType'] | list['EnvVarsType'] | str
EnvVarsType = dict[str, EnvVarsValueType]

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

inputs: InputSchemaType
inputs: InputDefinitionType
"""UI input fields schema."""

injectors: dict[str, dict[str, str]] | None = None
injectors: InjectorDefinitionType = None
"""Injector hook parameters."""

managed: bool = False
Expand All @@ -49,36 +54,9 @@ class ManagedCredentialType: # type: ignore[no-redef] # noqa: WPS440
custom_injectors: Callable[
[
Credential,
dict[str, GenericOptionalPrimitiveType], str,
EnvVarsType, str,
], str | None,
] | None = None
"""Function to call as an alternative to the templated injection."""

def inject_credential( # noqa: WPS211
self: 'ManagedCredentialType',
credential: Credential,
env: dict[str, GenericOptionalPrimitiveType],
safe_env: dict[str, GenericOptionalPrimitiveType],
args: list[GenericOptionalPrimitiveType],
private_data_dir: str,
) -> None: # noqa: DAR101
"""Transform credential data into runtime data.
This inject_credential is the entry point within this
project. Outside of this project, in AWX, the standalone
inject_credential is called directly. Once the above awx
import hack is removed the duplication can be removed.
"""
from ._temporary_private_inject_api import ( # noqa: WPS433, WPS436
inject_credential,
)
inject_credential(
self,
credential,
env,
safe_env,
args,
private_data_dir,
)

__all__ = () # noqa: WPS410
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
GenericOptionalPrimitiveType = bool | str | int | float | None # noqa: WPS465
"""Generic type for input values."""

CredentialInputType = dict[str, GenericOptionalPrimitiveType]


class Credential:
"""Input supplied by the user.
Expand All @@ -16,9 +18,9 @@ class Credential:

def __init__(
self: 'Credential',
inputs: dict[str, GenericOptionalPrimitiveType] | None = None,
inputs: CredentialInputType | None = None,
) -> None:
self._inputs: dict[str, GenericOptionalPrimitiveType] = inputs or {}
self._inputs: CredentialInputType = inputs or {}

def get_input(
self: 'Credential',
Expand Down
Loading

0 comments on commit 535f23a

Please sign in to comment.