From e57f78ac0d8dfa88f5305521e76f073b14e62ce8 Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 3 Sep 2023 01:49:48 +0200 Subject: [PATCH] Revert "Add hash for git based packages" This reverts commit 5f28fd1c9fae435414fa78c9ca4a269405e6e45a. --- pkgs/fetchPipMetadata/fetchPipMetadata.nix | 5 +- pkgs/fetchPipMetadata/package.nix | 2 - .../lock_file_from_report.py | 69 +++---------------- 3 files changed, 13 insertions(+), 63 deletions(-) diff --git a/pkgs/fetchPipMetadata/fetchPipMetadata.nix b/pkgs/fetchPipMetadata/fetchPipMetadata.nix index f206a979..67f5d4c8 100644 --- a/pkgs/fetchPipMetadata/fetchPipMetadata.nix +++ b/pkgs/fetchPipMetadata/fetchPipMetadata.nix @@ -40,17 +40,16 @@ nix, git, writePureShellScript, - nix-prefetch-scripts, }: let # We use nixpkgs python3 to run mitmproxy, see function parameters pythonWithMitmproxy = python3.withPackages (ps: [ps.mitmproxy ps.python-dateutil]); - path = [nix git nix-prefetch-scripts] ++ nativeBuildInputs; + path = [nix git] ++ nativeBuildInputs; package = import ./package.nix { - inherit git lib python nix-prefetch-scripts; + inherit git lib python; }; args = writeText "pip-args" (builtins.toJSON { diff --git a/pkgs/fetchPipMetadata/package.nix b/pkgs/fetchPipMetadata/package.nix index 0bfdb4b9..749fd5c4 100644 --- a/pkgs/fetchPipMetadata/package.nix +++ b/pkgs/fetchPipMetadata/package.nix @@ -5,7 +5,6 @@ # Pip accepts '--python-version', but this works only for wheel packages. python, git, - nix-prefetch-scripts, }: let package = python.pkgs.buildPythonPackage { name = "fetch_pip_metadata"; @@ -14,7 +13,6 @@ nativeBuildInputs = [ git python.pkgs.pytestCheckHook - nix-prefetch-scripts ]; propagatedBuildInputs = with python.pkgs; [ packaging diff --git a/pkgs/fetchPipMetadata/src/fetch_pip_metadata/lock_file_from_report.py b/pkgs/fetchPipMetadata/src/fetch_pip_metadata/lock_file_from_report.py index b6a43aa8..5fbb5646 100644 --- a/pkgs/fetchPipMetadata/src/fetch_pip_metadata/lock_file_from_report.py +++ b/pkgs/fetchPipMetadata/src/fetch_pip_metadata/lock_file_from_report.py @@ -1,5 +1,3 @@ -from __future__ import annotations -from typing import Optional, Tuple import subprocess import json from pathlib import Path @@ -51,13 +49,6 @@ def lock_info_from_fod(store_path, drv_json): return url, sha256 -def lock_info_from_file_url(download_info): - path = path_from_file_url(download_info["url"]) - - if path is not None: - return lock_info_from_path(path) - - def path_from_file_url(url): prefix = "file://" prefix_len = len(prefix) @@ -102,43 +93,6 @@ def lock_info_from_path(full_path): ) -def lock_info_from_archive(download_info) -> Optional[Tuple[str, Optional[str]]]: - try: - archive_info = download_info["archive_info"] - except KeyError: - return None - - hash = archive_info.get("hash", "").split("=", 1) - sha256 = hash[1] if hash[0] == "sha256" else None - - return (download_info["url"], sha256) - - -def lock_info_from_vcs(download_info) -> Optional[Tuple[str, Optional[str]]]: - try: - vcs_info = download_info["vcs_info"] - except KeyError: - return None - - match vcs_info["vcs"]: - case "git": - url = download_info["url"] - rev = vcs_info["commit_id"] - sha256 = json.loads( - subprocess.run( - ["nix-prefetch-git", url, rev], - capture_output=True, - universal_newlines=True, - check=True, - ).stdout - )["sha256"] - return (f"git+{url}@{rev}", sha256) - - -def lock_info_fallback(download_info): - return download_info["url"], None - - def lock_entry_from_report_entry(install): """ Convert an entry of report['install'] to an object we want to store @@ -147,19 +101,18 @@ def lock_entry_from_report_entry(install): name = canonicalize_name(install["metadata"]["name"]) download_info = install["download_info"] - for lock_info in ( - lock_info_from_archive, - lock_info_from_vcs, - lock_info_from_file_url, - ): - info = lock_info(download_info) - if info is not None: - break - else: - info = lock_info_fallback(download_info) - - url, sha256 = info + url, sha256 = download_info["url"], None + full_path = path_from_file_url(url) + if full_path: + url, sha256 = lock_info_from_path(full_path) + if not sha256: + hash = ( + download_info.get("archive_info", {}) + .get("hash", "") + .split("=", 1) # noqa: 501 + ) + sha256 = hash[1] if hash[0] == "sha256" else None return name, dict( url=url, version=install["metadata"]["version"],