Skip to content

Commit

Permalink
Avoid writing invalid PEP 723 scripts on tool.uv.sources
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 27, 2024
1 parent cee0d2d commit 580e3f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
9 changes: 4 additions & 5 deletions crates/uv-scripts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,12 @@ fn serialize_metadata(metadata: &str) -> String {
output.push('\n');

for line in metadata.lines() {
if line.is_empty() {
output.push('\n');
} else {
output.push_str("# ");
output.push('#');
if !line.is_empty() {
output.push(' ');
output.push_str(line);
output.push('\n');
}
output.push('\n');
}

output.push_str("# ///");
Expand Down
27 changes: 12 additions & 15 deletions crates/uv/tests/edit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg(all(feature = "python", feature = "pypi"))]

use anyhow::Result;
use assert_cmd::assert::OutputAssertExt;
use assert_fs::prelude::*;
use indoc::indoc;
use insta::assert_snapshot;
Expand Down Expand Up @@ -3918,16 +3919,12 @@ fn add_git_to_script() -> Result<()> {
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "rich",
# "anyio",
# ]
# ///
import requests
from rich.pretty import pprint
resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])
import anyio
import uv_public_pypackage
"#})?;

uv_snapshot!(context.filters(), context
Expand All @@ -3953,23 +3950,23 @@ fn add_git_to_script() -> Result<()> {
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "rich",
# "anyio",
# "uv-public-pypackage",
# ]
#
# [tool.uv.sources]
# uv-public-pypackage = { git = "https://github.com/astral-test/uv-public-pypackage", tag = "0.0.1" }
# ///
import requests
from rich.pretty import pprint
resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])
import anyio
import uv_public_pypackage
"###
);
});

// Ensure that the script runs without error.
context.run().arg("script.py").assert().success();

Ok(())
}

Expand Down

0 comments on commit 580e3f8

Please sign in to comment.