at 24.11-pre 9.0 kB view raw
1self: dontUse: with self; 2 3let 4 inherit (python) pythonOnBuildForHost; 5 inherit (pkgs) runCommand; 6 pythonInterpreter = pythonOnBuildForHost.interpreter; 7 pythonSitePackages = python.sitePackages; 8 pythonCheckInterpreter = python.interpreter; 9 setuppy = ../run_setup.py; 10in { 11 makePythonHook = let 12 defaultArgs = { passthru.provides.setupHook = true; }; 13 in args: pkgs.makeSetupHook (lib.recursiveUpdate defaultArgs args); 14 15 condaInstallHook = callPackage ({ makePythonHook, gnutar, lbzip2 }: 16 makePythonHook { 17 name = "conda-install-hook"; 18 propagatedBuildInputs = [ gnutar lbzip2 ]; 19 substitutions = { 20 inherit pythonSitePackages; 21 }; 22 } ./conda-install-hook.sh) {}; 23 24 condaUnpackHook = callPackage ({ makePythonHook }: 25 makePythonHook { 26 name = "conda-unpack-hook"; 27 propagatedBuildInputs = []; 28 } ./conda-unpack-hook.sh) {}; 29 30 eggBuildHook = callPackage ({ makePythonHook }: 31 makePythonHook { 32 name = "egg-build-hook.sh"; 33 propagatedBuildInputs = [ ]; 34 } ./egg-build-hook.sh) {}; 35 36 eggInstallHook = callPackage ({ makePythonHook, setuptools }: 37 makePythonHook { 38 name = "egg-install-hook.sh"; 39 propagatedBuildInputs = [ setuptools ]; 40 substitutions = { 41 inherit pythonInterpreter pythonSitePackages; 42 }; 43 } ./egg-install-hook.sh) {}; 44 45 eggUnpackHook = callPackage ({ makePythonHook, }: 46 makePythonHook { 47 name = "egg-unpack-hook.sh"; 48 propagatedBuildInputs = [ ]; 49 } ./egg-unpack-hook.sh) {}; 50 51 pipBuildHook = callPackage ({ makePythonHook, pip, wheel }: 52 makePythonHook { 53 name = "pip-build-hook.sh"; 54 propagatedBuildInputs = [ pip wheel ]; 55 substitutions = { 56 inherit pythonInterpreter pythonSitePackages; 57 }; 58 } ./pip-build-hook.sh) {}; 59 60 pypaBuildHook = callPackage ({ makePythonHook, build, wheel }: 61 makePythonHook { 62 name = "pypa-build-hook.sh"; 63 propagatedBuildInputs = [ wheel ]; 64 substitutions = { 65 inherit build; 66 }; 67 # A test to ensure that this hook never propagates any of its dependencies 68 # into the build environment. 69 # This prevents false positive alerts raised by catchConflictsHook. 70 # Such conflicts don't happen within the standard nixpkgs python package 71 # set, but in downstream projects that build packages depending on other 72 # versions of this hook's dependencies. 73 passthru.tests = callPackage ./pypa-build-hook-test.nix { 74 inherit pythonOnBuildForHost; 75 }; 76 } ./pypa-build-hook.sh) { 77 inherit (pythonOnBuildForHost.pkgs) build; 78 }; 79 80 pipInstallHook = callPackage ({ makePythonHook, pip }: 81 makePythonHook { 82 name = "pip-install-hook"; 83 propagatedBuildInputs = [ pip ]; 84 substitutions = { 85 inherit pythonInterpreter pythonSitePackages; 86 }; 87 } ./pip-install-hook.sh) {}; 88 89 pypaInstallHook = callPackage ({ makePythonHook, installer }: 90 makePythonHook { 91 name = "pypa-install-hook"; 92 propagatedBuildInputs = [ installer ]; 93 substitutions = { 94 inherit pythonInterpreter pythonSitePackages; 95 }; 96 } ./pypa-install-hook.sh) { 97 inherit (pythonOnBuildForHost.pkgs) installer; 98 }; 99 100 pytestCheckHook = callPackage ({ makePythonHook, pytest }: 101 makePythonHook { 102 name = "pytest-check-hook"; 103 propagatedBuildInputs = [ pytest ]; 104 substitutions = { 105 inherit pythonCheckInterpreter; 106 }; 107 } ./pytest-check-hook.sh) {}; 108 109 pythonCatchConflictsHook = callPackage ({ makePythonHook, setuptools }: 110 makePythonHook { 111 name = "python-catch-conflicts-hook"; 112 substitutions = let 113 useLegacyHook = lib.versionOlder python.pythonVersion "3"; 114 in { 115 inherit pythonInterpreter pythonSitePackages; 116 catchConflicts = if useLegacyHook then 117 ../catch_conflicts/catch_conflicts_py2.py 118 else 119 ../catch_conflicts/catch_conflicts.py; 120 } // lib.optionalAttrs useLegacyHook { 121 inherit setuptools; 122 }; 123 passthru.tests = import ./python-catch-conflicts-hook-tests.nix { 124 inherit pythonOnBuildForHost runCommand; 125 inherit (pkgs) coreutils gnugrep writeShellScript; 126 }; 127 } ./python-catch-conflicts-hook.sh) {}; 128 129 pythonImportsCheckHook = callPackage ({ makePythonHook }: 130 makePythonHook { 131 name = "python-imports-check-hook.sh"; 132 substitutions = { 133 inherit pythonCheckInterpreter pythonSitePackages; 134 }; 135 } ./python-imports-check-hook.sh) {}; 136 137 pythonNamespacesHook = callPackage ({ makePythonHook, buildPackages }: 138 makePythonHook { 139 name = "python-namespaces-hook.sh"; 140 substitutions = { 141 inherit pythonSitePackages; 142 inherit (buildPackages) findutils; 143 }; 144 } ./python-namespaces-hook.sh) {}; 145 146 pythonOutputDistHook = callPackage ({ makePythonHook }: 147 makePythonHook { 148 name = "python-output-dist-hook"; 149 } ./python-output-dist-hook.sh ) {}; 150 151 pythonRecompileBytecodeHook = callPackage ({ makePythonHook }: 152 makePythonHook { 153 name = "python-recompile-bytecode-hook"; 154 substitutions = { 155 inherit pythonInterpreter pythonSitePackages; 156 compileArgs = lib.concatStringsSep " " (["-q" "-f" "-i -"] ++ lib.optionals isPy3k ["-j $NIX_BUILD_CORES"]); 157 bytecodeName = if isPy3k then "__pycache__" else "*.pyc"; 158 }; 159 } ./python-recompile-bytecode-hook.sh ) {}; 160 161 pythonRelaxDepsHook = callPackage ({ makePythonHook, wheel }: 162 makePythonHook { 163 name = "python-relax-deps-hook"; 164 substitutions = { 165 inherit pythonInterpreter pythonSitePackages wheel; 166 }; 167 } ./python-relax-deps-hook.sh) {}; 168 169 pythonRemoveBinBytecodeHook = callPackage ({ makePythonHook }: 170 makePythonHook { 171 name = "python-remove-bin-bytecode-hook"; 172 } ./python-remove-bin-bytecode-hook.sh) {}; 173 174 pythonRemoveTestsDirHook = callPackage ({ makePythonHook }: 175 makePythonHook { 176 name = "python-remove-tests-dir-hook"; 177 substitutions = { 178 inherit pythonSitePackages; 179 }; 180 } ./python-remove-tests-dir-hook.sh) {}; 181 182 pythonRuntimeDepsCheckHook = callPackage ({ makePythonHook, packaging }: 183 makePythonHook { 184 name = "python-runtime-deps-check-hook.sh"; 185 propagatedBuildInputs = [ packaging ]; 186 substitutions = { 187 inherit pythonInterpreter pythonSitePackages; 188 hook = ./python-runtime-deps-check-hook.py; 189 }; 190 } ./python-runtime-deps-check-hook.sh) {}; 191 192 setuptoolsBuildHook = callPackage ({ makePythonHook, setuptools, wheel }: 193 makePythonHook { 194 name = "setuptools-build-hook"; 195 propagatedBuildInputs = [ setuptools wheel ]; 196 substitutions = { 197 inherit pythonInterpreter setuppy; 198 # python2.pkgs.setuptools does not support parallelism 199 setuptools_has_parallel = setuptools != null && lib.versionAtLeast setuptools.version "69"; 200 }; 201 } ./setuptools-build-hook.sh) {}; 202 203 setuptoolsCheckHook = callPackage ({ makePythonHook, setuptools }: 204 makePythonHook { 205 name = "setuptools-check-hook"; 206 propagatedBuildInputs = [ setuptools ]; 207 substitutions = { 208 inherit pythonCheckInterpreter setuppy; 209 }; 210 } ./setuptools-check-hook.sh) {}; 211 212 setuptoolsRustBuildHook = callPackage ({ makePythonHook, setuptools-rust }: 213 makePythonHook { 214 name = "setuptools-rust-setup-hook"; 215 propagatedBuildInputs = [ setuptools-rust ]; 216 substitutions = { 217 pyLibDir = "${python}/lib/${python.libPrefix}"; 218 cargoBuildTarget = stdenv.hostPlatform.rust.rustcTargetSpec; 219 cargoLinkerVar = stdenv.hostPlatform.rust.cargoEnvVarTarget; 220 targetLinker = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; 221 }; 222 } ./setuptools-rust-hook.sh) {}; 223 224 unittestCheckHook = callPackage ({ makePythonHook }: 225 makePythonHook { 226 name = "unittest-check-hook"; 227 substitutions = { 228 inherit pythonCheckInterpreter; 229 }; 230 } ./unittest-check-hook.sh) {}; 231 232 venvShellHook = disabledIf (!isPy3k) (callPackage ({ makePythonHook, ensureNewerSourcesForZipFilesHook }: 233 makePythonHook { 234 name = "venv-shell-hook"; 235 propagatedBuildInputs = [ ensureNewerSourcesForZipFilesHook ]; 236 substitutions = { 237 inherit pythonInterpreter; 238 }; 239 } ./venv-shell-hook.sh) {}); 240 241 wheelUnpackHook = callPackage ({ makePythonHook, wheel }: 242 makePythonHook { 243 name = "wheel-unpack-hook.sh"; 244 propagatedBuildInputs = [ wheel ]; 245 } ./wheel-unpack-hook.sh) {}; 246 247 wrapPython = callPackage ../wrap-python.nix { 248 inherit (pkgs.buildPackages) makeWrapper; 249 }; 250 251 sphinxHook = callPackage ({ makePythonHook, installShellFiles }: 252 makePythonHook { 253 name = "python${python.pythonVersion}-sphinx-hook"; 254 propagatedBuildInputs = [ pythonOnBuildForHost.pkgs.sphinx installShellFiles ]; 255 substitutions = { 256 sphinxBuild = "${pythonOnBuildForHost.pkgs.sphinx}/bin/sphinx-build"; 257 }; 258 } ./sphinx-hook.sh) {}; 259}