Skip to content

Commit

Permalink
Fix problem with pytest plugin when AnyBody is not installed (#109)
Browse files Browse the repository at this point in the history
* Update pixi config

* Don't mess up pytest runs on machines with no AnyBody installed

* Update pixi config

* Update version

* Recognize AnyBody 8 intallations in registry

* Add changelog entry
  • Loading branch information
melund authored Feb 6, 2024
1 parent 014dfd6 commit 98977e5
Show file tree
Hide file tree
Showing 5 changed files with 1,954 additions and 3,867 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# AnyPyTools Change Log

## v1.11.3

**Added:**

* Correctly detect installations of AnyBody version 8 on the machines.

**Fixed:**

* Allow the pytest plugin to work even if the machine doesn't have AnyBody installed.


## v1.11.2

**Fixed:**
Expand Down
2 changes: 1 addition & 1 deletion anypytools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"NORMAL_PRIORITY_CLASS",
]

__version__ = "1.11.2"
__version__ = "1.11.3"


def print_versions():
Expand Down
30 changes: 20 additions & 10 deletions anypytools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,25 @@ def _expand_short_path_name(short_path_name):
return long_path_name


def lookup_anybody_in_registry() -> str | None:
import winreg

keys_to_try = [
"AnyBody.any\\shell\\open\\command",
"AnyBody.AnyScript\\shell\\open\\command",
]
for key in keys_to_try:
try:
value = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, key)
except WindowsError:
continue
anybodypath = value.rsplit(" ", 1)[0].strip('"')
return os.path.join(os.path.dirname(anybodypath), "AnyBodyCon.exe")

warnings.warn("Could not locate AnyBody in registry")
return ""


def get_anybodycon_path() -> str | None:
"""Return the path to default AnyBody console application.
If AnyBodyCon.exe is on path it will take precedence over
Expand All @@ -543,16 +562,7 @@ def get_anybodycon_path() -> str | None:
else:
return None

import winreg

try:
abpath = winreg.QueryValue(
winreg.HKEY_CLASSES_ROOT, "AnyBody.AnyScript\\shell\\open\\command"
)
except WindowsError:
raise WindowsError("Could not locate AnyBody in registry")
abpath = abpath.rsplit(" ", 1)[0].strip('"')
anybodycon_path = os.path.join(os.path.dirname(abpath), "AnyBodyCon.exe")
anybodycon_path = lookup_anybody_in_registry()
if "~" in anybodycon_path:
anybodycon_path = _expand_short_path_name(anybodycon_path)
return anybodycon_path
Expand Down
Loading

0 comments on commit 98977e5

Please sign in to comment.