From 0251e7a3a5d1f0346cd6118a390e2fb7779428bb Mon Sep 17 00:00:00 2001 From: Cordell Blakkan Date: Wed, 20 Mar 2024 13:58:13 -0400 Subject: [PATCH] Add ruff gh action --- .github/workflows/run-tests.yml | 1 + .pre-commit-config.yaml | 7 +++++++ Makefile | 5 ++++- ruff.toml | 3 +++ yamale/schema/schema.py | 4 ++-- yamale/util.py | 25 +++++-------------------- yamale/yamale_testcase.py | 2 +- 7 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c18b85c..b6b45f8 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -18,6 +18,7 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: chartboost/ruff-action@v1 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8a1b580 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.3 + hooks: + - id: ruff + args: ["--fix"] + - id: ruff-format diff --git a/Makefile b/Makefile index 49b2c9a..1e72c60 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,7 @@ release: @git push --follow-tags --all @git push --tags -.PHONY: test tag coverage clean release +install-hooks: + @pre-commit install -f --install-hooks -t pre-commit + +.PHONY: test tag coverage clean release install-hooks diff --git a/ruff.toml b/ruff.toml index 46e6544..3e35689 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,2 +1,5 @@ line-length = 121 indent-width = 4 + +[lint] +ignore = ["F401", "F403"] diff --git a/yamale/schema/schema.py b/yamale/schema/schema.py index fe0972c..2b8af90 100644 --- a/yamale/schema/schema.py +++ b/yamale/schema/schema.py @@ -172,8 +172,8 @@ def _validate_any(self, validator, data, path, strict): def _validate_subset(self, validator, data, path, strict): def _internal_validate(internal_data): sub_errors = [] - for val in validator.validators: - err = self._validate(val, internal_data, path, strict) + for v in validator.validators: + err = self._validate(v, internal_data, path, strict) if not err: break sub_errors += err diff --git a/yamale/util.py b/yamale/util.py index 45c4ab3..d37ebf9 100644 --- a/yamale/util.py +++ b/yamale/util.py @@ -1,27 +1,12 @@ -# ABCs for containers were moved to their own module -try: - from collections.abc import Mapping, Set, Sequence -except ImportError: - from collections import Mapping, Set, Sequence +from collections.abc import Mapping, Set, Sequence -# Python 3 has no basestring, lets test it. -try: - basestring # attempt to evaluate basestring +def isstr(s): + return isinstance(s, str) - def isstr(s): - return isinstance(s, basestring) - def to_unicode(s): - return unicode(s) - -except NameError: - - def isstr(s): - return isinstance(s, str) - - def to_unicode(s): - return s +def to_unicode(s): + return s def is_list(obj): diff --git a/yamale/yamale_testcase.py b/yamale/yamale_testcase.py index 21ba6d7..49caea0 100644 --- a/yamale/yamale_testcase.py +++ b/yamale/yamale_testcase.py @@ -26,7 +26,7 @@ def validate(self, validators=None): if schema is None: return - if type(yaml) != list: + if not isinstance(yaml, list): yaml = [yaml] if base_dir is not None: