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

Export VIRTUAL_ENV when executing python inside a rye-managed project #1043

Closed
ma-sadeghi opened this issue Apr 24, 2024 · 7 comments
Closed

Comments

@ma-sadeghi
Copy link

ma-sadeghi commented Apr 24, 2024

Not sure if this was intentionally left out, but it'd be great if VIRTUAL_ENV was set when executing python inside a rye-managed project so third-party programs can still find the .venv path.

@ma-sadeghi ma-sadeghi changed the title Export VIRTUAL_ENV when executing python inside a rye-managed directory Export VIRTUAL_ENV when executing python inside a rye-managed project Apr 24, 2024
@bluss
Copy link
Contributor

bluss commented Apr 24, 2024

Do you have an example of a tool that is helped by this?

@ma-sadeghi
Copy link
Author

ma-sadeghi commented Apr 26, 2024

Yes, pyjuliapkg is the standard tool for managing Julia dependencies from Python (mostly used as part of juliacall for creating Python-Julia interface). It relies on VIRTUAL_ENV to decide where to put the Julia dependencies:

https://github.com/JuliaPy/pyjuliapkg/blob/main/src/juliapkg/state.py#L61

@bluss
Copy link
Contributor

bluss commented Apr 26, 2024

Just as extra information for context, most python tools don't need this since if the currently running python is in a virtual environment that can be detected and the recommended way to detect does not use VIRTUAL_ENV, instead something along these lines https://stackoverflow.com/a/1883251

When a virtual environment has been activated, the VIRTUAL_ENV environment variable is set to the path of the environment. Since explicitly activating a virtual environment is not required to use it, VIRTUAL_ENV cannot be relied upon to determine whether a virtual environment is being used.

https://docs.python.org/3/library/venv.html#how-venvs-work

Again, this is just context for the feature

@ma-sadeghi
Copy link
Author

Makes sense. I opened up a separate issue in the source repository to hopefully address it at root. Just to make sure I understood, would you still consider exporting VIRTUAL_ENV? or since it's not the proper way, you'd rather not? Thanks!

@bluss
Copy link
Contributor

bluss commented May 2, 2024

Maybe @mitsuhiko has better insight into what's best to do about that

@mitsuhiko
Copy link
Collaborator

We do set VIRTUAL_ENV for scripts, but not for Python itself. Reason being that python itself can discover the virtualenv with sys.prefix. I don't think it's correct for code to use anything other than that to discover virtualenvs.

@ma-sadeghi
Copy link
Author

I agree, and so do the the devs/maintainers of the conflicting package (pyjuliapkg). (And are willing to accept a PR that fixes the way virtualenv is identified.) So, I'm closing this issue. Thanks for the follow up :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants