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