Skip to content

Commit 3ba0bb2

Browse files
authored
Merge 98469c2 into 9c5130f
2 parents 9c5130f + 98469c2 commit 3ba0bb2

7 files changed

Lines changed: 49 additions & 34 deletions

File tree

source/addonHandler/__init__.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def initialize():
168168
getAvailableAddons(refresh=True, isFirstLoad=True)
169169
state.cleanupRemovedDisabledAddons()
170170
state.save()
171+
initializeModulePackagePaths()
171172

172173

173174
def terminate():
@@ -602,6 +603,54 @@ def _translatedManifestPaths(lang=None, forBundle=False):
602603
return [sep.join(("locale", lang, MANIFEST_FILENAME)) for lang in langs]
603604

604605

606+
def initializeModulePackagePaths():
607+
"""Initializes the module package paths for drivers and plugins.
608+
This ensures that drivers (such as braille display drivers) or plugins (such as app modules)
609+
can be discovered by NVDA.
610+
"""
611+
import appModules
612+
import brailleDisplayDrivers
613+
import globalPlugins
614+
import synthDrivers
615+
import visionEnhancementProviders
616+
modules = [
617+
appModules,
618+
brailleDisplayDrivers,
619+
globalPlugins,
620+
synthDrivers,
621+
visionEnhancementProviders,
622+
]
623+
for module in modules:
624+
addDirsToPythonPackagePath(module)
625+
626+
627+
def addDirsToPythonPackagePath(module: ModuleType, subdir: typing.Optional[str] = None):
628+
"""Add add-on and scratchpath directories for a module to the search path (__path__) of a Python package.
629+
C{subdir} is added to each directory. It defaults to the name of the Python package.
630+
@param module: The root module of the package.
631+
@param subdir: The subdirectory to be used, C{None} for the name of C{module}.
632+
"""
633+
if config.isAppX or globalVars.appArgs.disableAddons:
634+
return
635+
for addon in getRunningAddons():
636+
addon.addToPackagePath(module)
637+
if globalVars.appArgs.secure or not config.conf['development']['enableScratchpadDir']:
638+
return
639+
if not subdir:
640+
subdir = module.__name__
641+
fullPath = os.path.join(config.getScratchpadDir(), subdir)
642+
if fullPath in module.__path__:
643+
return
644+
# Ensure this directory exists otherwise pkgutil.iter_importers may emit None for missing paths.
645+
if not os.path.isdir(fullPath):
646+
os.makedirs(fullPath)
647+
# Insert this path at the beginning of the module's search paths.
648+
# The module's search paths may not be a mutable list, so replace it with a new one
649+
pathList = [fullPath]
650+
pathList.extend(module.__path__)
651+
module.__path__ = pathList
652+
653+
605654
class AddonBundle(AddonBase):
606655
""" Represents the contents of an NVDA addon suitable for distribution.
607656
The bundle is compressed using the zip file format. Manifest information

source/appModuleHandler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ def reloadAppModules():
361361
def initialize():
362362
"""Initializes the appModule subsystem.
363363
"""
364-
config.addConfigDirsToPythonPackagePath(appModules)
365364
if not initialize._alreadyInitialized:
366365
initialize._alreadyInitialized = True
367366

source/braille.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,6 @@ def func(cls):
23932393

23942394
def initialize():
23952395
global handler
2396-
config.addConfigDirsToPythonPackagePath(brailleDisplayDrivers)
23972396
log.info("Using liblouis version %s" % louis.version())
23982397
import serial
23992398
log.info("Using pySerial version %s"%serial.VERSION)

source/config/__init__.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -474,35 +474,6 @@ def setStartOnLogonScreen(enable: bool) -> None:
474474
raise RuntimeError("Slave failed to set startOnLogonScreen")
475475

476476

477-
def addConfigDirsToPythonPackagePath(module, subdir=None):
478-
"""Add the configuration directories to the module search path (__path__) of a Python package.
479-
C{subdir} is added to each configuration directory. It defaults to the name of the Python package.
480-
@param module: The root module of the package.
481-
@type module: module
482-
@param subdir: The subdirectory to be used, C{None} for the name of C{module}.
483-
@type subdir: str
484-
"""
485-
if isAppX or globalVars.appArgs.disableAddons:
486-
return
487-
# FIXME: this should not be coupled to the config module....
488-
import addonHandler
489-
for addon in addonHandler.getRunningAddons():
490-
addon.addToPackagePath(module)
491-
if globalVars.appArgs.secure or not conf['development']['enableScratchpadDir']:
492-
return
493-
if not subdir:
494-
subdir = module.__name__
495-
fullPath=os.path.join(getScratchpadDir(),subdir)
496-
# Ensure this directory exists otherwise pkgutil.iter_importers may emit None for missing paths.
497-
if not os.path.isdir(fullPath):
498-
os.makedirs(fullPath)
499-
# Insert this path at the beginning of the module's search paths.
500-
# The module's search paths may not be a mutable list, so replace it with a new one
501-
pathList=[fullPath]
502-
pathList.extend(module.__path__)
503-
module.__path__=pathList
504-
505-
506477
def _transformSpec(spec: ConfigObj):
507478
"""To make the spec less verbose, transform the spec:
508479
- Add default="default" to all featureFlag items. This is required so that the key can be read,

source/globalPluginHandler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def listPlugins():
2727
yield plugin
2828

2929
def initialize():
30-
config.addConfigDirsToPythonPackagePath(globalPlugins)
3130
for plugin in listPlugins():
3231
try:
3332
runningPlugins.add(plugin())

source/synthDriverHandler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ def _get_initialSettingsRingSetting(self):
375375

376376

377377
def initialize():
378-
config.addConfigDirsToPythonPackagePath(synthDrivers)
379378
config.post_configProfileSwitch.register(handlePostConfigProfileSwitch)
380379

381380

source/vision/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
def initialize() -> None:
2222
global handler
23-
config.addConfigDirsToPythonPackagePath(visionEnhancementProviders)
2423
handler = VisionHandler()
2524

2625

0 commit comments

Comments
 (0)