Skip to content

Commit

Permalink
Update all minor versions (minor) (#309)
Browse files Browse the repository at this point in the history
* Update all minor versions

* Add Ruff, fix Checks

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Stéphane Brunner <stephane.brunner@camptocamp.com>
  • Loading branch information
renovate[bot] and sbrunner authored Dec 2, 2024
1 parent 73361b2 commit 5b596b7
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 63 deletions.
23 changes: 6 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,24 @@ repos:
rev: v0.1.8
hooks:
- id: ripsecrets
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
hooks:
- id: pyupgrade
- id: ruff-format
args:
- --py39-plus
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- --line-length=110
- repo: https://github.com/PyCQA/prospector
rev: v1.13.3
hooks:
- id: prospector
args:
- --tool=pydocstyle
- --tool=ruff
- --die-on-tool-error
- --output-format=pylint
additional_dependencies:
- prospector-profile-duplicated==1.8.0 # pypi
- prospector-profile-utils==1.12.2 # pypi
- ruff==0.8.1 # pypi
- repo: https://github.com/sbrunner/jsonschema-validator
rev: 0.3.2
hooks:
Expand Down
8 changes: 8 additions & 0 deletions .prospector.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
inherits:
- duplicated
- utils:base
- utils:fix
- utils:no-design-checks
- utils:unsafe

pycodestyle:
disable:
- E704 # multiple statements on one line (def) (not compatible with protocol)

ruff:
disable:
- D101 # Missing docstring in public class
- D102 # Missing docstring in public method
- D103 # Missing docstring in public function
45 changes: 21 additions & 24 deletions c2c/template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from typing import Any, Callable, Optional, Protocol, Union, cast

import yaml
import yaml_include # type: ignore
import yaml_include
from yaml.parser import ParserError

Value = Union[str, int, float, dict[str, Any], list[Any]]
Expand Down Expand Up @@ -80,7 +80,7 @@ def transform_path(
"The key '%s' in '%s' is not present in: [%s]",
key,
current_path,
", ".join([f"'{k}'" for k in value.keys()]),
", ".join([f"'{k}'" for k in value]),
)
else:
if len(path) == 1:
Expand Down Expand Up @@ -190,10 +190,7 @@ def __init__(
self.all_environment_dict[env["name"]] = os.environ[env["name"]]

def path_in(self, path_list: list[str], list_: list[str]) -> bool:
for path in path_list:
if path in list_:
return True
return False
return any(path in list_ for path in path_list)

def format_walker(
self, current_vars: dict[str, Any], path: Optional[str] = None, path_list: Optional[list[str]] = None
Expand Down Expand Up @@ -231,7 +228,7 @@ def format_walker(

elif isinstance(current_vars, dict):
skip = []
for key in current_vars.keys():
for key in current_vars:
if path is None:
current_path = key
current_path_list = [key]
Expand Down Expand Up @@ -392,12 +389,16 @@ def set_path(item: tuple[dict[str, Any], str], value: str) -> None:

def _proceed(files: list[tuple[str, str]], used_vars: dict[str, Any], options: Namespace) -> None:
if options.engine == "jinja":
from bottle import jinja2_template as engine # type: ignore # pylint: disable=import-outside-toplevel
from bottle import ( # pylint: disable=import-outside-toplevel
jinja2_template as engine,
)

bottle_template(files, used_vars, engine)

elif options.engine == "mako":
from bottle import mako_template as engine # pylint: disable=import-outside-toplevel
from bottle import ( # pylint: disable=import-outside-toplevel
mako_template as engine,
)

bottle_template(files, used_vars, engine)

Expand Down Expand Up @@ -553,7 +554,7 @@ def do_process(used: dict[str, Any], new_vars: dict[str, Any]) -> dict[str, Any]
}
interpreters.append(interpreter)

interpreters.sort(key=lambda v: -v["priority"]) # type: ignore
interpreters.sort(key=lambda v: -v["priority"])

class CmdAction:
def __init__(self, interpreter: dict[str, Any]):
Expand Down Expand Up @@ -584,13 +585,11 @@ class PythonAction:
def __init__(self, interpreter: dict[str, Any]):
self.interpreter = interpreter

def __call__(self, expression: str, current_path: str) -> Value: # type: ignore
def __call__(self, expression: str, current_path: str) -> Value:
try:
return cast(Value, eval(expression, globs)) # nosec # pylint: disable=eval-used
return cast(Value, eval(expression, globs)) # nosec # pylint: disable=eval-used # noqa: S307
except Exception: # pragma: nocover # pylint: disable=broad-except
error = "When evaluating {} expression '{}' in '{}' as Python:\n{}".format(
var_name, expression, current_path, traceback.format_exc()
)
error = f"When evaluating {var_name} expression '{expression}' in '{current_path}' as Python:\n{traceback.format_exc()}"
LOG.error(error)
if interpreter.get("ignore_error", False):
return "ERROR: " + error
Expand Down Expand Up @@ -622,8 +621,8 @@ def __call__(self, value: str, current_path: str) -> Value:
try:
return cast(dict[str, Any], json.loads(value))
except ValueError as exception: # pragma: nocover
error = "When evaluating {} expression '{}' in '{}' as JSON: {}".format(
key, value, current_path, exception
error = (
f"When evaluating {key} expression '{value}' in '{current_path}' as JSON: {exception}"
)
LOG.error(error)
if interpreter.get("ignore_error", False):
Expand All @@ -639,8 +638,8 @@ def __call__(self, value: str, current_path: str) -> Value:
try:
return cast(dict[str, Any], yaml.safe_load(value))
except ParserError as exception: # pragma: nocover
error = "When evaluating {} expression '{}' in '{}' as YAML: {}".format(
key, value, current_path, exception
error = (
f"When evaluating {key} expression '{value}' in '{current_path}' as YAML: {exception}"
)
LOG.error(error)
if self.interpreter.get("ignore_error", False):
Expand Down Expand Up @@ -674,15 +673,13 @@ class PostprocessAction:
def __init__(self, postprocess: dict[str, Any]) -> None:
self.postprocess = postprocess

def __call__(self, value: str, current_path: str) -> Value: # type: ignore
def __call__(self, value: str, current_path: str) -> Value:
expression = self.postprocess["expression"] # [:] to clone
expression = expression.format(repr(value))
try:
return cast(Value, eval(expression, globs)) # nosec # pylint: disable=eval-used
return cast(Value, eval(expression, globs)) # nosec # pylint: disable=eval-used # noqa: S307
except ValueError as exception: # pragma: nocover
error = "When interpreting the expression '{}' in '{}': {}".format(
expression, current_path, exception
)
error = f"When interpreting the expression '{expression}' in '{current_path}': {exception}"
LOG.error(error)
if ignore_error:
return "ERROR: " + error
Expand Down
67 changes: 49 additions & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ bottle = "0.13.2"
Jinja2 = "3.1.4"
Mako = "1.3.6"
PyYAML = "6.0.2"
pyyaml-include = "2.1"
pyyaml-include = "2.2"

[tool.poetry.group.dev.dependencies]
prospector = { version = "1.12.1", extras = ["with_bandit", "with_mypy", "with_pyroma"] }
prospector-profile-duplicated = "1.6.0"
prospector-profile-utils = "1.9.1"
prospector = { version = "1.13.3", extras = ["with_bandit", "with_mypy", "with_pyroma", "with_ruff"] }
prospector-profile-duplicated = "1.8.0"
prospector-profile-utils = "1.13.0"
pytest = "8.3.4"
types-PyYAML = "6.0.12.20240917"

Expand Down

0 comments on commit 5b596b7

Please sign in to comment.