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