about summary refs log tree commit diff
path: root/pkgs/development/tools/pipenv/default.nix
blob: dd65dbe34221f73b8997565eda209c242ce16f06 (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
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
{ lib
, stdenv
, python3
, fetchFromGitHub
, installShellFiles
, pipenv
, runCommand
}:

with python3.pkgs;

let

  runtimeDeps = ps: with ps; [
    certifi
    setuptools
    pip
    virtualenv
    virtualenv-clone
  ]
  ++ lib.optionals stdenv.hostPlatform.isAndroid [
    pyjnius
  ];

  pythonEnv = python3.withPackages runtimeDeps;

in buildPythonApplication rec {
  pname = "pipenv";
  version = "2024.0.1";
  format = "pyproject";

  src = fetchFromGitHub {
    owner = "pypa";
    repo = "pipenv";
    rev = "refs/tags/v${version}";
    hash = "sha256-IyjJrIEcKHm7TpZk26MYI///ZIB/7ploTBzvms1gDmI=";
  };

  env.LC_ALL = "en_US.UTF-8";

  nativeBuildInputs = [
    installShellFiles
    setuptools
    wheel
  ];

  postPatch = ''
    # pipenv invokes python in a subprocess to create a virtualenv
    # and to call setup.py.
    # It would use sys.executable, which in our case points to a python that
    # does not have the required dependencies.
    substituteInPlace pipenv/utils/virtualenv.py \
      --replace "sys.executable" "'${pythonEnv.interpreter}'"
  '';

  propagatedBuildInputs = runtimeDeps python3.pkgs;

  preCheck = ''
    export HOME="$TMPDIR"
  '';

  nativeCheckInputs = [
    mock
    pytestCheckHook
    pytest-xdist
    pytz
    requests
  ];

  disabledTests = [
    # this test wants access to the internet
    "test_download_file"
  ];

  disabledTestPaths = [
    # many of these tests want access to the internet
    "tests/integration"
  ];

  passthru.tests = {
    verify-venv-patch = runCommand "${pname}-test-verify-venv-patch" {} ''
      export PIPENV_VENV_IN_PROJECT=1

      # "pipenv install" should be able to create a venv
      ${pipenv}/bin/pipenv install

       # the venv exists
      [ -d .venv ]

      touch $out
    '';
  };

  postInstall = ''
    installShellCompletion --cmd pipenv \
      --bash <(_PIPENV_COMPLETE=bash_source $out/bin/pipenv) \
      --zsh <(_PIPENV_COMPLETE=zsh_source $out/bin/pipenv) \
      --fish <(_PIPENV_COMPLETE=fish_source $out/bin/pipenv)
  '';

  meta = with lib; {
    description = "Python Development Workflow for Humans";
    license = licenses.mit;
    platforms = platforms.all;
    maintainers = with maintainers; [ berdario ];
  };
}