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

fix: in project conda venv activate without argument #1735

Merged
merged 5 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions news/1735.doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support using `pdm venv activate` without specifying `env_name` to activate in project venv created by conda
6 changes: 6 additions & 0 deletions src/pdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ def get_venv_like_prefix(interpreter: str | Path) -> Path | None:
virtual_env = os.getenv("VIRTUAL_ENV", os.getenv("CONDA_PREFIX"))
if virtual_env and is_path_relative_to(interpreter, virtual_env):
return Path(virtual_env)

with contextlib.suppress(FileNotFoundError, subprocess.CalledProcessError):
envs = json.loads(subprocess.check_output(["conda", "env", "list", "--json"]))["envs"]
ProgramRipper marked this conversation as resolved.
Show resolved Hide resolved
for env in envs:
if is_path_relative_to(interpreter, env):
return Path(env)
return None


Expand Down