Skip to content
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

Detect if a script is called with uv run #8775

Closed
samuelcolvin opened this issue Nov 3, 2024 · 7 comments
Closed

Detect if a script is called with uv run #8775

samuelcolvin opened this issue Nov 3, 2024 · 7 comments
Labels
enhancement New feature or improvement to existing functionality

Comments

@samuelcolvin
Copy link

I'd like to know if my script was called with uv run, but there doesn't seem to be an obvious way to tell.

I suggest you set an extra environment variable (e.g. UV=1) which the process can use to check if it was called that way.

(My use case if it matters is that I'm printing instructions on how to run other scripts, and I'd like to show "Run with uv run -m ..." or "Run with python -m ...")

@zanieb zanieb added the enhancement New feature or improvement to existing functionality label Nov 3, 2024
@zanieb
Copy link
Member

zanieb commented Nov 3, 2024

Seems fine to me, though I'm a little wary of people keying behavior off of executing in a uv context in general.

@charliermarsh
Copy link
Member

This could also be helpful for the infinitely-recursive shebang @zanieb...

@zanieb
Copy link
Member

zanieb commented Nov 4, 2024

True I basically suggested this as a solution. Though the problem there is we can't tell if the recursion is intentional or not without capturing more information.

@samuelcolvin
Copy link
Author

Your could increment the count in the env car, so UV=1, UV=2 etc.

@samuelcolvin
Copy link
Author

Fwiw, (maybe supports @zanieb's point) I no longer need this right now. Although I think adding the env var is still a good idea.

@konstin
Copy link
Member

konstin commented Nov 12, 2024

This sounds like something that would fit nicely into the sys module, similar sys.orig_argv

@zanieb
Copy link
Member

zanieb commented Feb 13, 2025

Closed in #11326

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality
Projects
None yet
Development

No branches or pull requests

4 participants