Skip to content

Commit

Permalink
Add ruff check. Fix ruff issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
User committed Mar 19, 2024
1 parent 753d6ea commit 2ccbab8
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 177 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Code Quality
name: Linters

on: [push]
on: ["push", "pull_request"]

jobs:
build:
Expand All @@ -20,9 +20,9 @@ jobs:

- name: Install dependencies
run: |
pip install --upgrade -r requirements.txt
pip install --upgrade -e .
pip install -U -r requirements_dev.txt
pip install -U -e .
- name: Run tests
run: |
make pylint && make flake8 && make bandit
make ruff && make pylint
8 changes: 4 additions & 4 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Type Check
name: Types

on: [push]
on: ["push", "pull_request"]

jobs:
build:
Expand All @@ -20,8 +20,8 @@ jobs:

- name: Install dependencies
run: |
pip install --upgrade -r requirements.txt
pip install --upgrade -e .
pip install -U -r requirements_dev.txt
pip install -U -e .
- name: Run tests
run: |
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Tests

on: [push]
on: ["push", "pull_request"]

jobs:
build:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -20,9 +20,10 @@ jobs:

- name: Install dependencies
run: |
pip install --upgrade -r requirements.txt
pip install --upgrade -e .
pip install -U -r requirements_dev.txt
pip install -U -e .
- name: Run tests
run: |
pytest
make pytest
coverage lcov -o .coverage.lcov
31 changes: 18 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
.PHONY: bootstrap venv deps dirs clean test release mypy pylint flake8 bandit check build
.PHONY: init venv deps dirs clean pytest test release mypy pylint ruff check build

SHELL := /bin/bash
FILES_CHECK_MYPY = user_agent
FILES_CHECK_ALL = $(FILES_CHECK_MYPY) tests
COVERAGE_TARGET = user_agent

bootstrap: venv deps dirs
init: venv deps dirs

venv:
virtualenv -p python3 .env

deps:
.env/bin/pip install -r requirements.txt
.env/bin/pip install -r requirements_dev.txt
.env/bin/pip install -e .

dirs:
Expand All @@ -22,8 +23,11 @@ clean:
find -name '*.swp' -delete
find -name '__pycache__' -delete

test:
tox -e py3-test
pytest:
pytest -n30 -x --cov $(COVERAGE_TARGET) --cov-report term-missing

test: check pytest
tox -e check-minver

#release:
# git push \
Expand All @@ -32,20 +36,21 @@ test:
# && twine upload dist/*

mypy:
mypy --python-version=3.8 --strict $(FILES_CHECK_MYPY)
mypy --strict $(FILES_CHECK_MYPY)

pylint:
pylint -j0 $(FILES_CHECK_ALL)

flake8:
flake8 -j auto --max-cognitive-complexity=17 $(FILES_CHECK_ALL)
ruff:
ruff check $(FILES_CHECK_ALL)

coverage:
pytest -n30 -x --cov $(COVERAGE_TARGET) --cov-report term-missing

bandit:
bandit -qc pyproject.toml -r $(FILES_CHECK_ALL)
eradicate:
tox -e eradicate -- flake8 -j auto --eradicate-whitelist-extend="" $(FILES_CHECK_ALL)

check:
tox -e py38-check \
&& tox -e py3-check
check: ruff mypy pylint

build:
rm -rf *.egg-info
Expand Down
53 changes: 46 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ profile = "black"
line_length = 88
# skip_gitignore = true # throws errors in stderr when ".git" dir does not exist

[tool.bandit]
# B101 assert_used
# B410 Using HtmlElement to parse untrusted XML data
skips = ["B101", "B410"]

[tool.pylint.main]
jobs=4
extension-pkg-whitelist="lxml"
Expand All @@ -70,11 +65,9 @@ max-line-length=88
max-args=9
load-plugins=[
"pylint.extensions.check_elif",
"pylint.extensions.comparetozero",
"pylint.extensions.comparison_placement",
"pylint.extensions.consider_ternary_expression",
"pylint.extensions.docstyle",
"pylint.extensions.emptystring",
"pylint.extensions.for_any_all",
"pylint.extensions.overlapping_exceptions",
"pylint.extensions.redefined_loop_name",
Expand All @@ -85,3 +78,49 @@ load-plugins=[

[tool.pytest.ini_options]
testpaths = ["tests"]


[tool.ruff]
lint.select = ["ALL"]
lint.ignore = [
"A003", # Class attribute `type` is shadowing a python builtin
"ANN101", # Missing type annotation for `self` in method
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
"BLE001", # Do not catch blind exception: `Exception`
"COM812", # Trailing comma missing
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method1
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method,
"D107", # Missing docstring in `__init__`
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"EM101", # Check for raw usage of a string literal in Exception raising
"EM102", # Check for raw usage of an f-string literal in Exception raising
"EM103", # Check for raw usage of .format on a string literal in Exception raising
"F401", # Imported but unused
"FBT", # Boolean arg/value in function definition
"PTH", # A plugin finding use of functions that can be replaced by pathlib module
"S101", # Use of `assert` detected
"T201", # print found
"T203", # pprint found
"TCH", # Move import into a type-checking block
"TRY003", # Avoid specifying long messages outside the exception class
"UP032", # Use f-string instead of format call
"ERA001", # Found commented-out code
"RUF001", # String contains ambiguous unicode character
"ANN102", # Missing type annotation for `cls` in classmethod
"TD002", # Missing author in TODO
"TD003", # Missing issue link on the line following this TODO
"FIX002", # Line contains TODO
"RUF003", # Comment contains ambiguous
"RUF012", # Mutable class attributes should be annotated
"TRY400", # Use `logging.exception` instead of `logging.error`
"PERF401", # Use a list comprehension to create a transformed list
"RUF100", # [*] Unused `noqa` directive
]
lint.pylint.max-args=9
target-version = "py38"
extend-exclude = ["var"]
36 changes: 0 additions & 36 deletions requirements.txt

This file was deleted.

18 changes: 18 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sphinx
tox
test_server>=0.0.35
mock
bumpversion
pytest
build
twine
coverage
coveralls
pytest-cov
pytest-xdist
flake8
mccabe
mypy
pep8-naming
pylint
ruff
Loading

0 comments on commit 2ccbab8

Please sign in to comment.