Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 20.03 28 lines 1.2 kB view raw
1# `fetchPypi` function for fetching artifacts from PyPI. 2{ fetchurl 3, makeOverridable 4}: 5 6let 7 computeUrl = {format ? "setuptools", ... } @attrs: let 8 computeWheelUrl = {pname, version, python ? "py2.py3", abi ? "none", platform ? "any"}: 9 # Fetch a wheel. By default we fetch an universal wheel. 10 # See https://www.python.org/dev/peps/pep-0427/#file-name-convention for details regarding the optional arguments. 11 "https://files.pythonhosted.org/packages/${python}/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}-${python}-${abi}-${platform}.whl"; 12 13 computeSourceUrl = {pname, version, extension ? "tar.gz"}: 14 # Fetch a source tarball. 15 "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.${extension}"; 16 17 compute = (if format == "wheel" then computeWheelUrl 18 else if format == "setuptools" then computeSourceUrl 19 else throw "Unsupported format ${format}"); 20 21 in compute (builtins.removeAttrs attrs ["format"]); 22 23in makeOverridable( {format ? "setuptools", sha256 ? "", hash ? "", ... } @attrs: 24 let 25 url = computeUrl (builtins.removeAttrs attrs ["sha256" "hash"]) ; 26 in fetchurl { 27 inherit url sha256 hash; 28 })