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

Avoid writing invalid PEP 723 scripts on tool.uv.sources #6706

Merged
merged 1 commit into from
Aug 27, 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
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]
charliermarsh marked this conversation as resolved.
Show resolved Hide resolved
# 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
Loading