sixty-north / venv-management

A Python package for programmatic creation of Python virtual environments
MIT License
0 stars 1 forks source link

Misleading error message when requested Python doesn't exist #5

Closed abingham closed 2 years ago

abingham commented 2 years ago

When a call to ensure_virtual_env specifies a Python version that isn't available, the resulting exception isn't very informative. Here's an example of what I've seen:

Could not find dest for virtualenv {name!r}Traceback (most recent call last):
  File "/Users/sixtynorth/.virtualenvs/visning-server-metaclasses-and-allocations/lib/python3.9/site-packages/venv_management/api.py", line 182, in ensure_virtual_env
    env_dirpath = resolve_virtual_env(name)
  File "/Users/sixtynorth/.virtualenvs/visning-server-metaclasses-and-allocations/lib/python3.9/site-packages/venv_management/api.py", line 126, in resolve_virtual_env
    return driver().resolve_virtual_env(name)
  File "/Users/sixtynorth/.virtualenvs/visning-server-metaclasses-and-allocations/lib/python3.9/site-packages/venv_management/ext/drivers/virtualenvwrapper/driver.py", line 177, in resolve_virtual_env
    raise ValueError(f"No virtual environment called {name!r} to remove")
ValueError: No virtual environment called 'tracing-meta' to remove

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sixtynorth/.virtualenvs/visning-server-metaclasses-and-allocations/lib/python3.9/site-packages/visning/ext/masters/code_editor/slide.py", line 339, in invoke_preparation_delegate
    result = delegate(**kwargs)
  File "/private/var/folders/w6/qkh4q3552ys824_lndfl38x00000gn/T/tmpn49lmsru/extracted/tracing-meta-demo/fragments.py", line 6, in prepare
    idea.ensure_virtual_env("tracing-meta", "3.10")
  File "/Users/sixtynorth/.virtualenvs/visning-server-metaclasses-and-allocations/lib/python3.9/site-packages/replay_python/idea.py", line 2438, in ensure_virtual_env
    env_path = venv_management.ensure_virtual_env(name, python_version)
  File "/Users/sixtynorth/.virtualenvs/visning-server-metaclasses-and-allocations/lib/python3.9/site-packages/venv_management/api.py", line 185, in ensure_virtual_env
    env_dirpath = make_virtual_env(name, python=python_arg, **kwargs)
  File "/Users/sixtynorth/.virtualenvs/visning-server-metaclasses-and-allocations/lib/python3.9/site-packages/venv_management/api.py", line 100, in make_virtual_env
    return driver().make_virtual_env(
  File "/Users/sixtynorth/.virtualenvs/visning-server-metaclasses-and-allocations/lib/python3.9/site-packages/venv_management/ext/drivers/virtualenvwrapper/driver.py", line 140, in make_virtual_env
    raise RuntimeError(message)
RuntimeError: Could not find dest for virtualenv {name!r}

I'm not sure what's to be done about it, but I wanted to record this.

In this case the call was requesting a Python 3.10 when only Python 3.9 was available.

rob-smallshire commented 2 years ago

Definitely room for improvement there. I’ll see what I can do.

rob-smallshire commented 2 years ago

Fixed in 1.6.0. Now raises a PythonNotFoundError with a more helpful message. "Could not locate Python {}"