From af482e102fc623607577b49b9cad4e3c3e30483d Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Sun, 31 Jan 2021 13:05:36 -0800 Subject: [PATCH 1/4] Louis helper: update copyright header --- source/louisHelper.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/louisHelper.py b/source/louisHelper.py index c89064a03cc..08b7999b5b2 100644 --- a/source/louisHelper.py +++ b/source/louisHelper.py @@ -1,8 +1,8 @@ -#louisHelper.py -#A part of NonVisual Desktop Access (NVDA) -#This file is covered by the GNU General Public License. -#See the file COPYING for more details. -#Copyright (C) 2018 NV Access Limited, Babbage B.V. +# louisHelper.py +# A part of NonVisual Desktop Access (NVDA) +# This file is covered by the GNU General Public License. +# See the file COPYING for more details. +# Copyright (C) 2018-2021 NV Access Limited, Babbage B.V., Joseph Lee """Helper module to ease communication to and from liblouis.""" From 714db9ca3a26d58c13f529fce4eb09e386451e2b Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Sun, 31 Jan 2021 13:08:10 -0800 Subject: [PATCH 2/4] Louis helper/Python 3.8: call os.add_dll_directory when importing libluis DLL. Python 3.8 adds os.add_dll_directory to securely load DLL's from known locations, which affects Louis helper when trying to load liblouis.dll from NVDA executable folder. Therefore add NVDA executable path to known DLL directories through os.add_dll_directory, which resolves ModuleNotFoundError. --- source/louisHelper.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/louisHelper.py b/source/louisHelper.py index 08b7999b5b2..ab1b342c017 100644 --- a/source/louisHelper.py +++ b/source/louisHelper.py @@ -6,7 +6,11 @@ """Helper module to ease communication to and from liblouis.""" -import louis +# Python 3.8 changes the way DLL's are loaded due to security. +# Thus manually add NVDA executable path to DLL lookup path for loading liblouis.dll. +import os +with os.add_dll_directory(os.path.dirname(__file__)): + import louis from logHandler import log import config From 129c8477aa9b424bd06cfcf6d0ca0127e1a6a9f5 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Sat, 6 Feb 2021 11:16:25 -0800 Subject: [PATCH 3/4] Louis helper: remove header comment, use globalVars.appDir as executable path. Reviewed by Lukasz Golonka: remove file name from header comment. Also, because __file__ will point to library.zip, use globalVars.appDir to locate NVDA executable where liblouis.dll actually resides. --- source/louisHelper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/louisHelper.py b/source/louisHelper.py index ab1b342c017..6be30bbc7d4 100644 --- a/source/louisHelper.py +++ b/source/louisHelper.py @@ -1,4 +1,3 @@ -# louisHelper.py # A part of NonVisual Desktop Access (NVDA) # This file is covered by the GNU General Public License. # See the file COPYING for more details. @@ -9,7 +8,8 @@ # Python 3.8 changes the way DLL's are loaded due to security. # Thus manually add NVDA executable path to DLL lookup path for loading liblouis.dll. import os -with os.add_dll_directory(os.path.dirname(__file__)): +import globalVars +with os.add_dll_directory(os.path.dirname(globalVars.appDir)): import louis from logHandler import log import config From e9fbce047c8509a72fdc24a658ef36ef91a81cad Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Sat, 13 Feb 2021 13:09:05 -0800 Subject: [PATCH 4/4] Louis helper: use globalVars.appDir directly rather than going through os.path.dirname. Pointed out by Lukasz Golonka: globalVars.appDir records the actual path to the executable, including in source code version (nvda.pyw). Therefore use app dir directly. --- source/louisHelper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/louisHelper.py b/source/louisHelper.py index 6be30bbc7d4..533086d19c6 100644 --- a/source/louisHelper.py +++ b/source/louisHelper.py @@ -9,7 +9,7 @@ # Thus manually add NVDA executable path to DLL lookup path for loading liblouis.dll. import os import globalVars -with os.add_dll_directory(os.path.dirname(globalVars.appDir)): +with os.add_dll_directory(globalVars.appDir): import louis from logHandler import log import config