Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BUILD_VENDOR_LINKS_URL from packse version #3246

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)] = &[
Expand Down
24 changes: 24 additions & 0 deletions scripts/scenarios/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import importlib.metadata
import logging
import os
import re
import subprocess
import sys
import textwrap
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.",
Expand Down
Loading