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