-
Notifications
You must be signed in to change notification settings - Fork 327
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
Changes to how we pick which Python to use. #1419
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- change signature to make clear that `python` is resolved by `virtualenv_starter()` - add a `force` argument to `virtualenv_create()`, allowing for removing and recreating a new venv. - remove usage of `virtualenv_default_python()` due to infinite recursion via `py_discover_config()` bootsrapping a venv - add some comments
use `heredoc()` to make it more readable
I very much approve! |
kevinushey
approved these changes
Jul 20, 2023
- reflect hints from `import(,delay_load = )` correctly in `py_discover_config()` calls by default, rather than depending on them being provided as function arguments.
- use `brew` to install more dependencies - echo brew commands to console (they can take a while if brew hasn't updated itself in a while)
t-kalinowski
force-pushed
the
py-discover-config-v2
branch
from
July 22, 2023 12:22
c06a16a
to
c7a3824
Compare
t-kalinowski
force-pushed
the
py-discover-config-v2
branch
from
July 22, 2023 13:07
f081c67
to
4e58d43
Compare
- also, no longer prompt for miniconda
t-kalinowski
force-pushed
the
py-discover-config-v2
branch
from
July 25, 2023 11:24
c12a637
to
f4666fd
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adjusts the logic that reticulate uses to determine which python installation to load. The changes are mostly related to the choices reticulate makes in the absence of any concrete preference expressed by the user via
use_python()
,RETICULATE_PYTHON
, or similar.Previously, reticulate would prompt the user to install miniconda, bootstrap a "r-reticulate" conda environment, or go searching through all known venvs and conda envs for the presence of a requested module.
New behavior highlights:
No longer prompt to install miniconda. Instead, at a similar point in the order of discovery, we prompt the user to instead create a default "r-reticulate" venv.
We give higher precedence now to explicitly provided hints of the form:
import("bar", delay_load = list(environment = "r-barlyr")
use_python("/path/to/bin/python", required = FALSE)
We give higher precedence to module derived env names when we're initializing because of a call to import that module. In other words, in the absence of more a more concrete expression of preference (
RETICULATE_PYTHON
env var,use_python(required = TRUE)
, etc) if the user callsimport("scipy")
, and there exists an environment"r-scipy"
, we use it.If there is no suitable python installation to create a venv from, we ask the user to install python manually, suggesting options:
reticulate::install_python()
,www.python.org/downloads/
,RETICULATE_VIRTUALENV_STARTER
andoption("reticulate.virtualenv.starter")
which users can use for pointing reticulate at suitable venv starters, encoded in the functionvirtualenv_starter()
, though this should be not needed by most users.We no longer scan all known pythons. Absent any expression of preference for a particular python from the user, we fall back to a
r-reticulate
venv, or if user explicitly opts out of that, to the python on the PATH.The previous approach went to great lengths to succeed in finding a Python that satisfied a particular
import()
call, and often did. However, the search behavior made predicting which python installation would be found very difficult, and subject to change as the environments on the system changed. Now we no longer use the presence of an installed module as criteria for selecting a particular python installation.This is the new order of precedence for selecting a python:
RETICULATE_PYTHON
env var (path to python binary)RETICULATE_PYTHON_ENV
env var (path to venv or condaenv directory, or bare name of venv or conda env) (previously this only accepted a full path)use_python(required = TRUE)
call (and related,use_virtualenv()
,use_condaenv()
)Presence of a
pyproject.toml
file from a poetry environment in the current working directoryPresence of a pipfile associated with a pipenv in the current working directory
If there was a call
import("bar", delay_load = list(environment = "r-barlyr")
, and there exists an environment named "r-barlyr", use it.use_python(required = FALSE)
If there was a call
import("bar")
, and there exists an environment namedr-bar
, use that.If we're running under an activated virtualenv (i.e., the
python
on the PATH is a virtualenv, use that).env var
RETICULATE_PYTHON_FALLBACK
In the absence of any expression of preference from the user, (via one of the ways outlined above) we fallback to using a
r-reticulate
virtual environment. If one does not exist, we prompt the user to create one.If the user declines to use the "r-reticulate" environment, then we fall back to using the python on the PATH.