Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / python-modules / setuptools / default.nix
blob0e144c5b0090145a39b36066b8dfd2d0d5cd7151
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
15 let
16   pname = "setuptools";
17   version = "54.2.0";
19   bootstrap = fetchurl {
20     url = "https://raw.githubusercontent.com/pypa/setuptools/v52.0.0/bootstrap.py";
21     sha256 = "sha256-HzhlnJvMskBfb3kVnYltdnjS63wt1GWd0RK+VQqrJQ8=";
22   };
24   # Create an sdist of setuptools
25   sdist = stdenv.mkDerivation rec {
26     name = "${pname}-${version}-sdist.tar.gz";
28     src = fetchFromGitHub {
29       owner = "pypa";
30       repo = pname;
31       rev = "v${version}";
32       sha256 = "sha256-ZHJZiwlWLHP4vf2TLwj/DYB9wjbRp0apVmmjsKCLPq0=";
33       name = "${pname}-${version}-source";
34     };
36     patches = [
37       ./tag-date.patch
38     ];
40     buildPhase = ''
41       cp ${bootstrap} bootstrap.py
42       ${python.pythonForBuild.interpreter} bootstrap.py
43       ${python.pythonForBuild.interpreter} setup.py sdist --formats=gztar
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     '';
51     installPhase = ''
52       echo "Moving sdist..."
53       mv dist/${name} $out
54     '';
55   };
56 in 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";
63   src = sdist;
65   nativeBuildInputs = [
66     bootstrapped-pip
67     (pipInstallHook.override{pip=null;})
68     (setuptoolsBuildHook.override{setuptools=null; wheel=null;})
69   ];
71   preBuild = lib.strings.optionalString (!stdenv.hostPlatform.isWindows) ''
72     export SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES=0
73   '';
75   pipInstallFlags = [ "--ignore-installed" ];
77   # Adds setuptools to nativeBuildInputs causing infinite recursion.
78   catchConflicts = false;
80   # Requires pytest, causing infinite recursion.
81   doCheck = false;
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   };