pythonPackages.fetchPypi: separate url computation from fetchurl

This commit is contained in:
Frederik Rietdijk 2019-07-11 16:17:31 +02:00 committed by Frederik Rietdijk
parent f2a8117492
commit 30f299027a

View File

@ -3,20 +3,26 @@
, makeOverridable , makeOverridable
}: }:
makeOverridable( {format ? "setuptools", ... } @attrs:
let let
fetchWheel = {pname, version, sha256, python ? "py2.py3", abi ? "none", platform ? "any"}: computeUrl = {format ? "setuptools", ... } @attrs: let
computeWheelUrl = {pname, version, python ? "py2.py3", abi ? "none", platform ? "any"}:
# Fetch a wheel. By default we fetch an universal wheel. # 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. # See https://www.python.org/dev/peps/pep-0427/#file-name-convention for details regarding the optional arguments.
let "https://files.pythonhosted.org/packages/${python}/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}-${python}-${abi}-${platform}.whl";
url = "https://files.pythonhosted.org/packages/${python}/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}-${python}-${abi}-${platform}.whl";
in fetchurl {inherit url sha256;}; computeSourceUrl = {pname, version, extension ? "tar.gz"}:
fetchSource = {pname, version, sha256, extension ? "tar.gz"}:
# Fetch a source tarball. # Fetch a source tarball.
let "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.${extension}";
url = "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.${extension}";
in fetchurl {inherit url sha256;}; compute = (if format == "wheel" then computeWheelUrl
fetcher = (if format == "wheel" then fetchWheel else if format == "setuptools" then computeSourceUrl
else if format == "setuptools" then fetchSource
else throw "Unsupported format ${format}"); else throw "Unsupported format ${format}");
in fetcher (builtins.removeAttrs attrs ["format"]) )
in compute (builtins.removeAttrs attrs ["format"]);
in makeOverridable( {format ? "setuptools", sha256, ... } @attrs:
let
url = computeUrl (builtins.removeAttrs attrs ["sha256"]) ;
in fetchurl {
inherit url sha256;
})