-
Notifications
You must be signed in to change notification settings - Fork 620
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
uv run: List available scripts when a script is not specified #7687
base: main
Are you sure you want to change the base?
uv run: List available scripts when a script is not specified #7687
Conversation
3b07e17
to
e95ee42
Compare
.filter(|entry| { | ||
entry | ||
.file_type() | ||
.is_ok_and(|file_type| file_type.is_file() || file_type.is_symlink()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we handle symlinks like we do in uv python list
? i.e. displaying "/opt/homebrew/opt/python@3.12/bin/python3.12 -> ../Frameworks/Python.framework/Versions/3.12/bin/python3.12"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should show the filename. We don't need to be super descriptive here. Propabaly this usage flow will be like:
❯ cargo run -q -- run
Provide a command or script to invoke with `uv run <command>` or `uv run script.py`.
The following scripts are available:
python3
python3.12
python
normalizer
See `uv run --help` for more information.
❯ cargo run -q -- run python
No entry for terminal type "xterm-256color";
using dumb terminal settings.
Python 3.12.1 (main, Jan 8 2024, 05:57:25) [Clang 17.0.6 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
}) | ||
.map(|entry| entry.path()) | ||
.filter(|path| is_executable(path)) | ||
.for_each(|path| println!("{}", path.display())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably just display the name of the file, not the full path since we're making suggestions for uv run <name>
.
Some(RunCommand::try_from(command)?) | ||
match command { | ||
Some(command) => Some(RunCommand::try_from(command)?), | ||
None => Some(RunCommand::Empty), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is Some(RunCommand::Empty)
different than None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just following the existing function signatures here. I preferred to use Empty
since it was available rather than changing to Option<RunCommand>
.
I'm not sure if there is a general convention/style to follow here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't run_command
already Option<RunCommand
> though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in this particular context
uv/crates/uv/src/commands/project/run.rs
Lines 52 to 77 in 26a3552
pub(crate) async fn run( | |
project_dir: &Path, | |
script: Option<Pep723Script>, | |
command: RunCommand, | |
requirements: Vec<RequirementsSource>, | |
show_resolution: bool, | |
locked: bool, | |
frozen: bool, | |
no_sync: bool, | |
isolated: bool, | |
package: Option<PackageName>, | |
no_project: bool, | |
no_config: bool, | |
extras: ExtrasSpecification, | |
dev: DevMode, | |
editable: EditableMode, | |
python: Option<String>, | |
settings: ResolverInstallerSettings, | |
python_preference: PythonPreference, | |
python_downloads: PythonDownloads, | |
connectivity: Connectivity, | |
concurrency: Concurrency, | |
native_tls: bool, | |
cache: &Cache, | |
printer: Printer, | |
) -> anyhow::Result<ExitStatus> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah but it is at
Line 133 in 106633a
let run_command = if let Commands::Project(command) = &*cli.command { |
and
Line 1149 in 106633a
command: Option<RunCommand>, |
then we unwrap at
Line 1230 in 106633a
let command = command.expect("run command is required"); |
The Empty
variant is stale code i.e. we actually don't do this anymore
uv/crates/uv/src/commands/project/run.rs
Lines 846 to 847 in 77c2496
/// Execute an empty command (in practice, `python` with no arguments). | |
Empty, |
I'd think I'd prefer to just make it an Option<...>
and remove the expect
call, but I don't feel strongly. I guess if it's an Option
someone could make a mistake upstream while developing and we wouldn't notice? Regardless we should update the RunCommand::Empty
documentation.
e95ee42
to
26a3552
Compare
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
26a3552
to
3c1be57
Compare
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
acc79e2
to
1c3691e
Compare
activate.bat | ||
activate.csh | ||
activate.fish | ||
activate.nu | ||
activate.ps1 | ||
activate_this.py | ||
deactivate.bat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll want to exclude all the shell activation scripts
python.exe | ||
pythonw.exe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably also want to exclude the .exe
suffix since it's implied during invocation.
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
Provide a command or script to invoke with `uv run <command>` or `uv run script.py`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide a command or script to invoke with `uv run <command>` or `uv run script.py`. | |
Provide a command or script to invoke with `uv run <command>` or `uv run <script>.py`. |
----- stdout ----- | ||
Provide a command or script to invoke with `uv run <command>` or `uv run script.py`. | ||
The following scripts are available: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably say "commands" here not "scripts" since above you suggest running a script as script.py
and it risks user's conflating the concepts.
"\nSee `uv run --help` for more information." | ||
)?; | ||
|
||
return Ok(ExitStatus::Success); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we exit with a non-zero exit code? I'm not sure but I think so?
python | ||
python3 | ||
python3.12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have a minor preference for omitting the leading empty newline and listing these with the prefix -
.
pub(crate) fn is_executable(path: &Path) -> bool { | ||
pub fn is_executable(path: &Path) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to move this to uv-fs
instead of uv-python
now.
Signed-off-by: Kemal Akkoyun kakkoyun@gmail.com
Summary
This PR adds the ability to list available scripts in the environment
when
uv run
is invoked without any arguments.It somewhat mimics the behavior of
rye run
command(See https://rye.astral.sh/guide/commands/run).
This is an attempt to fix #4024.
Test Plan
I added test cases. The CI pipeline should pass.
Manuel Tests