Skip to content

Commit

Permalink
Make rye run print script list to stdout (#1268)
Browse files Browse the repository at this point in the history
Fixes #1136
  • Loading branch information
mitsuhiko committed Jul 24, 2024
1 parent 3f9dcfb commit 2fd1895
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion rye/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ enum Cmd {
}

pub fn execute(cmd: Args) -> Result<(), Error> {
let _guard = redirect_to_stderr(true);
let guard = redirect_to_stderr(true);
let pyproject = PyProject::load_or_discover(cmd.pyproject.as_deref())?;

// make sure we have the minimal virtualenv.
sync(SyncOptions::python_only().pyproject(cmd.pyproject))
.context("failed to sync ahead of run")?;

if cmd.list || cmd.cmd.is_none() {
drop(guard);
return list_scripts(&pyproject);
}
let args = match cmd.cmd {
Expand Down
2 changes: 1 addition & 1 deletion rye/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub const INSTA_FILTERS: &[(&str, &str)] = &[
(r"/tmp/\.tmp\S+", "[TEMP_FILE]"),
// windows temp folders
(r"\b[A-Z]:\\.*\\Local\\Temp\\\S+", "[TEMP_FILE]"),
(r" in (\d+\.)?\d+(ms|s)\b", " in [EXECUTION_TIME]"),
(r" in (\d+m )?(\d+\.)?\d+(ms|s)\b", " in [EXECUTION_TIME]"),
(r"\\\\?([\w\d.])", "/$1"),
(r"rye.exe", "rye"),
];
Expand Down
39 changes: 39 additions & 0 deletions rye/tests/test_scripts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use toml_edit::value;

use crate::common::{rye_cmd_snapshot, Space};

mod common;

#[test]
fn test_basic_script() {
let mut settings = insta::Settings::clone_current();
settings.add_filter(r"(?m)(^py[a-z\d._]+$\r?\n)+", "[PYTHON SCRIPTS]\n");
let _guard = settings.bind_to_scope();

let space = Space::new();
space.init("my-project");
space.edit_toml("pyproject.toml", |doc| {
doc["tool"]["rye"]["scripts"]["test-script"] = value("python -c 'print(\"Hello World\")'");
});

rye_cmd_snapshot!(space.rye_cmd().arg("run").arg("test-script"), @r###"
success: true
exit_code: 0
----- stdout -----
Hello World
----- stderr -----
Initializing new virtualenv in [TEMP_PATH]/project/.venv
Python version: [email protected]
"###);

rye_cmd_snapshot!(space.rye_cmd().arg("run"), @r###"
success: true
exit_code: 0
----- stdout -----
[PYTHON SCRIPTS]
test-script (python -c 'print("Hello World")')
----- stderr -----
"###);
}

0 comments on commit 2fd1895

Please sign in to comment.