-
-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
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:
pythonfinder/src/pythonfinder/models/path.py
Lines 732 to 742 in dfac150
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).)
Metadata
Metadata
Assignees
Labels
No labels