Skip to content

Commit

Permalink
pythonPackages: new fetchers
Browse files Browse the repository at this point in the history
Inspired by #22257.
It is recommend to use fetchpypi and, when fetching a wheel, to pass
`format = "wheel"` (typically you can just `inherit format;`).

The hash type is fixed (for now) because this is the hash type PyPI
uses.
  • Loading branch information
FRidh committed Feb 1, 2017
1 parent 7b6b7f6 commit 695ff0d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,30 @@ let

graphiteVersion = "0.9.15";

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;};

fetchtarball = {pname, version, sha256}:
# Fetch a tarball.
let
url = "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.tar.gz";
in pkgs.fetchurl {inherit url sha256;};

fetchpypi = {format ? "setuptools", ... } @attrs:
let
fetcher = (if format == "wheel" then fetchwheel
else if format == "setuptools" then fetchtarball
else throw "Unsupported kind ${kind}");
in fetcher (builtins.removeAttrs attrs ["format"]);

in {

inherit python bootstrapped-pip pythonAtLeast pythonOlder isPy26 isPy27 isPy33 isPy34 isPy35 isPy36 isPyPy isPy3k mkPythonDerivation buildPythonPackage buildPythonApplication;
inherit fetchwheel fetchtarball fetchpypi;

# helpers

Expand Down

1 comment on commit 695ff0d

@edolstra
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Function names should be in camelCase, i.e. fetchWheel and fetchTarball.

  • The name fetchTarball seems potentially confusing with Nix's builtin fetchTarball.

Please sign in to comment.