Skip to content

Commit

Permalink
fix: in project conda venv activate without argument (#1735)
Browse files Browse the repository at this point in the history
* fix: in project conda venv activate without argument

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Create 1735.doc.md

* fix: FileNotFoundError when conda isn't installed

* fix: detect conda venv by checking conda-meta

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ProgramRipper and pre-commit-ci[bot] authored Mar 2, 2023
1 parent 6d8f19d commit 91d9a1e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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
8 changes: 6 additions & 2 deletions src/pdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,12 @@ def get_venv_like_prefix(interpreter: str | Path) -> Path | None:
and return the prefix if found.
"""
interpreter = Path(interpreter)
prefix = interpreter.parent.parent
if prefix.joinpath("pyvenv.cfg").exists():
prefix = interpreter.parent
if prefix.joinpath("conda-meta").exists():
return prefix

prefix = prefix.parent
if prefix.joinpath("pyvenv.cfg").exists() or prefix.joinpath("conda-meta").exists():
return prefix

virtual_env = os.getenv("VIRTUAL_ENV", os.getenv("CONDA_PREFIX"))
Expand Down

0 comments on commit 91d9a1e

Please sign in to comment.