Update BUILD_VENDOR_LINKS_URL from packse version (#3246)

Make `generate.py` update the packse version used in
`BUILD_VENDOR_LINKS_URL`.

Closes #3245
This commit is contained in:
konsti 2024-04-24 17:54:38 +02:00 committed by GitHub
parent 691b7d26a0
commit 005b76770e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View file

@ -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)] = &[

View file

@ -39,6 +39,7 @@ import argparse
import importlib.metadata
import logging
import os
import re
import subprocess
import sys
import textwrap
@ -54,6 +55,7 @@ PROJECT_ROOT = TOOL_ROOT.parent.parent
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.",