Repository navigation
Expand file tree
/
Copy pathtreefmt.nix
More file actions
35 lines (32 loc) · 1.43 KB
/
Copy pathtreefmt.nix
File metadata and controls
35 lines (32 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Formatter configuration shared by `nix fmt` and the `formatting` flake check.
#
# Every formatter here is pinned by flake.lock, which is the point: black's
# stable style changes between releases, so a floating `pip install black` in
# CI disagrees with whatever a contributor happens to have installed. Pinning
# makes formatting a single, reproducible answer.
_: let
# Paths black and isort must not touch. They are excluded per-formatter
# rather than globally because the treefmt in the pinned nixpkgs does not
# read the top-level `excludes` key that `settings.global` writes.
#
# Note that black and isort are configured to skip these in pyproject.toml
# too, but that only covers files they discover by walking a directory --
# treefmt hands them explicit paths, which bypasses those settings.
pythonExcludes = [
# Vendored verbatim from pyelftools; reformatting it would only make the
# next copybara import conflict.
"sqlelf/_vendor/**"
# Written by setuptools-scm at build time.
"sqlelf/_version.py"
];
in {
projectRootFile = "flake.nix";
programs.alejandra.enable = true;
programs.isort.enable = true;
programs.black.enable = true;
# isort rewrites the import block that black then wraps, so it runs first.
settings.formatter.isort.priority = 0;
settings.formatter.black.priority = 1;
settings.formatter.isort.excludes = pythonExcludes;
settings.formatter.black.excludes = pythonExcludes;
}