Skip to content

Commit

Permalink
rolled back precommit config
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroPasotti committed Dec 4, 2023
1 parent 9cd044f commit d9c8dd0
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 178 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/quality_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ jobs:
python-version: "3.10"
- name: Install dependencies
run: python -m pip install tox
- name: Run lint tests
- name: Run linter
run: tox -vve lint
- name: Run static checks
run: tox -vve static


unit-test:
name: Unit Tests
Expand All @@ -38,4 +41,4 @@ jobs:
- name: Install dependencies
run: python -m pip install tox
- name: Run unit tests
run: tox -vve unit
run: tox -vve unit
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,3 @@ repos:
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.338
hooks:
- id: pyright
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ skip-magic-trailing-comma = false
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

[tool.pyright]
ignore = [
"scenario/sequences.py",
"scenario/cpature_events.py"
]
[tool.isort]
profile = "black"

Expand Down
4 changes: 2 additions & 2 deletions scenario/capture_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import typing
from contextlib import contextmanager
from typing import ContextManager, List, Type, TypeVar
from typing import Type, TypeVar

from ops import CollectStatusEvent
from ops.framework import (
Expand All @@ -24,7 +24,7 @@ def capture_events(
*types: Type[EventBase],
include_framework=False,
include_deferred=True,
) -> ContextManager[List[EventBase]]:
):
"""Capture all events of type `*types` (using instance checks).
Arguments exposed so that you can define your own fixtures if you want to.
Expand Down
39 changes: 28 additions & 11 deletions scenario/consistency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def check_consistency(
So a State declaring some config keys that are not in the charm's config.yaml is nonsense,
and the combination of the two is inconsistent.
"""
juju_version: Tuple[int, ...] = tuple(map(int, juju_version.split(".")))
juju_version_: Tuple[int, ...] = tuple(map(int, juju_version.split(".")))

if os.getenv("SCENARIO_SKIP_CONSISTENCY_CHECKS"):
logger.info("skipping consistency checks.")
Expand All @@ -74,7 +74,7 @@ def check_consistency(
state=state,
event=event,
charm_spec=charm_spec,
juju_version=juju_version,
juju_version=juju_version_,
)
errors.extend(results.errors)
warnings.extend(results.warnings)
Expand Down Expand Up @@ -201,12 +201,14 @@ def _check_action_event(
"cannot construct a workload event without the container instance. "
"Please pass one.",
)
return

elif not event.name.startswith(normalize_name(action.name)):
errors.append(
f"action event should start with action name. {event.name} does "
f"not start with {action.name}.",
)
if action.name not in charm_spec.actions:
if action.name not in (charm_spec.actions or ()):
errors.append(
f"action event {event.name} refers to action {action.name} "
f"which is not declared in the charm metadata (actions.yaml).",
Expand All @@ -223,6 +225,8 @@ def _check_storage_event(
warnings: List[str], # noqa: U100
):
storage = event.storage
meta = charm_spec.meta

if not storage:
errors.append(
"cannot construct a storage event without the Storage instance. "
Expand All @@ -233,7 +237,7 @@ def _check_storage_event(
f"storage event should start with storage name. {event.name} does "
f"not start with {storage.name}.",
)
elif storage.name not in charm_spec.meta["storage"]:
elif storage.name not in meta["storage"]:
errors.append(
f"storage event {event.name} refers to storage {storage.name} "
f"which is not declared in the charm metadata (metadata.yaml) under 'storage'.",
Expand All @@ -246,6 +250,10 @@ def _check_action_param_types(
errors: List[str],
warnings: List[str],
):
actions = charm_spec.actions
if not actions:
return

to_python_type = {
"string": str,
"boolean": bool,
Expand All @@ -255,7 +263,7 @@ def _check_action_param_types(
"object": dict,
}
expected_param_type = {}
for par_name, par_spec in charm_spec.actions[action.name].get("params", {}).items():
for par_name, par_spec in actions[action.name].get("params", {}).items():
value = par_spec.get("type")
if not value:
errors.append(
Expand Down Expand Up @@ -343,7 +351,7 @@ def check_config_consistency(
"integer": int, # fixme: which one is it?
"number": float,
"boolean": bool,
"attrs": NotImplemented, # fixme: wot?
# "attrs": NotImplemented, # fixme: wot?
}

expected_type_name = meta_config[key].get("type", None)
Expand All @@ -352,7 +360,12 @@ def check_config_consistency(
continue

expected_type = converters.get(expected_type_name)
if not isinstance(value, expected_type):
if not expected_type:
errors.append(
f"config invalid for option {key!r}: 'type' {expected_type_name} unknown",
)

elif not isinstance(value, expected_type):
errors.append(
f"config invalid; option {key!r} should be of type {expected_type} "
f"but is of type {type(value)}.",
Expand Down Expand Up @@ -394,11 +407,14 @@ def check_relation_consistency(
**_kwargs, # noqa: U101
) -> Results:
errors = []

meta = charm_spec.meta

nonpeer_relations_meta = chain(
charm_spec.meta.get("requires", {}).items(),
charm_spec.meta.get("provides", {}).items(),
meta.get("requires", {}).items(),
meta.get("provides", {}).items(),
)
peer_relations_meta = charm_spec.meta.get("peers", {}).items()
peer_relations_meta = meta.get("peers", {}).items()
all_relations_meta = list(chain(nonpeer_relations_meta, peer_relations_meta))

def _get_relations(r):
Expand Down Expand Up @@ -468,7 +484,8 @@ def check_containers_consistency(
"""Check the consistency of `state.containers` vs. `charm_spec.meta`."""

# event names will be normalized; need to compare against normalized container names.
meta_containers = list(map(normalize_name, charm_spec.meta.get("containers", {})))
meta = charm_spec.meta
meta_containers = list(map(normalize_name, meta.get("containers", {})))
state_containers = [normalize_name(c.name) for c in state.containers]
errors = []

Expand Down
Loading

0 comments on commit d9c8dd0

Please sign in to comment.