1{ stdenv
2, lib
3, buildPythonPackage
4, fetchPypi
5, pythonOlder
6, pytestCheckHook
7, aiohttp
8, aiohttp-cors
9, click
10, colorama
11, hatch-fancy-pypi-readme
12, hatch-vcs
13, hatchling
14, mypy-extensions
15, pathspec
16, parameterized
17, platformdirs
18, tomli
19, typed-ast
20, typing-extensions
21, uvloop
22}:
23
24buildPythonPackage rec {
25 pname = "black";
26 version = "22.10.0";
27 format = "pyproject";
28
29 disabled = pythonOlder "3.7";
30
31 src = fetchPypi {
32 inherit pname version;
33 hash = "sha256-9RNYjaWZlD4M3k4yzJh56CXVhyDWVXBi0QmMWtgAgOE=";
34 };
35
36 nativeBuildInputs = [
37 hatch-fancy-pypi-readme
38 hatch-vcs
39 hatchling
40 ];
41
42 # Necessary for the tests to pass on Darwin with sandbox enabled.
43 # Black starts a local server and needs to bind a local address.
44 __darwinAllowLocalNetworking = true;
45
46 checkInputs = [ pytestCheckHook parameterized aiohttp ];
47
48 preCheck = ''
49 export PATH="$PATH:$out/bin"
50
51 # The top directory /build matches black's DEFAULT_EXCLUDE regex.
52 # Make /build the project root for black tests to avoid excluding files.
53 touch ../.git
54 '' + lib.optionalString stdenv.isDarwin ''
55 # Work around https://github.com/psf/black/issues/2105
56 export TMPDIR="/tmp"
57 '';
58
59 disabledTests = [
60 # requires network access
61 "test_gen_check_output"
62 ] ++ lib.optionals stdenv.isDarwin [
63 # fails on darwin
64 "test_expression_diff"
65 # Fail on Hydra, see https://github.com/NixOS/nixpkgs/pull/130785
66 "test_bpo_2142_workaround"
67 "test_skip_magic_trailing_comma"
68 ];
69 # multiple tests exceed max open files on hydra builders
70 doCheck = !(stdenv.isLinux && stdenv.isAarch64);
71
72 propagatedBuildInputs = [
73 click
74 mypy-extensions
75 pathspec
76 platformdirs
77 tomli
78 ] ++ lib.optional (pythonOlder "3.8") typed-ast
79 ++ lib.optional (pythonOlder "3.10") typing-extensions;
80
81 passthru.optional-dependencies = {
82 d = [ aiohttp aiohttp-cors ];
83 colorama = [ colorama ];
84 uvloop = [ uvloop ];
85 };
86
87 meta = with lib; {
88 description = "The uncompromising Python code formatter";
89 homepage = "https://github.com/psf/black";
90 changelog = "https://github.com/psf/black/blob/${version}/CHANGES.md";
91 license = licenses.mit;
92 maintainers = with maintainers; [ sveitser autophagy ];
93 };
94}