1{
2 stdenv,
3 buildPythonPackage,
4 fetchFromGitHub,
5 python,
6 bootstrapped-pip,
7 lib,
8 pipInstallHook,
9 setuptoolsBuildHook,
10}:
11
12let
13 pname = "setuptools";
14 version = "44.0.0";
15
16 # Create an sdist of setuptools
17 sdist = stdenv.mkDerivation rec {
18 name = "${pname}-${version}-sdist.tar.gz";
19
20 src = fetchFromGitHub {
21 owner = "pypa";
22 repo = pname;
23 rev = "v${version}";
24 sha256 = "0z3q0qinyp1rmnxkw3y5f6nbsxhqlfq5k7skfrqa6ymb3zr009y1";
25 name = "${pname}-${version}-source";
26 };
27
28 patches = [
29 ./tag-date.patch
30 ];
31
32 buildPhase = ''
33 ${python.pythonOnBuildForHost.interpreter} bootstrap.py
34 ${python.pythonOnBuildForHost.interpreter} setup.py sdist --formats=gztar
35
36 # Here we untar the sdist and retar it in order to control the timestamps
37 # of all the files included
38 tar -xzf dist/${pname}-${version}.post0.tar.gz -C dist/
39 tar -czf dist/${name} -C dist/ --mtime="@$SOURCE_DATE_EPOCH" ${pname}-${version}.post0
40 '';
41
42 installPhase = ''
43 echo "Moving sdist..."
44 mv dist/${name} $out
45 '';
46 };
47in
48buildPythonPackage {
49 inherit pname version;
50 # Because of bootstrapping we don't use the setuptoolsBuildHook that comes with format="setuptools" directly.
51 # Instead, we override it to remove setuptools to avoid a circular dependency.
52 # The same is done for pip and the pipInstallHook.
53 format = "other";
54
55 src = sdist;
56
57 nativeBuildInputs = [
58 bootstrapped-pip
59 (pipInstallHook.override { pip = null; })
60 (setuptoolsBuildHook.override {
61 setuptools = null;
62 wheel = null;
63 })
64 ];
65
66 preBuild = lib.optionalString (!stdenv.hostPlatform.isWindows) ''
67 export SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES=0
68 '';
69
70 pipInstallFlags = [ "--ignore-installed" ];
71
72 # Adds setuptools to nativeBuildInputs causing infinite recursion.
73 catchConflicts = false;
74
75 # Requires pytest, causing infinite recursion.
76 doCheck = false;
77
78 meta = with lib; {
79 description = "Utilities to facilitate the installation of Python packages";
80 homepage = "https://pypi.python.org/pypi/setuptools";
81 license = with licenses; [
82 psfl
83 zpl20
84 ];
85 platforms = python.meta.platforms;
86 priority = 10;
87 };
88}