Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cerberus with jsonschema for configuration validation #3638

Merged
merged 2 commits into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ jobs:
- tox_env: docs
python-version: 3.9
- tox_env: py38
PREFIX: PYTEST_REQPASS=461
PREFIX: PYTEST_REQPASS=453
python-version: 3.8
cover: true
- tox_env: py39
PREFIX: PYTEST_REQPASS=461
PREFIX: PYTEST_REQPASS=453
python-version: 3.9
cover: true
- tox_env: py310
PREFIX: PYTEST_REQPASS=461
PREFIX: PYTEST_REQPASS=453
python-version: "3.10"
cover: true
- tox_env: py311
os: ubuntu-20.04
python-version: "~3.11.0-0" # see https://github.com/actions/setup-python/issues/213#issuecomment-1146676713
cover: true
- tox_env: py39-devel
PREFIX: PYTEST_REQPASS=461
PREFIX: PYTEST_REQPASS=453
python-version: 3.9
cover: true
- tox_env: py310-devel
PREFIX: PYTEST_REQPASS=461
PREFIX: PYTEST_REQPASS=453
python-version: "3.10"
# see https://github.com/ansible-community/molecule/issues/3291
experimental: true
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ repos:
- id: pylint
additional_dependencies:
- ansible-compat>=2.2.0
- cerberus
- click
- click-help-colors
- cookiecutter
- enrich>=1.2.7
- filelock
- jsonschema
- pexpect
- testinfra
- repo: https://github.com/jazzband/pip-tools
Expand Down
7 changes: 3 additions & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ disallow_untyped_calls = True
warn_redundant_casts = True
no_implicit_optional = True

# 3rd party ignores, to remove once they add hints
[mypy-cerberus.*]
ignore_missing_imports = True

[mypy-click_completion]
ignore_missing_imports = True

Expand All @@ -19,6 +15,9 @@ ignore_missing_imports = True
[mypy-cookiecutter.*]
ignore_missing_imports = True

[mypy-jsonschema.*]
ignore_missing_imports = True

[mypy-pexpect]
ignore_missing_imports = True

Expand Down
4 changes: 0 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ arrow==1.2.2
attrs==21.4.0
babel==2.10.3
binaryornot==0.4.4
cerberus==1.3.2
certifi==2022.6.15
cffi==1.15.0
chardet==4.0.0
Expand Down Expand Up @@ -84,6 +83,3 @@ tomli==2.0.1
typing-extensions==4.2.0
urllib3==1.26.9
zipp==3.8.0

# The following packages are considered to be unsafe in a requirements file:
# setuptools
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ zip_safe = False
# These are required in actual runtime:
install_requires =
ansible-compat >= 2.2.0
cerberus >= 1.3.1, !=1.3.3, !=1.3.4
click >= 8.0, < 9
click-help-colors >= 0.9
cookiecutter >= 1.7.3 # dependency issues in older versions
enrich >= 1.2.7
jsonschema >= 4.9.1
Jinja2 >= 2.11.3
packaging
pluggy >= 0.7.1, < 2.0
Expand Down
9 changes: 0 additions & 9 deletions src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ def _combine(self, env=os.environ, keep_string=None) -> MutableMapping:
for base_config in base_configs:
with util.open_file(base_config) as stream:
s = stream.read()
self._preflight(s)
interpolated_config = self._interpolate(s, env, keep_string)
defaults = util.merge_dicts(
defaults, util.safe_load(interpolated_config)
Expand All @@ -314,7 +313,6 @@ def _combine(self, env=os.environ, keep_string=None) -> MutableMapping:
if self.molecule_file:
with util.open_file(self.molecule_file) as stream:
s = stream.read()
self._preflight(s)
interpolated_config = self._interpolate(s, env, keep_string)
defaults = util.merge_dicts(
defaults, util.safe_load(interpolated_config)
Expand Down Expand Up @@ -429,13 +427,6 @@ def _get_defaults(self) -> MutableMapping:
},
}

def _preflight(self, data: MutableMapping):
env = set_env_from_file(os.environ.copy(), self.env_file)
errors, data = schema_v3.pre_validate(data, env, MOLECULE_KEEP_STRING)
if errors:
msg = f"Failed to pre-validate.\n\n{errors}"
util.sysexit_with_message(msg, detail=data)

def _validate(self):
msg = f"Validating schema {self.molecule_file}."
LOG.debug(msg)
Expand Down