Skip to content

Commit

Permalink
Fix comInterfaces_sconscript to no longer fail on wrapper module crea…
Browse files Browse the repository at this point in the history
…tion (nvaccess#10235)

* Fix comInterfaces_sconscript to no longer fail on creation

* Monkeypatch instead
  • Loading branch information
LeonarddeR authored and michaelDCurran committed Sep 18, 2019
1 parent 340291b commit e77dcbd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions sconstruct
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def recursiveCopy(env,targetDir,sourceDir):
import gettext
gettext.install("nvda")
sys.path.append("source")
import comtypesMonkeyPatches
import versionInfo
del sys.path[-1]

Expand Down
4 changes: 1 addition & 3 deletions source/comInterfaces_sconscript
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ interfaceBuilder=env.Builder(
)
env['BUILDERS']['comtypesInterface']=interfaceBuilder

#Bit of a dance to force comtypes generated interfaces in to our directory
# Force comtypes generated interfaces in to our directory
import comtypes.client
comtypes.client.gen_dir=Dir('comInterfaces').abspath
import sys
sys.modules['comtypes.gen']=comtypes.gen=__import__("comInterfaces",globals(),locals(),[])

COM_INTERFACES = {
"IAccessible2Lib.py": "typelibs/ia2.tlb",
Expand Down
22 changes: 18 additions & 4 deletions source/comtypesMonkeyPatches.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2009-2016 NV Access Limited
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2009-2019 NV Access Limited, Babbage B.V.
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

import ctypes
import _ctypes
import importlib
import comtypes.client._generate

# A version of ctypes.WINFUNCTYPE
# that produces a WinFunctionType class whose instance will convert COMError into a CallCancelled exception when called as a function.
Expand Down Expand Up @@ -125,3 +127,15 @@ def _check_version(actual):
if actual != required:
raise ImportError("Wrong version")
comtypes._check_version = _check_version


# Monkeypatch comtypes to clear the importlib cache when importing a new module
old_my_import = comtypes.client._generate._my_import


def new_my_import(fullname):
importlib.invalidate_caches()
return old_my_import(fullname)


comtypes.client._generate._my_import = new_my_import

0 comments on commit e77dcbd

Please sign in to comment.