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

InvalidPythonVersion with dangling symlink via Finder.find_all_python_versions #100

Open
blueyed opened this issue May 7, 2021 · 0 comments

Comments

@blueyed
Copy link

blueyed commented May 7, 2021

Given a dangling symlink in a $PATH entry you will get an error:

t.py:

from pythonfinder import Finder

finder = Finder()
print(finder.find_all_python_versions())
% python t.py
Traceback (most recent call last):
  File "…/Vcs/pythonfinder/t.py", line 4, in <module>
    print(finder.find_all_python_versions())
  File "…/Vcs/pythonfinder/src/pythonfinder/pythonfinder.py", line 322, in find_all_python_versions
    versions = self.system_path.find_all_python_versions(
  File "…/Vcs/pythonfinder/src/pythonfinder/models/path.py", line 547, in find_all_python_versions
    values = list(self.get_pythons(sub_finder))
  File "…/Vcs/pythonfinder/src/pythonfinder/models/path.py", line 505, in get_pythons
    pythons = [entry for entry in self._get_all_pythons(finder)]
  File "…/Vcs/pythonfinder/src/pythonfinder/models/path.py", line 505, in <listcomp>
    pythons = [entry for entry in self._get_all_pythons(finder)]
  File "…/Vcs/pythonfinder/src/pythonfinder/models/path.py", line 498, in _get_all_pythons
    for python in self._filter_paths(finder):
  File "…/Vcs/pythonfinder/src/pythonfinder/models/path.py", line 490, in _filter_paths
    python_versions = finder(path)
  File "…/Vcs/pythonfinder/src/pythonfinder/models/mixins.py", line 330, in find_all_python_versions
    unnested = [sub_finder(path) for path in expand_paths(self)]
  File "…/Vcs/pythonfinder/src/pythonfinder/models/mixins.py", line 330, in <listcomp>
    unnested = [sub_finder(path) for path in expand_paths(self)]
  File "…/Vcs/pythonfinder/src/pythonfinder/utils.py", line 433, in expand_paths
    for p in path.children.values():
  File "…/Vcs/pythonfinder/src/pythonfinder/models/path.py", line 751, in children
    for child_key, child_val in self._gen_children():
  File "…/Vcs/pythonfinder/src/pythonfinder/models/path.py", line 742, in _gen_children
    entry = PathEntry.create(path=child, **pass_args)  # type: ignore
  File "…/Vcs/pythonfinder/src/pythonfinder/models/path.py", line 782, in create
    raise InvalidPythonVersion("Python interpreter does not exist: {}".format(target))
pythonfinder.exceptions.InvalidPythonVersion: Python interpreter does not exist: /home/user/bin/calm

It appears that a check for a non-existent file / danging symlink should happen in the calling code already maybe:

elif self.is_root:
for child in self._filter_children():
if any(is_in_path(str(child), shim) for shim in shim_paths):
continue
if self.only_python:
try:
entry = PathEntry.create(path=child, **pass_args) # type: ignore
except (InvalidPythonVersion, ValueError):
continue
else:
entry = PathEntry.create(path=child, **pass_args) # type: ignore

But then it is also not clear to me how/if that is related to the PathEntry being a root entry in the first place, i.e. take this hint with a lot of salt.. ;)

(btw: this also happens with Finder.find_python_version as with the example in the README (https://github.com/sarugaku/pythonfinder/blob/dfac150ffeaccbcb3c2867c5429b38b568d85a8d/README.rst#usage).)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant