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

Add user-facing output to indicate PEP 723 script #4881

Merged
merged 1 commit into from
Jul 8, 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: 8 additions & 1 deletion crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::borrow::Cow;
use std::ffi::OsString;
use std::fmt::Write;
use std::path::PathBuf;

use anyhow::{Context, Result};
use itertools::Itertools;
use owo_colors::OwoColorize;
use tokio::process::Command;
use tracing::debug;

Expand All @@ -13,6 +15,7 @@ use uv_cli::ExternalCommand;
use uv_client::{BaseClientBuilder, Connectivity};
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode};
use uv_distribution::{VirtualProject, Workspace, WorkspaceError};
use uv_fs::Simplified;
use uv_installer::{SatisfiesResult, SitePackages};
use uv_normalize::PackageName;
use uv_python::{
Expand Down Expand Up @@ -63,7 +66,11 @@ pub(crate) async fn run(
// Determine whether the command to execute is a PEP 723 script.
let script_interpreter = if let RunCommand::Python(target, _) = &command {
if let Some(metadata) = uv_scripts::read_pep723_metadata(&target).await? {
debug!("Found PEP 723 script at: {}", target.display());
writeln!(
printer.stderr(),
"Reading inline script metadata from: {}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of a nit, but we've already read it right? And the user passed us this script name already? Should we just say "Using inline script metadata for requirements" (a little unsure about "requirements")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer "Using inline script metadata for: {}"

target.user_display().cyan()
)?;

// (1) Explicit request from user
let python_request = if let Some(request) = python.as_deref() {
Expand Down
20 changes: 11 additions & 9 deletions crates/uv/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,17 @@ fn run_script() -> Result<()> {

// Running the script should install the requirements.
uv_snapshot!(context.filters(), context.run().arg("--preview").arg("main.py"), @r###"
success: true
exit_code: 0
----- stdout -----
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ iniconfig==2.0.0
"###);
----- stderr -----
Reading inline script metadata from: main.py
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ iniconfig==2.0.0
"###);

// Running again should use the existing environment.
uv_snapshot!(context.filters(), context.run().arg("--preview").arg("main.py"), @r###"
Expand All @@ -243,6 +244,7 @@ fn run_script() -> Result<()> {
----- stdout -----

----- stderr -----
Reading inline script metadata from: main.py
Resolved 1 package in [TIME]
"###);

Expand Down
Loading