From 81d43b9b83b4443d9c4d90f601e6fe356eb89a9e Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 12 Nov 2023 23:40:41 +0700 Subject: [PATCH] fetchPypiLegacy: add test --- pkgs/build-support/fetchpypilegacy/default.nix | 11 ++++++----- pkgs/build-support/fetchpypilegacy/tests.nix | 9 +++++++++ pkgs/test/default.nix | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 pkgs/build-support/fetchpypilegacy/tests.nix diff --git a/pkgs/build-support/fetchpypilegacy/default.nix b/pkgs/build-support/fetchpypilegacy/default.nix index 1a308ffc323e..bcd560449916 100644 --- a/pkgs/build-support/fetchpypilegacy/default.nix +++ b/pkgs/build-support/fetchpypilegacy/default.nix @@ -14,6 +14,8 @@ file, # SRI hash hash, + # allow overriding the derivation name + name ? null, }: let urls' = urls ++ lib.optional (url != null) url; @@ -27,17 +29,16 @@ let in # Assert that we have at least one URL assert urls' != [ ]; runCommand file - { + ({ nativeBuildInputs = [ python3 ]; impureEnvVars = lib.fetchers.proxyImpureEnvVars; outputHashMode = "flat"; - outputHashAlgo = null; + # if hash is empty select a default algo to let nix propose the actual hash. + outputHashAlgo = if hash == "" then "sha256" else null; outputHash = hash; NETRC = netrc_file; - passthru = { - urls = urls'; - }; } + // (lib.optionalAttrs (name != null) {inherit name;})) '' python ${./fetch-legacy.py} ${lib.concatStringsSep " " (map (url: "--url ${lib.escapeShellArg url}") urls')} --pname ${pname} --filename ${file} mv ${file} $out diff --git a/pkgs/build-support/fetchpypilegacy/tests.nix b/pkgs/build-support/fetchpypilegacy/tests.nix new file mode 100644 index 000000000000..b16325b96b7e --- /dev/null +++ b/pkgs/build-support/fetchpypilegacy/tests.nix @@ -0,0 +1,9 @@ +{ testers, fetchPypiLegacy, ... }: { + # Tests that we can send custom headers with spaces in them + fetchSimple = testers.invalidateFetcherByDrvHash fetchPypiLegacy { + pname = "requests"; + file = "requests-2.31.0.tar.gz"; + url = "https://pypi.org/simple"; + hash = "sha256-lCxadY+Y15Dq7Ropy27vx/+w0c968Fw9J5Flbb1q0eE="; + }; +} diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index b89fcc3ecb6d..5382cae6159f 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -111,6 +111,7 @@ with pkgs; fetchzip = callPackages ../build-support/fetchzip/tests.nix { }; fetchgit = callPackages ../build-support/fetchgit/tests.nix { }; fetchFirefoxAddon = callPackages ../build-support/fetchfirefoxaddon/tests.nix { }; + fetchPypiLegacy = callPackages ../build-support/fetchpypilegacy/tests.nix { }; install-shell-files = callPackage ./install-shell-files {};