Skip to content

Commit

Permalink
Fix attributeerror from uninstalled pythons
Browse files Browse the repository at this point in the history
- Fixes #26

Signed-off-by: Dan Ryan <dan@danryan.co>
  • Loading branch information
techalchemy committed Nov 3, 2018
1 parent dc974b6 commit bbac068
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/26.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug with searching windows registry entries which sometimes caused errors for uninstalled python instances.
13 changes: 13 additions & 0 deletions src/pythonfinder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ def cli(ctx, find=False, which=False, findall=False, version=False, ignore_unsup
click.secho("Searching for python: {0!s}".format(find.strip()), fg="yellow")
found = finder.find_python_version(find.strip())
if found:
py = found.py_version
comes_from = getattr(py, "comes_from", None)
if comes_from is not None:
comes_from_path = getattr(comes_from, "path", found.path)
else:
comes_from_path = found.path
arch = getattr(py, "architecture", None)
click.secho("Found python at the following locations:", fg="green")
click.secho(
"{py.name!s}: {py.version!s} ({py.architecture!s}) @ {comes_from!s}".format(
py=py, comes_from=comes_from_path
),
fg="yellow",
)
sys.exit(0)
else:
click.secho("Failed to find matching executable...", fg="yellow")
Expand Down
5 changes: 4 additions & 1 deletion src/pythonfinder/models/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def get_versions(self):
install_path = getattr(version_object.info, "install_path", None)
if install_path is None:
continue
path = ensure_path(install_path.__getattr__(""))
try:
path = ensure_path(install_path.__getattr__(""))
except AttributeError:
continue
try:
py_version = PythonVersion.from_windows_launcher(version_object)
except InvalidPythonVersion:
Expand Down

0 comments on commit bbac068

Please sign in to comment.