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

Don't treat the conda root env as an env #324

Merged
merged 8 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion jupyter_core/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def prefer_environment_over_user() -> bool:
return True

# If sys.prefix indicates Python comes from a conda/mamba environment, default to True
minrk marked this conversation as resolved.
Show resolved Hide resolved
if "CONDA_PREFIX" in os.environ and sys.prefix.startswith(os.environ["CONDA_PREFIX"]):
if (
"CONDA_PREFIX" in os.environ
and sys.prefix.startswith(os.environ["CONDA_PREFIX"])
and os.environ.get("CONDA_ROOT") != os.environ["CONDA_PREFIX"]
):
return True

return False
Expand Down
19 changes: 15 additions & 4 deletions jupyter_core/tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,21 @@ def test_prefer_environment_over_user():

# Test default if environment variable is not set, and try to determine if we are in a virtual environment
os.environ.pop("JUPYTER_PREFER_ENV_PATH", None)
in_venv = sys.prefix != sys.base_prefix or (
"CONDA_PREFIX" in os.environ and sys.prefix.startswith(os.environ["CONDA_PREFIX"])
)
assert prefer_environment_over_user() is in_venv
# base prefix differs, venv
with patch.object(sys, "base_prefix", "notthesame"):
assert prefer_environment_over_user()

# conda
with patch.object(sys, "base_prefix", sys.prefix):
# in root env, don't prefer it
with patch.dict(os.environ, {"CONDA_PREFIX": sys.prefix, "CONDA_ROOT": sys.prefix}):
assert not prefer_environment_over_user()
# in non-root env, prefer it
with patch.dict(os.environ, {"CONDA_PREFIX": sys.prefix, "CONDA_ROOT": "/tmp"}):
assert prefer_environment_over_user()
# conda env defined, but we aren't using it
with patch.dict(os.environ, {"CONDA_PREFIX": "/somewherelese", "CONDA_ROOT": "/tmp"}):
assert not prefer_environment_over_user()


def test_is_hidden():
Expand Down