Skip to content

Commit

Permalink
Self heal invalid cache files.
Browse files Browse the repository at this point in the history
  • Loading branch information
vijairaj authored and junkmd committed Aug 1, 2022
1 parent f406cee commit 0d783c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions comtypes/client/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import comtypes.client
import comtypes.tools.codegenerator
import imp

import logging
logger = logging.getLogger(__name__)
Expand All @@ -23,7 +24,11 @@ def _my_import(fullname):
if comtypes.client.gen_dir \
and comtypes.client.gen_dir not in comtypes.gen.__path__:
comtypes.gen.__path__.append(comtypes.client.gen_dir)
return __import__(fullname, globals(), locals(), ['DUMMY'])

mod = imp.reload(eval(fullname)) if fullname in sys.modules \
else __import__(fullname, globals(), locals(), ['DUMMY'])
mod._comtypes_validate_file()
return mod

def _name_module(tlib):
# Determine the name of a typelib wrapper module.
Expand Down Expand Up @@ -152,8 +157,10 @@ def _CreateWrapper(tlib, pathname=None):
# helper which creates and imports the real typelib wrapper module.
fullname = _name_module(tlib)
try:
return sys.modules[fullname]
except KeyError:
mod = sys.modules[fullname]
mod._comtypes_validate_file()
return mod
except (KeyError, AttributeError):
pass

modname = fullname.split(".")[-1]
Expand Down
3 changes: 2 additions & 1 deletion comtypes/tools/codegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def generate_code(self, items, filename=None):
for line in wrapper.wrap(text):
print >> self.output, line
print >> self.output, "from comtypes import _check_version; _check_version(%r)" % version
print >> self.output, "def _comtypes_validate_file(): pass"
return loops

def type_name(self, t, generate=True):
Expand Down Expand Up @@ -627,7 +628,7 @@ def External(self, ext):
modname = comtypes.client._generate._name_module(ext.tlib)
ext.name = "%s.%s" % (modname, ext.symbol_name)
self._externals[libdesc] = modname
print >> self.imports, "import", modname
print >> self.imports, "import %s; %s._comtypes_validate_file()" % (modname, modname)
comtypes.client.GetModule(ext.tlib)

def Constant(self, tp):
Expand Down

0 comments on commit 0d783c6

Please sign in to comment.