Skip to content

Commit

Permalink
fix: prevent crash when venv isn't activated correctly (DEV-3233) (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Jan 25, 2024
1 parent 03213ed commit 6d339ed
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/dsp_tools/cli/entry_point.py
Expand Up @@ -119,8 +119,13 @@ def _parse_arguments(


def _get_version() -> str:
result = subprocess.run("pip freeze".split(), check=False, capture_output=True).stdout.decode("utf-8")
_detail_version = next(x for x in result.split("\n") if "dsp-tools" in x)
pip_freeze_output = subprocess.run("pip freeze".split(), check=False, capture_output=True).stdout.decode("utf-8")
dsp_tools_lines = [x for x in pip_freeze_output.split("\n") if "dsp-tools" in x]
if not dsp_tools_lines:
# if the virtual environment was activated with env variables instead of executing activation commands,
# dsp-tools will run correctly, but "pip freeze" won't show dsp-tools
return version("dsp-tools")
_detail_version = dsp_tools_lines[0]
# _detail_version has one of the following formats:
# - 'dsp-tools==5.0.3\n'
# - 'dsp-tools==5.6.0.post9\n'
Expand Down

0 comments on commit 6d339ed

Please sign in to comment.