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

Add ruff gh action #244

Merged
merged 1 commit into from
Mar 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ VERSION ?= $(shell cat yamale/VERSION)

all: test

lint:
@ruff check --fix .
@ruff format .

test:
@tox

Expand All @@ -15,4 +19,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 lint tag coverage clean release install-hooks
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,11 @@ class TestYaml(YamaleTestCase):

Developers
----------
### Linting + Formatting
Yamale is formatted with [ruff](https://github.com/astral-sh/ruff). There is a github action enforcing
ruff formatting and linting rules. You can run this locally via `make lint` or by installing
the pre-commit hooks via `make install-hooks`

### Testing
Yamale uses [Tox](https://tox.readthedocs.org/en/latest/) to run its tests against multiple Python
versions. To run tests, first checkout Yamale, install Tox, then run `make test` in Yamale's root
Expand Down
3 changes: 3 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
line-length = 121
indent-width = 4

[lint]
ignore = ["F401", "F403"]
4 changes: 2 additions & 2 deletions yamale/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 5 additions & 20 deletions yamale/util.py
Original file line number Diff line number Diff line change
@@ -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, 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):
Expand Down
2 changes: 1 addition & 1 deletion yamale/yamale_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading