Skip to content

Commit

Permalink
🐛 v2.7.5 Fix venv deactivation race conditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeares committed Dec 30, 2024
1 parent db76549 commit 05ef50a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion meerschaum/config/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Specify the Meerschaum release version.
"""

__version__ = "2.7.4"
__version__ = "2.7.5.dev1"
31 changes: 19 additions & 12 deletions meerschaum/utils/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,26 @@ def deactivate_venv(
if sys.path is None:
return False

target = venv_target_path(venv, allow_nonexistent=force, debug=debug).as_posix()
target = venv_target_path(venv, allow_nonexistent=True, debug=debug).as_posix()
with LOCKS['sys.path']:
if target in sys.path:
sys.path.remove(target)
try:
sys.path.remove(target)
except Exception:
pass
try:
active_venvs_order.remove(venv)
except Exception as e:
except Exception:
pass

return True


def is_venv_active(
venv: str = 'mrsm',
color : bool = True,
debug: bool = False
) -> bool:
venv: str = 'mrsm',
color : bool = True,
debug: bool = False
) -> bool:
"""
Check if a virtual environment is active.
Expand Down Expand Up @@ -663,10 +666,10 @@ def venv_exists(venv: Union[str, None], debug: bool = False) -> bool:


def venv_target_path(
venv: Union[str, None],
allow_nonexistent: bool = False,
debug: bool = False,
) -> 'pathlib.Path':
venv: Union[str, None],
allow_nonexistent: bool = False,
debug: bool = False,
) -> 'pathlib.Path':
"""
Return a virtual environment's site-package path.
Expand All @@ -683,7 +686,11 @@ def venv_target_path(
The `pathlib.Path` object for the virtual environment's path.
"""
import os, sys, platform, pathlib, site
import os
import sys
import platform
import pathlib
import site
from meerschaum.config._paths import VIRTENV_RESOURCES_PATH
from meerschaum.config.static import STATIC_CONFIG

Expand Down

0 comments on commit 05ef50a

Please sign in to comment.