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

chore: clean up runtime code for python setup #26042

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jdstrand
Copy link
Contributor

@jdstrand jdstrand commented Feb 19, 2025

ccd5d22 introduced working but temporary code for setting up the python runtime environment. This cleans that up:

  • refactor various find_python() functionality into virtualenv.rs
  • refactor PYTHONHOME calculation to virtualenv.rs:find_python_install()
  • adjust init_pyo3() to temporarily set PYTHONHOME based on virtualenv.rs:find_python_install() as this is the only place it is needed (indeed, venv activation scripts try to remove it)

Importantly, virtualenv.rs:find_python_install() tries to find the python build standalone runtime based on a few heuristics. This function could be improved in the fullness of time to, eg, be configured via a build parameter.

Also, virtualenv.rs:find_python() can be used pre and post venv activation. Before entering the venv, it will use find_python_install() which is useful for things like setting up the initial venv. After entering the venv, it will honor VIRTUAL_ENV (as set by virtualenv.rs:initialize_venv()) to find python, which is important for install packages with pip and having them installed into the venv.

Testing: this has been lightly tested (linux/amd64 and windows/amd64). If @jacksonrnewhouse is happy with the approach, I'll take in feedback and do a full round of testing.

Helps with #26012

@jdstrand
Copy link
Contributor Author

Testing: this has been lightly tested (linux/amd64 and windows/amd64). If @jacksonrnewhouse is happy with the approach, I'll take in feedback and do a full round of testing.

@jacksonrnewhouse - rebased on main and retested on linux/amd64. This is ready to review for the approach. If you're generally happy with it, I'll do full testing.

Copy link
Contributor

@jacksonrnewhouse jacksonrnewhouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

fn get_python_version() -> Result<(u8, u8), std::io::Error> {
// Find the python installation location (not virtual env).
// XXX: use build flag?
fn find_python_install() -> PathBuf {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have this return an Option<PathBuf> rather than an empty PathBuf.

@jdstrand
Copy link
Contributor Author

jdstrand commented Feb 21, 2025

@jacksonrnewhouse - thanks for the review! In doing further testing and looking at #26050, I need followup commits (which may end up fixing #26050 in the process).

UPDATE: I'm going to mark this as DRAFT just to be sure that it doesn't get committed before I have those ready.

@jdstrand jdstrand marked this pull request as draft February 21, 2025 19:02
@jdstrand
Copy link
Contributor Author

@jacksonrnewhouse - thanks for the review! In doing further testing and looking at #26050, I need followup commits (which may end up fixing #26050 in the process).

UPDATE: I'm going to mark this as DRAFT just to be sure that it doesn't get committed before I have those ready.

Since you approved, I'll take that to mean that you like the approach. When I have the follow-up commits ready, I'll do full testing and list it in this issue, then undraft.

ccd5d22 introduced working but temporary code for setting up the
python runtime environment. This cleans that up:

* refactor various find_python() functionality into virtualenv.rs
* refactor PYTHONHOME calculation to virtualenv.rs:find_python_install()
* adjust init_pyo3() to temporarily set PYTHONHOME based on
  virtualenv.rs:find_python_install() as this is the only place it is
  needed (indeed, venv activation scripts try to remove it)

Importantly, virtualenv.rs:find_python_install() tries to find the
python build standalone runtime based on a few heuristics. This function
could be improved in the fullness of time to, eg, be configured via a
build parameter.

Also, virtualenv.rs:find_python() can be used pre and post venv
activation. Before entering the venv, it will use find_python_install()
which is useful for things like setting up the initial venv. After
entering the venv, it will honor VIRTUAL_ENV (as set by
virtualenv.rs:initialize_venv()) to find python, which is important for
install packages with pip and having them installed into the venv.
@jdstrand jdstrand force-pushed the jdstrand/pe-standalone-cleanup branch from 87ae90e to c5c542d Compare February 21, 2025 19:11
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

Successfully merging this pull request may close these issues.

2 participants