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