Skip to content

Commit

Permalink
Use ruff for linting and formatting (#99)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 23.12.1 → 24.1.1](psf/black@23.12.1...24.1.1)
- [github.com/PyCQA/bandit: 1.7.6 → 1.7.7](PyCQA/bandit@1.7.6...1.7.7)
- [github.com/crate-ci/typos: v1.17.1 → v1.17.2](crate-ci/typos@v1.17.1...v1.17.2)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Use ruff

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Felix Uellendall <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and feluelle authored Jan 30, 2024
1 parent 4551604 commit 3d8a651
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 64 deletions.
4 changes: 0 additions & 4 deletions .bandit

This file was deleted.

66 changes: 9 additions & 57 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,66 +24,18 @@ repos:
- id: mypy
additional_dependencies:
- types-toml
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: ["--max-line-length", "88", "--extend-ignore", "E501"]
additional_dependencies:
- flake8-bugbear
- flake8-builtins
- repo: https://github.com/PyCQA/bandit
rev: 1.7.6
hooks:
- id: bandit
args: ["-c", ".bandit"]
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
args: ["--convention", "pep257", "--add-ignore", "D100,D102"]
additional_dependencies:
- toml
exclude: airflint/__main__.py|tests/
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.15
hooks:
- id: ruff
args:
- --fix
- --unsafe-fixes
- id: ruff-format
- repo: https://github.com/crate-ci/typos
rev: v1.17.1
rev: v1.17.2
hooks:
- id: typos
- repo: https://github.com/pycqa/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args: ["--remove-all-unused-imports", "--in-place"]
- repo: local
hooks:
- id: pytest
Expand Down
1 change: 1 addition & 0 deletions airflint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Top-level package for airflint."""

from importlib.metadata import version
from os import getcwd
from os.path import dirname, join, realpath
Expand Down
8 changes: 5 additions & 3 deletions airflint/rules/use_jinja_variable_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ def _lookup_template_fields(self, keyword: ast.keyword) -> None:
and scope.can_reach(self.context["scope"].resolve(node))
)
except StopIteration:
raise AssertionError("Could not find import definition. Skipping..")
raise AssertionError(
"Could not find import definition. Skipping.."
) from None
assert (module_name := import_node.module)

# Try to import the module into python.
try:
_module = import_module(module_name)
except ImportError:
raise AssertionError("Could not import module. Skipping..")
except ImportError as e:
raise AssertionError("Could not import module. Skipping..") from e
assert (file_path := _module.__file__)

# Parse the ast to check if the keyword is in template_fields.
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ build-backend = "poetry.core.masonry.api"

[tool.coverage.run]
omit = ["airflint/__main__.py"]

[tool.ruff]
target-version = "py39"

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "B", "S", "UP", "PGH", "D", "I", "A"]
ignore = ["D100", "D102"]

[tool.ruff.per-file-ignores]
"tests/*" = ["S101", "D"]
"airflint/rules/*.py" = ["S101"]
"airflint/__main__.py" = ["D"]

[tool.ruff.pydocstyle]
convention = "pep257"

0 comments on commit 3d8a651

Please sign in to comment.