Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nvaccess/nvda
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofdusk committed Sep 30, 2020
2 parents ba42885 + 40e1d07 commit 6850cb1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions source/addonHandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,19 +512,22 @@ def getCodeAddon(obj=None, frameDist=1):
obj = sys._getframe(frameDist)
fileName = inspect.getfile(obj)
assert os.path.isabs(fileName), f"Module file name {fileName} is not absolute"
dir = os.path.dirname(fileName)
dir = os.path.normpath(os.path.dirname(fileName))
# if fileName is not a subdir of one of the addon paths
# It does not belong to an addon.
for p in _getDefaultAddonPaths():
if dir.startswith(p):
addonsPath = None
for addonsPath in _getDefaultAddonPaths():
addonsPath = os.path.normpath(addonsPath)
if dir.startswith(addonsPath):
break
else:
raise AddonError("Code does not belong to an addon package.")
assert addonsPath is not None
curdir = dir
while curdir not in _getDefaultAddonPaths():
while curdir.startswith(addonsPath) and len(curdir) > len(addonsPath):
if curdir in _availableAddons:
return _availableAddons[curdir]
curdir = os.path.join(curdir, "..")
curdir = os.path.normpath(os.path.join(curdir, ".."))
# Not found!
raise AddonError("Code does not belong to an addon")

Expand Down

0 comments on commit 6850cb1

Please sign in to comment.