From 747d69dc962d1016c2c59effbdde69b59b4847b5 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 18 Nov 2024 13:19:31 -0500 Subject: [PATCH] Respect `[[tool.uv.index]]` in PEP 723 scripts (#9208) ## Summary There was a typo here, combined with a lack of test coverage. Closes https://github.com/astral-sh/uv/issues/9201. --- crates/uv-scripts/src/lib.rs | 2 +- crates/uv/src/commands/project/run.rs | 2 +- crates/uv/tests/it/run.rs | 42 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/crates/uv-scripts/src/lib.rs b/crates/uv-scripts/src/lib.rs index fb9118a2a..02b26b88d 100644 --- a/crates/uv-scripts/src/lib.rs +++ b/crates/uv-scripts/src/lib.rs @@ -275,7 +275,7 @@ pub struct ToolUv { pub override_dependencies: Option>>, pub constraint_dependencies: Option>>, pub sources: Option>, - pub indexes: Option>, + pub index: Option>, } #[derive(Debug, Error)] diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index f5bb2b627..b7cbdfcea 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -243,7 +243,7 @@ pub(crate) async fn run( .tool .as_ref() .and_then(|tool| tool.uv.as_ref()) - .and_then(|uv| uv.indexes.as_deref()) + .and_then(|uv| uv.index.as_deref()) .unwrap_or(&empty), SourceStrategy::Disabled => &empty, }; diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 2a12d9846..b58d1e12c 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -654,6 +654,48 @@ fn run_pep723_script_metadata() -> Result<()> { Ok(()) } +/// Run a PEP 723-compatible script with a `[[tool.uv.index]]`. +#[test] +fn run_pep723_script_index() -> Result<()> { + let context = TestContext::new("3.12"); + + let test_script = context.temp_dir.child("main.py"); + test_script.write_str(indoc! { r#" + # /// script + # requires-python = ">=3.11" + # dependencies = [ + # "idna>=2", + # ] + # + # [[tool.uv.index]] + # name = "test" + # url = "https://test.pypi.org/simple" + # explicit = true + # + # [tool.uv.sources] + # idna = { index = "test" } + # /// + + import idna + "# + })?; + + uv_snapshot!(context.filters(), context.run().arg("main.py"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Reading inline script metadata from `main.py` + Resolved 1 package in [TIME] + Prepared 1 package in [TIME] + Installed 1 package in [TIME] + + idna==2.7 + "###); + + Ok(()) +} + /// Run a PEP 723-compatible script with `tool.uv` constraints. #[test] fn run_pep723_script_constraints() -> Result<()> {