Skip to content

Commit

Permalink
Add docstrings and type hints to schema_v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Nov 22, 2024
1 parent 0f21762 commit 2e7b423
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
7 changes: 0 additions & 7 deletions .config/pydoclint-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ src/molecule/dependency/shell.py
DOC107: Method `Shell.__init__`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC103: Method `Shell.__init__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [config: ].
--------------------
src/molecule/model/schema_v3.py
DOC101: Function `validate`: Docstring contains fewer arguments than in function signature.
DOC106: Function `validate`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
DOC107: Function `validate`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC103: Function `validate`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [c: ].
DOC201: Function `validate` does not have a return section in docstring
--------------------
src/molecule/verifier/base.py
DOC601: Class `Verifier`: Class docstring contains fewer class attributes than actual class attributes. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.)
DOC603: Class `Verifier`: Class docstring attributes are different from actual class attributes. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Attributes in the class definition but not in the docstring: [__metaclass__: ]. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.)
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def _validate(self) -> None:
msg = f"Validating schema {self.molecule_file}."
LOG.debug(msg)

errors = schema_v3.validate(self.config) # type: ignore[no-untyped-call]
errors = schema_v3.validate(self.config)
if errors:
msg = f"Failed to validate {self.molecule_file}\n\n{errors}"
util.sysexit_with_message(msg)
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# D104 # noqa: D104, ERA001
# noqa: D104
29 changes: 21 additions & 8 deletions src/molecule/model/schema_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

import json
import logging
import os

from pathlib import Path
from typing import TYPE_CHECKING

from jsonschema import validate as jsonschema_validate
from jsonschema.exceptions import ValidationError
Expand All @@ -31,32 +33,43 @@
from molecule.data import __file__ as data_module


if TYPE_CHECKING:
from molecule.types import ConfigData


LOG = logging.getLogger(__name__)


def validate(c): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201
"""Perform schema validation."""
def validate(c: ConfigData) -> list[str]:
"""Perform schema validation.
Args:
c: Dictionary of configuration data.
Returns:
Any errors generated by the schema validation.
"""
result = []
schemas = []

schema_files = [os.path.dirname(data_module) + "/molecule.json"] # noqa: PTH120
schema_files = [str(Path(data_module).parent / "molecule.json")]
driver_name = c["driver"]["name"]

driver_schema_file = None
if driver_name in api.drivers():
driver_schema_file = api.drivers()[driver_name].schema_file()
driver_schema_file = Path(api.drivers()[driver_name].schema_file())

if driver_schema_file is None:
msg = f"Driver {driver_name} does not provide a schema."
LOG.warning(msg)
elif not os.path.exists(driver_schema_file): # noqa: PTH110
elif not driver_schema_file.exists():
msg = f"Schema {driver_schema_file} for driver {driver_name} not found."
LOG.warning(msg)
else:
schema_files.append(driver_schema_file)
schema_files.append(str(driver_schema_file))

for schema_file in schema_files:
with open(schema_file, encoding="utf-8") as f: # noqa: PTH123
with Path(schema_file).open(encoding="utf-8") as f:
schema = json.load(f)
schemas.append(schema)

Expand Down

0 comments on commit 2e7b423

Please sign in to comment.