astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
12.08k stars 425 forks source link

rye run -l prints to stderr #1136

Open engeir opened 3 weeks ago

engeir commented 3 weeks ago

Steps to Reproduce

  1. create a script in the [project.scripts] section, or rye add a package with entry points.
  2. run rye run -l (or rye run) to see the list of available entry points
  3. grep for specific entry point rye run -l | grep "my-entrypoint"

Expected Result

I would expect in step 3 to be able to grep against the list of available entry points. If not from rye run, then at least from rye run -l/rye run --list.

Actual Result

rye run -l output to stderr, so all entry points are printed and then a non-zero exit code occur due to no grep matches.

rye run -l 2>&1 | grep "my-entrypoint" will give the desired result.

Version Info

rye 0.34.0 commit: 0.34.0 (d31340178 2024-05-20) platform: linux (x86_64) self-python: cpython@3.12.1 symlink support: true uv enabled: true

Stacktrace

No response

Zander-1024 commented 3 weeks ago

https://github.com/astral-sh/rye/pull/342 pub fn execute(cmd: Args) -> Result<(), Error> { let _guard = redirect_to_stderr(true); I'm not sure if this issue should be fixed, because it seems to be intentional by the developers, or maybe it's a mistake.

engeir commented 3 weeks ago

Aha, I see! It was opposite to the behaviour I expected so I figured it was just overlooked, but feel free to close if it isn't really an issue.

zanieb commented 3 weeks ago

I would probably expect this to be written to stdout, personally.

Zander-1024 commented 3 weeks ago

I would probably expect this to be written to stdout, personally. I think so, I will try to submit a PR, but still have to see the administrator to accept or not.

Woovie commented 3 weeks ago

This is definitely a very opinionated topic. Personally I prefer STDERR to keep it separate from STDOUT. This is standard for a lot of applications, like strace as a fine example. 2&>1 | is not too hard write to enable you grepping through the output from my POV.

zanieb commented 3 weeks ago

@Woovie what's to be kept separate from STDOUT though? The entire output of rye run -l is a list of commands which is meaningful data that could be piped to another tool as is the intent of STDOUT. Think about if there were some log messages output by Rye while determining what the list of commands is — that'd go to STDERR and should not be piped to another program. If you just combine STDERR / STDOUT you're unable to discern which information is relevant.