Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at python-updates 67 lines 1.5 kB view raw
1# `fetchPypi` function for fetching artifacts from PyPI. 2{ 3 fetchurl, 4 makeOverridable, 5}: 6 7let 8 computeUrl = 9 { 10 format ? "setuptools", 11 ... 12 }@attrs: 13 let 14 computeWheelUrl = 15 { 16 pname, 17 version, 18 dist ? "py2.py3", 19 python ? "py2.py3", 20 abi ? "none", 21 platform ? "any", 22 }: 23 # Fetch a wheel. By default we fetch an universal wheel. 24 # See https://www.python.org/dev/peps/pep-0427/#file-name-convention for details regarding the optional arguments. 25 "https://files.pythonhosted.org/packages/${dist}/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}-${python}-${abi}-${platform}.whl"; 26 27 computeSourceUrl = 28 { 29 pname, 30 version, 31 extension ? "tar.gz", 32 }: 33 # Fetch a source tarball. 34 "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.${extension}"; 35 36 compute = ( 37 if format == "wheel" then 38 computeWheelUrl 39 else if format == "setuptools" then 40 computeSourceUrl 41 else 42 throw "Unsupported format ${format}" 43 ); 44 45 in 46 compute (builtins.removeAttrs attrs [ "format" ]); 47 48in 49makeOverridable ( 50 { 51 format ? "setuptools", 52 sha256 ? "", 53 hash ? "", 54 ... 55 }@attrs: 56 let 57 url = computeUrl ( 58 builtins.removeAttrs attrs [ 59 "sha256" 60 "hash" 61 ] 62 ); 63 in 64 fetchurl { 65 inherit url sha256 hash; 66 } 67)