From f2a81174922c1bd1875e2b1b09c29565226c30db Mon Sep 17 00:00:00 2001 From: Frederik Rietdijk Date: Thu, 11 Jul 2019 16:06:32 +0200 Subject: [PATCH] pythonPackages.fetchPypi: put expression in own file Also fixes an evaluation bug. --- .../interpreters/python/fetchpypi.nix | 22 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 18 +-------------- 2 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 pkgs/development/interpreters/python/fetchpypi.nix diff --git a/pkgs/development/interpreters/python/fetchpypi.nix b/pkgs/development/interpreters/python/fetchpypi.nix new file mode 100644 index 000000000000..ece4e136d3f8 --- /dev/null +++ b/pkgs/development/interpreters/python/fetchpypi.nix @@ -0,0 +1,22 @@ +# `fetchPypi` function for fetching artifacts from PyPI. +{ fetchurl +, makeOverridable +}: + +makeOverridable( {format ? "setuptools", ... } @attrs: + let + fetchWheel = {pname, version, sha256, 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. + let + url = "https://files.pythonhosted.org/packages/${python}/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}-${python}-${abi}-${platform}.whl"; + in fetchurl {inherit url sha256;}; + fetchSource = {pname, version, sha256, extension ? "tar.gz"}: + # Fetch a source tarball. + let + url = "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.${extension}"; + in fetchurl {inherit url sha256;}; + fetcher = (if format == "wheel" then fetchWheel + else if format == "setuptools" then fetchSource + else throw "Unsupported format ${format}"); + in fetcher (builtins.removeAttrs attrs ["format"]) ) \ No newline at end of file diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 65179adf5c27..3b2e27d30ad5 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -58,23 +58,7 @@ let # See build-setupcfg/default.nix for documentation. buildSetupcfg = import ../build-support/build-setupcfg self; - fetchPypi = makeOverridable( {format ? "setuptools", ... } @attrs: - let - fetchWheel = {pname, version, sha256, 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. - let - url = "https://files.pythonhosted.org/packages/${python}/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}-${python}-${abi}-${platform}.whl"; - in pkgs.fetchurl {inherit url sha256;}; - fetchSource = {pname, version, sha256, extension ? "tar.gz"}: - # Fetch a source tarball. - let - url = "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.${extension}"; - in pkgs.fetchurl {inherit url sha256;}; - fetcher = (if format == "wheel" then fetchWheel - else if format == "setuptools" then fetchSource - else throw "Unsupported kind ${kind}"); - in fetcher (builtins.removeAttrs attrs ["format"]) ); + fetchPypi = callPackage ../development/interpreters/python/fetchpypi.nix {}; # Check whether a derivation provides a Python module. hasPythonModule = drv: drv?pythonModule && drv.pythonModule == python;