Skip to content

Commit

Permalink
Add user-facing output to indicate PEP 723 script (#4881)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Jul 8, 2024
1 parent ae242c3 commit ffcc052
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
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: {}",
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

0 comments on commit ffcc052

Please sign in to comment.