Skip to content

Commit

Permalink
Address the review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
  • Loading branch information
kakkoyun committed Sep 26, 2024
1 parent 2a93ebb commit f9a62eb
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions crates/uv-fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ tempfile = { workspace = true }
tracing = { workspace = true }
urlencoding = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies]
winsafe = { workspace = true }

[target.'cfg(any(unix, target_os = "wasi", target_os = "redox"))'.dependencies]
rustix = { workspace = true }

[target.'cfg(windows)'.dependencies]
junction = { workspace = true }

Expand Down
1 change: 1 addition & 0 deletions crates/uv-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub use crate::path::*;

pub mod cachedir;
mod path;
pub mod which;

/// Reads data from the path and requires that it be valid UTF-8 or UTF-16.
///
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions crates/uv-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ tracing = { workspace = true }
url = { workspace = true }
which = { workspace = true }

[target.'cfg(any(unix, target_os = "wasi", target_os = "redox"))'.dependencies]
rustix = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies]
windows-sys = { workspace = true }
winsafe = { workspace = true }
windows-registry = { workspace = true }
windows-result = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-python/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use which::{which, which_all};

use pep440_rs::{Prerelease, Version, VersionSpecifier, VersionSpecifiers};
use uv_cache::Cache;
use uv_fs::which::is_executable;
use uv_fs::Simplified;
use uv_warnings::warn_user_once;

Expand All @@ -27,7 +28,6 @@ use crate::virtualenv::{
conda_prefix_from_env, virtualenv_from_env, virtualenv_from_working_dir,
virtualenv_python_executable,
};
use crate::which::is_executable;
use crate::{Interpreter, PythonVersion};

/// A request to find a Python installation.
Expand Down
1 change: 0 additions & 1 deletion crates/uv-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ mod python_version;
mod target;
mod version_files;
mod virtualenv;
pub mod which;

#[cfg(not(test))]
pub(crate) fn current_dir() -> Result<std::path::PathBuf, std::io::Error> {
Expand Down
36 changes: 27 additions & 9 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ use uv_configuration::{
Concurrency, DevMode, EditableMode, ExtrasSpecification, InstallOptions, SourceStrategy,
};
use uv_distribution::LoweredRequirement;
use uv_fs::which::is_executable;
use uv_fs::{PythonExt, Simplified};
use uv_installer::{SatisfiesResult, SitePackages};
use uv_normalize::PackageName;
use uv_python::which::is_executable;

use uv_python::{
EnvironmentPreference, Interpreter, PythonDownloads, PythonEnvironment, PythonInstallation,
PythonPreference, PythonRequest, PythonVersionFile, VersionRequest,
Expand Down Expand Up @@ -723,10 +724,11 @@ pub(crate) async fn run(
if let RunCommand::Empty = command {
writeln!(
printer.stdout(),
"Provide a command or script to invoke with `uv run <command>` or `uv run script.py`.\n"
"Provide a command or script to invoke with `uv run <command>` or `uv run <script>.py`.\n"
)?;

let mut scripts = interpreter
#[allow(clippy::map_identity)]
let mut commands = interpreter
.scripts()
.read_dir()
.ok()
Expand All @@ -735,7 +737,10 @@ pub(crate) async fn run(
.filter_map(|entry| match entry {
Ok(entry) => Some(entry),
Err(err) => {
debug!("Failed to read entry: {}", err);
// If we can't read the entry, skip it.
// However, let the user know that we failed to read it.
// This could be a symptom of a more serious problem.
warn!("Failed to read entry: {}", err);
None
}
})
Expand All @@ -746,25 +751,38 @@ pub(crate) async fn run(
})
.map(|entry| entry.path())
.filter(|path| is_executable(path))
.map(|path| {
if cfg!(windows) {
// remove the extensions
path.with_extension("")
} else {
path
}
})
.map(|path| {
path.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_string()
})
.filter(|command| {
!command.starts_with("activate") || !command.starts_with("deactivate")
})
.collect_vec();
scripts.sort();
commands.sort();

if !scripts.is_empty() {
writeln!(printer.stdout(), "The following scripts are available:\n")?;
writeln!(printer.stdout(), "{}", scripts.join("\n"))?;
if !commands.is_empty() {
writeln!(printer.stdout(), "The following commands are available:")?;
for command in commands {
writeln!(printer.stdout(), "- {command}")?;
}
}
writeln!(
printer.stdout(),
"\nSee `uv run --help` for more information."
)?;

return Ok(ExitStatus::Success);
return Ok(ExitStatus::Failure);
};

debug!("Running `{command}`");
Expand Down
33 changes: 12 additions & 21 deletions crates/uv/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,15 @@ fn run_no_args() -> Result<()> {
// Run without specifying any argunments.
#[cfg(not(windows))]
uv_snapshot!(context.filters(), context.run(), @r###"
success: true
exit_code: 0
success: false
exit_code: 1
----- stdout -----
Provide a command or script to invoke with `uv run <command>` or `uv run script.py`.
The following scripts are available:
Provide a command or script to invoke with `uv run <command>` or `uv run <script>.py`.
python
python3
python3.12
The following commands are available:
- python
- python3
- python3.12
See `uv run --help` for more information.
Expand All @@ -245,20 +244,12 @@ fn run_no_args() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
Provide a command or script to invoke with `uv run <command>` or `uv run script.py`.
The following scripts are available:
Provide a command or script to invoke with `uv run <command>` or `uv run <script>.py`.
activate.bat
activate.csh
activate.fish
activate.nu
activate.ps1
activate_this.py
deactivate.bat
pydoc.bat
python.exe
pythonw.exe
The following commands are available:
- pydoc
- python
- pythonw
See `uv run --help` for more information.
Expand Down

0 comments on commit f9a62eb

Please sign in to comment.