diff options
author | figsoda <figsoda@pm.me> | 2023-01-17 11:46:03 -0500 |
---|---|---|
committer | Frederik Rietdijk <freddyrietdijk@fridh.nl> | 2023-01-21 08:21:33 +0100 |
commit | 3290828905a77069b6d51cafb7a6a8669a51bb11 (patch) | |
tree | 7d6562755dfe17fbbfbe416baa392fac553e9dc5 /pkgs/build-support/fetchpypi | |
parent | a72e215c758b3d80a5e540236aac5622c34be140 (diff) |
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.
Diffstat (limited to 'pkgs/build-support/fetchpypi')
-rw-r--r-- | pkgs/build-support/fetchpypi/default.nix | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pkgs/build-support/fetchpypi/default.nix b/pkgs/build-support/fetchpypi/default.nix new file mode 100644 index 0000000000000..ebd277cd2bdf8 --- /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; + }) |