From 005b76770ebb59589e3203ddf3eb16752a4fc834 Mon Sep 17 00:00:00 2001 From: konsti Date: Wed, 24 Apr 2024 17:54:38 +0200 Subject: [PATCH] Update BUILD_VENDOR_LINKS_URL from packse version (#3246) Make `generate.py` update the packse version used in `BUILD_VENDOR_LINKS_URL`. Closes #3245 --- crates/uv/tests/common/mod.rs | 2 +- scripts/scenarios/generate.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/uv/tests/common/mod.rs b/crates/uv/tests/common/mod.rs index 3951458c937e..46f6538c5594 100644 --- a/crates/uv/tests/common/mod.rs +++ b/crates/uv/tests/common/mod.rs @@ -25,7 +25,7 @@ pub static EXCLUDE_NEWER: &str = "2024-03-25T00:00:00Z"; /// Using a find links url allows using `--index-url` instead of `--extra-index-url` in tests /// to prevent dependency confusion attacks against our test suite. pub const BUILD_VENDOR_LINKS_URL: &str = - "https://raw.githubusercontent.com/astral-sh/packse/0.3.14/vendor/links.html"; + "https://raw.githubusercontent.com/astral-sh/packse/0.3.15/vendor/links.html"; #[doc(hidden)] // Macro and test context only, don't use directly. pub const INSTA_FILTERS: &[(&str, &str)] = &[ diff --git a/scripts/scenarios/generate.py b/scripts/scenarios/generate.py index f5a60998eff9..054ff574c85c 100755 --- a/scripts/scenarios/generate.py +++ b/scripts/scenarios/generate.py @@ -39,6 +39,7 @@ import importlib.metadata import logging import os +import re import subprocess import sys import textwrap @@ -54,6 +55,7 @@ TESTS = PROJECT_ROOT / "crates" / "uv" / "tests" INSTALL_TESTS = TESTS / "pip_install_scenarios.rs" COMPILE_TESTS = TESTS / "pip_compile_scenarios.rs" +TESTS_COMMON_MOD_RS = TESTS / "common/mod.rs" try: import packse @@ -81,6 +83,8 @@ def main(scenarios: list[Path], snapshot_update: bool = True): debug = logging.getLogger().getEffectiveLevel() <= logging.DEBUG + update_common_mod_rs(packse_version) + if not scenarios: if packse_version == "0.0.0": path = packse.__development_base_path__ / "scenarios" @@ -235,6 +239,26 @@ def main(scenarios: list[Path], snapshot_update: bool = True): logging.info("Done!") +def update_common_mod_rs(packse_version: str): + """Update the value of `BUILD_VENDOR_LINKS_URL` used in non-scenario tests.""" + test_common = TESTS_COMMON_MOD_RS.read_text() + url_before_version = "https://raw.githubusercontent.com/astral-sh/packse/" + url_after_version = "/vendor/links.html" + build_vendor_links_url = f"{url_before_version}{packse_version}{url_after_version}" + if build_vendor_links_url in test_common: + logging.info(f"Up-to-date: {TESTS_COMMON_MOD_RS}") + else: + logging.info(f"Updating: {TESTS_COMMON_MOD_RS}") + url_matcher = re.compile( + re.escape(url_before_version) + "[^/]+" + re.escape(url_after_version) + ) + assert ( + len(url_matcher.findall(test_common)) == 1 + ), f"BUILD_VENDOR_LINKS_URL not found in {TESTS_COMMON_MOD_RS}" + test_common = url_matcher.sub(build_vendor_links_url, test_common) + TESTS_COMMON_MOD_RS.write_text(test_common) + + if __name__ == "__main__": parser = argparse.ArgumentParser( description="Generates and updates snapshot test cases from packse scenarios.",