From 94db039602b90f75524fa22a00092d01a22c8385 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Mon, 12 Feb 2024 23:59:27 -0500 Subject: [PATCH] Add ruff pre-commit check for Python code --- .pre-commit-config.yaml | 6 ++++++ vault_config/loader.py | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61c3b8f..3efbc2a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,6 +25,12 @@ repos: types: [file, yaml] entry: yamllint --strict + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.2.1 + hooks: + - id: ruff + - id: ruff-format + - repo: local hooks: - id: jsonnetfmt diff --git a/vault_config/loader.py b/vault_config/loader.py index 0f8110f..848cfbc 100644 --- a/vault_config/loader.py +++ b/vault_config/loader.py @@ -8,7 +8,6 @@ from pathlib import Path from fnmatch import fnmatch -from contextlib import contextmanager from .exceptions import InvalidFileTypeError @@ -16,7 +15,7 @@ class Loader: - '''Load serialized data into a local cache.''' + """Load serialized data into a local cache.""" def __init__(self, import_directories=None): self.import_directories = import_directories or [] @@ -32,7 +31,7 @@ def __exit__(self, *args): self.tmpdir = None def import_callback(self, parent, path): - '''Resolve jsonnet imports''' + """Resolve jsonnet imports""" LOG.debug("jsonnet import %s", path) for importdir in [parent] + self.import_directories: @@ -75,13 +74,13 @@ def load_jsonnet_file(self, path): return json.loads(content) def load(self, path): - '''Load a document into our local cache. + """Load a document into our local cache. This function unmarshals the given path into a Python data structure, and then writes it out as a JSON file in self.tmpdir. This pre-processing ensures that the files are syntactically correct and that any dependencies can be successfully resolved. - ''' + """ LOG.debug("loading %s", path) if fnmatch(path, "*.j2.yaml"):