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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
{
stdenv,
lib,
buildPythonPackage,
fetchPypi,
fetchpatch,
pythonOlder,
pytestCheckHook,
aiohttp,
click,
colorama,
hatch-fancy-pypi-readme,
hatch-vcs,
hatchling,
ipython,
mypy-extensions,
packaging,
pathspec,
parameterized,
platformdirs,
tokenize-rt,
tomli,
typing-extensions,
uvloop,
}:
buildPythonPackage rec {
pname = "black";
version = "25.1.0";
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-M0ltXNEiKtczkTUrSujaFSU8Xeibk6gLPiyNmhnsJmY=";
};
patches = [
(fetchpatch {
name = "click-8.2-compat-1.patch";
url = "https://github.com/psf/black/commit/14e1de805a5d66744a08742cad32d1660bf7617a.patch";
hash = "sha256-fHRlMetE6+09MKkuFNQQr39nIKeNrqwQuBNqfIlP4hc=";
})
(fetchpatch {
name = "click-8.2-compat-2.patch";
url = "https://github.com/psf/black/commit/ed64d89faa7c738c4ba0006710f7e387174478af.patch";
hash = "sha256-df/J6wiRqtnHk3mAY3ETiRR2G4hWY1rmZMfm2rjP2ZQ=";
})
(fetchpatch {
name = "click-8.2-compat-3.patch";
url = "https://github.com/psf/black/commit/b0f36f5b4233ef4cf613daca0adc3896d5424159.patch";
hash = "sha256-SGLCxbgrWnAi79IjQOb2H8mD/JDbr2SGfnKyzQsJrOA=";
})
];
nativeBuildInputs = [
hatch-fancy-pypi-readme
hatch-vcs
hatchling
];
propagatedBuildInputs = [
click
mypy-extensions
packaging
pathspec
platformdirs
]
++ lib.optionals (pythonOlder "3.11") [
tomli
typing-extensions
];
optional-dependencies = {
colorama = [ colorama ];
d = [ aiohttp ];
uvloop = [ uvloop ];
jupyter = [
ipython
tokenize-rt
];
};
# Necessary for the tests to pass on Darwin with sandbox enabled.
# Black starts a local server and needs to bind a local address.
__darwinAllowLocalNetworking = true;
nativeCheckInputs = [
pytestCheckHook
parameterized
]
++ lib.concatAttrValues optional-dependencies;
pytestFlags = [
"-Wignore::DeprecationWarning"
];
preCheck = ''
export PATH="$PATH:$out/bin"
# The top directory /build matches black's DEFAULT_EXCLUDE regex.
# Make /build the project root for black tests to avoid excluding files.
touch ../.git
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
# Work around https://github.com/psf/black/issues/2105
export TMPDIR="/tmp"
'';
disabledTests = [
# requires network access
"test_gen_check_output"
# broken on Python 3.13.4
# FIXME: remove this when fixed upstream
"test_simple_format[pep_701]"
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# fails on darwin
"test_expression_diff"
# Fail on Hydra, see https://github.com/NixOS/nixpkgs/pull/130785
"test_bpo_2142_workaround"
"test_skip_magic_trailing_comma"
];
# multiple tests exceed max open files on hydra builders
doCheck = !(stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64);
meta = {
description = "Uncompromising Python code formatter";
homepage = "https://github.com/psf/black";
changelog = "https://github.com/psf/black/blob/${version}/CHANGES.md";
license = lib.licenses.mit;
mainProgram = "black";
maintainers = with lib.maintainers; [
sveitser
autophagy
];
};
}
|