summary refs log tree commit diff
path: root/pkgs/development/python-modules/black/default.nix
blob: 6f4e05767bb7c750939abd283840831c3906785e (plain) (blame)
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
{ stdenv, lib
, buildPythonPackage, fetchPypi, pythonOlder, setuptools-scm, pytestCheckHook
, aiohttp
, aiohttp-cors
, appdirs
, attrs
, click
, colorama
, dataclasses
, mypy-extensions
, pathspec
, parameterized
, regex
, toml
, typed-ast
, typing-extensions
, uvloop
}:


buildPythonPackage rec {
  pname = "black";
  version = "21.6b0";

  disabled = pythonOlder "3.6";

  src = fetchPypi {
    inherit pname version;
    sha256 = "016f6bhnnnbcrrh3cvmpk77ww0nykv5n1qvgf8b3044dm14264yw";
  };

  nativeBuildInputs = [ setuptools-scm ];

  # 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;

  checkInputs = [ pytestCheckHook parameterized ];

  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.isDarwin ''
    # Work around https://github.com/psf/black/issues/2105
    export TMPDIR="/tmp"
  '';

  disabledTests = [
    # requires network access
    "test_gen_check_output"
  ] ++ lib.optionals stdenv.isDarwin [
    # fails on darwin
    "test_expression_diff"
  ];

  propagatedBuildInputs = [
    aiohttp
    aiohttp-cors
    appdirs
    attrs
    click
    colorama
    mypy-extensions
    pathspec
    regex
    toml
    typed-ast # required for tests and python2 extra
    uvloop
  ] ++ lib.optional (pythonOlder "3.7") dataclasses
    ++ lib.optional (pythonOlder "3.8") typing-extensions;

  meta = with lib; {
    description = "The uncompromising Python code formatter";
    homepage = "https://github.com/psf/black";
    changelog = "https://github.com/psf/black/blob/${version}/CHANGES.md";
    license = licenses.mit;
    maintainers = with maintainers; [ sveitser ];
  };
}