From 3290828905a77069b6d51cafb7a6a8669a51bb11 Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 17 Jan 2023 11:46:03 -0500 Subject: fetchPypi: move to top level fetchPypi doesn't use python under the hood and doesn't need to be tied to a specific version of python. Moving it to top level makes it more consistent with other fetchers and makes code generation easier. --- pkgs/build-support/fetchpypi/default.nix | 28 ++++++++++++++++++++++ pkgs/development/interpreters/python/fetchpypi.nix | 28 ---------------------- .../interpreters/python/python-packages-base.nix | 4 +--- pkgs/top-level/all-packages.nix | 2 ++ 4 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 pkgs/build-support/fetchpypi/default.nix delete mode 100644 pkgs/development/interpreters/python/fetchpypi.nix diff --git a/pkgs/build-support/fetchpypi/default.nix b/pkgs/build-support/fetchpypi/default.nix new file mode 100644 index 000000000000..ebd277cd2bdf --- /dev/null +++ b/pkgs/build-support/fetchpypi/default.nix @@ -0,0 +1,28 @@ +# `fetchPypi` function for fetching artifacts from PyPI. +{ fetchurl +, makeOverridable +}: + +let + computeUrl = {format ? "setuptools", ... } @attrs: let + computeWheelUrl = {pname, version, dist ? "py2.py3", python ? "py2.py3", abi ? "none", platform ? "any"}: + # Fetch a wheel. By default we fetch an universal wheel. + # See https://www.python.org/dev/peps/pep-0427/#file-name-convention for details regarding the optional arguments. + "https://files.pythonhosted.org/packages/${dist}/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}-${python}-${abi}-${platform}.whl"; + + computeSourceUrl = {pname, version, extension ? "tar.gz"}: + # Fetch a source tarball. + "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.${extension}"; + + compute = (if format == "wheel" then computeWheelUrl + else if format == "setuptools" then computeSourceUrl + else throw "Unsupported format ${format}"); + + in compute (builtins.removeAttrs attrs ["format"]); + +in makeOverridable( {format ? "setuptools", sha256 ? "", hash ? "", ... } @attrs: + let + url = computeUrl (builtins.removeAttrs attrs ["sha256" "hash"]) ; + in fetchurl { + inherit url sha256 hash; + }) diff --git a/pkgs/development/interpreters/python/fetchpypi.nix b/pkgs/development/interpreters/python/fetchpypi.nix deleted file mode 100644 index ebd277cd2bdf..000000000000 --- a/pkgs/development/interpreters/python/fetchpypi.nix +++ /dev/null @@ -1,28 +0,0 @@ -# `fetchPypi` function for fetching artifacts from PyPI. -{ fetchurl -, makeOverridable -}: - -let - computeUrl = {format ? "setuptools", ... } @attrs: let - computeWheelUrl = {pname, version, dist ? "py2.py3", python ? "py2.py3", abi ? "none", platform ? "any"}: - # Fetch a wheel. By default we fetch an universal wheel. - # See https://www.python.org/dev/peps/pep-0427/#file-name-convention for details regarding the optional arguments. - "https://files.pythonhosted.org/packages/${dist}/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}-${python}-${abi}-${platform}.whl"; - - computeSourceUrl = {pname, version, extension ? "tar.gz"}: - # Fetch a source tarball. - "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.${extension}"; - - compute = (if format == "wheel" then computeWheelUrl - else if format == "setuptools" then computeSourceUrl - else throw "Unsupported format ${format}"); - - in compute (builtins.removeAttrs attrs ["format"]); - -in makeOverridable( {format ? "setuptools", sha256 ? "", hash ? "", ... } @attrs: - let - url = computeUrl (builtins.removeAttrs attrs ["sha256" "hash"]) ; - in fetchurl { - inherit url sha256 hash; - }) diff --git a/pkgs/development/interpreters/python/python-packages-base.nix b/pkgs/development/interpreters/python/python-packages-base.nix index 92b0a456b077..d5b02223fd6c 100644 --- a/pkgs/development/interpreters/python/python-packages-base.nix +++ b/pkgs/development/interpreters/python/python-packages-base.nix @@ -41,8 +41,6 @@ let # See build-setupcfg/default.nix for documentation. buildSetupcfg = import ../../../build-support/build-setupcfg self; - fetchPypi = callPackage ./fetchpypi.nix { }; - # Check whether a derivation provides a Python module. hasPythonModule = drv: drv?pythonModule && drv.pythonModule == python; @@ -89,7 +87,7 @@ in { inherit lib pkgs stdenv; inherit (python.passthru) isPy27 isPy37 isPy38 isPy39 isPy310 isPy311 isPy3k isPyPy pythonAtLeast pythonOlder; inherit buildPythonPackage buildPythonApplication; - inherit fetchPypi; + inherit (pkgs) fetchPypi; inherit hasPythonModule requiredPythonModules makePythonPath disabled disabledIf; inherit toPythonModule toPythonApplication; inherit buildSetupcfg; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2a5d3d46f7f1..e072453f0c9d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -935,6 +935,8 @@ with pkgs; fetchgx = callPackage ../build-support/fetchgx { }; + fetchPypi = callPackage ../build-support/fetchpypi { }; + resolveMirrorURLs = {url}: fetchurl { showURLs = true; inherit url; -- cgit v1.2.3