Skip to content

Commit

Permalink
✨ Add extensible python linter configs
Browse files Browse the repository at this point in the history
You can now override the configuration for linters project wide.
  • Loading branch information
sakarias88 committed Feb 14, 2024
1 parent b11adb3 commit 891439a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Support for overriding python linters config.

### Changed
- Ruff default configuration. Now picks upp issues similar to to the
alternative (isort, black, flake etc).
Expand Down
6 changes: 5 additions & 1 deletion python/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
, python
, pythonVersions ? { }
, defaultCheckPhase ? "standardTests"
, linterConfigs ? { }
}:
let
pythons = pythonVersions // { inherit python; };
defaultPythonName = "python";

hooks = callPackage ./hooks { inherit defaultCheckPhase; };
hooks = callPackage ./hooks {
inherit defaultCheckPhase;
configs = linterConfigs;
};

mkPackage = callPackage ./package.nix { inherit base; checkHook = hooks.check; };

Expand Down
35 changes: 29 additions & 6 deletions python/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, findutils
, lib
, defaultCheckPhase
, configs
, ruff
}:
let
Expand Down Expand Up @@ -82,6 +83,9 @@ let
files = [
"pyproject.toml"
{ path = "setup.cfg"; key = "black"; }
] ++
(lib.optional (configs ? black) configs.black)
++ [
./config/black.toml
];
};
Expand All @@ -104,6 +108,9 @@ let
{ path = "pyproject.toml"; key = "tool.ruff"; }
"ruff.toml"
".ruff.toml"
] ++
(lib.optional (configs ? ruff) configs.ruff)
++ [
{ path = ./config/ruff.toml; key = "tool.ruff"; }
];
};
Expand All @@ -118,6 +125,9 @@ let
{ path = "setup.cfg"; key = "tool:coverage"; }
{ path = "tox.ini"; key = "tool:coverage"; }
"pyproject.toml"
] ++
(lib.optional (configs ? coverage) configs.coverage)
++ [
./config/coverage.toml
];
};
Expand All @@ -130,6 +140,9 @@ let
".flake8"
"setup.cfg"
"tox.ini"
] ++
(lib.optional (configs ? flake8) configs.flake8)
++ [
{ path = ./config/flake8.toml; key = "tool.pycodestyle"; }
{ path = ./config/flake8.toml; key = "tool.flake8"; }
];
Expand All @@ -147,6 +160,9 @@ let
"setup.cfg"
"tox.ini"
".editorconfig"
] ++
(lib.optional (configs ? isort) configs.isort)
++ [
{ path = ./config/isort.toml; key = "tool.isort"; }
];
};
Expand All @@ -162,6 +178,9 @@ let
{ path = "pyproject.toml"; key = "tool.mypy.overrides"; }
{ path = "pyproject.toml"; key = "tool.mypy"; removeField = "tool.mypy.overrides"; }
"setup.cfg"
] ++
(lib.optional (configs ? mypy) configs.mypy)
++ [
{ path = ./config/mypy.toml; key = "tool.mypy"; }
];
};
Expand All @@ -175,12 +194,13 @@ let
{ path = "pylintrc"; key = ""; }
{ path = ".pylintrc"; key = ""; }
"pyproject.toml"
(
if lib.versionAtLeast toolDerivation.version "2.14" then
./config/pylint2_14.toml
else
./config/pylint.toml
)
] ++
(lib.optional (configs ? pylint) configs.pylint)
++ [
(if lib.versionAtLeast toolDerivation.version "2.14" then
./config/pylint2_14.toml
else
./config/pylint.toml)
];
};

Expand All @@ -195,6 +215,9 @@ let
{ path = "pylintrc.toml"; key = "tool.pytest.ini_options"; }
"tox.ini"
{ path = "setup.cfg"; key = "tool:pytest"; }
] ++
(lib.optional (configs ? pytest) configs.pytest)
++ [
{ path = ./config/pytest.toml; key = "tool.pytest.ini_options"; }
];
extraArgs = "--rootdir=./";
Expand Down

0 comments on commit 891439a

Please sign in to comment.