Skip to content

Commit

Permalink
Add ruff Python linter
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Jul 17, 2023
1 parent 02eb9c4 commit d260c26
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
12 changes: 7 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@

devShells.default = pkgs.mkShell {
packages = [
pkgs.treefmt
pkgs.deadnix
pkgs.statix
pkgs.nixpkgs-fmt
pkgs.treefmt # Format all the things in one go
pkgs.deadnix # Check for dead Nix code
pkgs.statix # Static Nix analysis
pkgs.ruff # Python linter
pkgs.nixpkgs-fmt # Nix formatter
pythonEnv
pkgs.pdm
pkgs.pdm # Python PEP-621 compliant package manager
];

shellHook = ''
Expand Down Expand Up @@ -72,6 +73,7 @@
deadnix = "deadnix --fail";
statix = "statix check";
mypy = "mypy .";
ruff = "ruff check .";
};

});
Expand Down
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,26 @@ dev = [
"black>=23.7.0",
"mypy>=1.4.1",
]

[tool.black]
line-length = 120
target-version = ["py37", "py38", "py39", "py310"]

[tool.ruff]
line-length = 120
extend-select = [
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"PGH", # pygrep-hooks
"RUF", # ruff
"W", # pycodestyle
"YTT", # flake8-2020
]
extend-ignore = ["B018", "B019"]
src = ["src"]
exclude = ["tests/fixtures"]
target-version = "py37"

[tool.ruff.mccabe]
max-complexity = 10
21 changes: 10 additions & 11 deletions tests/test_nix.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import json
import subprocess
from typing import (
Iterator,
Optional,
Any,
Dict,
Iterator,
List,
cast,
Optional,
Set,
Any,
cast,
)
import subprocess

import pytest
import json


def assert_deepequals(
Expand Down Expand Up @@ -37,13 +38,13 @@ def assert_deepequals(
}, ignore_paths=set(["metadata.poetry-version"]))
"""

_path = cast(tuple[str], (_path if _path else tuple()))
_path = cast(tuple[str], (_path if _path else ()))
ignore_paths = ignore_paths if ignore_paths else set()
path = ".".join(_path)
err = ValueError("{}: {} != {}".format(path, a, b))

def make_path(entry):
return _path + (str(entry),)
return (*_path, str(entry))

if isinstance(a, list):
if not isinstance(b, list) or len(a) != len(b):
Expand Down Expand Up @@ -82,9 +83,7 @@ def nix_eval(attr: str) -> Dict:
"-A",
attr,
]
proc = subprocess.run(
cmd, stdout=subprocess.PIPE, check=True, stderr=subprocess.PIPE
)
proc = subprocess.run(cmd, stdout=subprocess.PIPE, check=True, stderr=subprocess.PIPE)
return json.loads(proc.stdout)


Expand Down

0 comments on commit d260c26

Please sign in to comment.