From eee740aff9e4ec06e971056b84275e0a70c11b6b Mon Sep 17 00:00:00 2001 From: Some One Date: Wed, 13 Aug 2025 21:09:49 +0200 Subject: [PATCH] --- pip-install-hook.nix => pip-install-hook.sh | 6 +- python-overrides.nix | 4 + python26/wheel.nix | 8 +- result | 2 +- setuptools.nix | 99 +++++++++++++++------ 5 files changed, 84 insertions(+), 35 deletions(-) rename pip-install-hook.nix => pip-install-hook.sh (81%) diff --git a/pip-install-hook.nix b/pip-install-hook.sh similarity index 81% rename from pip-install-hook.nix rename to pip-install-hook.sh index f6546fd..d2b2ea8 100644 --- a/pip-install-hook.nix +++ b/pip-install-hook.sh @@ -13,18 +13,14 @@ pipInstallPhase() { local -a flagsArray=( --no-index - --no-warn-script-location --prefix="$out" --no-cache ) concatTo flagsArray pipInstallFlags - echo "Lolol" - pushd dist || return 1 echoCmd 'pip install flags' "${flagsArray[@]}" - # @pythonInterpreter@ -m pip install ./*.whl "${flagsArray[@]}" - @pip@ install ./*.whl "${flagsArray[@]}" + pip install ./*.whl "${flagsArray[@]}" popd || return 1 runHook postInstall diff --git a/python-overrides.nix b/python-overrides.nix index e6d854e..5d33e5b 100644 --- a/python-overrides.nix +++ b/python-overrides.nix @@ -5,6 +5,10 @@ let in with self; with super; +let + pythonInterpreter = python.pythonOnBuildForHost.interpreter; + pythonSitePackages = python.sitePackages; +in rec { bootstrapped-pip = toPythonModule (callPackage ./python26/bootstrapped-pip.nix {}); diff --git a/python26/wheel.nix b/python26/wheel.nix index 2418503..5b5340b 100644 --- a/python26/wheel.nix +++ b/python26/wheel.nix @@ -10,7 +10,7 @@ buildPythonPackage rec { pname = "wheel"; version = "0.29.0"; - format = "setuptools"; + format = "other"; #src = fetchPypi { # inherit pname version; @@ -25,16 +25,16 @@ buildPythonPackage rec { }; #buildInputs = [ pytest pytestcov coverage ]; - #nativeBuildInputs = [ bootstrapped-pip setuptools ]; + nativeBuildInputs = [ bootstrapped-pip setuptools ]; #catchConflicts = false; - #doCheck = false; + doCheck = false; #pythonImportsCheck = [ "wheel" ]; # We add this flag to ignore the copy installed by bootstrapped-pip - installFlags = [ "--ignore-installed" ]; + pipInstallFlags = [ "--ignore-installed" ]; meta = { description = "A built-package format for Python"; diff --git a/result b/result index 41ef4f2..c3f6e6e 120000 --- a/result +++ b/result @@ -1 +1 @@ -/nix/store/b5d52gx1g9lwihsqgkdgm606nb1hni57-python2.6-wheel-0.29.0 \ No newline at end of file +/nix/store/qr2d62ybl4vm30hdn5bzxm0387hq95ik-python2.6-wheel-0.29.0 \ No newline at end of file diff --git a/setuptools.nix b/setuptools.nix index 55d6df3..616adbb 100644 --- a/setuptools.nix +++ b/setuptools.nix @@ -1,40 +1,89 @@ -{ lib, - stdenv -, fetchPypi -, python -, wrapPython -, unzip +{ + pkgs, + stdenv, + buildPythonPackage, + fetchFromGitHub, + python, + bootstrapped-pip, + lib, + pipInstallHookMine, + setuptoolsBuildHook, }: -# Should use buildPythonPackage here somehow -stdenv.mkDerivation rec { +let pname = "setuptools"; version = "36.8.0"; - name = "${python.libPrefix}-${pname}-${version}"; - src = fetchPypi { - inherit pname version; - extension = "zip"; - hash = "sha256-sqpaAOnk/SDzw91BLUkJIXRu/hS9o01TlzxKWasFs10="; + # Create an sdist of setuptools + sdist = stdenv.mkDerivation rec { + name = "${pname}-${version}-sdist.tar.gz"; + + src = fetchFromGitHub { + owner = "pypa"; + repo = pname; + rev = "v${version}"; + hash = "sha256-S9drUN5W1fA9zEC2tGUi15Mnn9ZkKOxEUAlJrlJjcR8="; + name = "${pname}-${version}-source"; + }; + + patches = [ + (pkgs.path + "/pkgs/development/python2-modules/setuptools//tag-date.patch") + ]; + + buildPhase = '' + ${python.pythonOnBuildForHost.interpreter} bootstrap.py + ${python.pythonOnBuildForHost.interpreter} setup.py sdist --formats=gztar + + # Here we untar the sdist and retar it in order to control the timestamps + # of all the files included + tar -xzf dist/${pname}-${version}.post0.tar.gz -C dist/ + tar -czf dist/${name} -C dist/ --mtime="@$SOURCE_DATE_EPOCH" ${pname}-${version}.post0 + ''; + + installPhase = '' + echo "Moving sdist..." + mv dist/${name} $out + ''; }; +in +buildPythonPackage { + inherit pname version; + # Because of bootstrapping we don't use the setuptoolsBuildHook that comes with format="setuptools" directly. + # Instead, we override it to remove setuptools to avoid a circular dependency. + # The same is done for pip and the pipInstallHook. + format = "other"; - buildInputs = [ python wrapPython unzip ]; - doCheck = false; # requires pytest - installPhase = '' - dst=$out/${python.sitePackages} - mkdir -p $dst - export PYTHONPATH="$dst:$PYTHONPATH" - ${python.interpreter} setup.py install --prefix=$out - wrapPythonPrograms + src = sdist; + + nativeBuildInputs = [ + bootstrapped-pip + (pipInstallHookMine.override { pip = null; }) + (setuptoolsBuildHook.override { + setuptools = null; + wheel = null; + }) + ]; + + preBuild = lib.optionalString (!stdenv.hostPlatform.isWindows) '' + export SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES=0 ''; - pythonPath = []; + pipInstallFlags = [ "--ignore-installed" ]; + + # Adds setuptools to nativeBuildInputs causing infinite recursion. + catchConflicts = false; + + # Requires pytest, causing infinite recursion. + doCheck = false; meta = with lib; { description = "Utilities to facilitate the installation of Python packages"; - homepage = http://pypi.python.org/pypi/setuptools; - license = with licenses; [ psfl zpl20 ]; - platforms = platforms.all; + homepage = "https://pypi.python.org/pypi/setuptools"; + license = with licenses; [ + psfl + zpl20 + ]; + platforms = python.meta.platforms; priority = 10; }; }