From b7e47afd118c36015cbbe8abf7bd22813896b6d4 Mon Sep 17 00:00:00 2001 From: Vasily Ryabov Date: Sun, 28 Feb 2021 17:42:00 +0300 Subject: [PATCH] Handle case if typelib path is not set. --- comtypes/tools/codegenerator.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/comtypes/tools/codegenerator.py b/comtypes/tools/codegenerator.py index 918184bc..4f7caa07 100644 --- a/comtypes/tools/codegenerator.py +++ b/comtypes/tools/codegenerator.py @@ -261,12 +261,15 @@ def generate_code(self, items, filename=None): for line in wrapper.wrap(text): print >> self.output, line - # get full path to DLL first (os.stat can't work with relative DLL paths properly) - loaded_typelib = comtypes.typeinfo.LoadTypeLib(self.filename) - full_filename = comtypes.tools.tlbparser.get_tlib_filename(loaded_typelib) + tlib_mtime = None + if self.filename is not None: + # get full path to DLL first (os.stat can't work with relative DLL paths properly) + loaded_typelib = comtypes.typeinfo.LoadTypeLib(self.filename) + full_filename = comtypes.tools.tlbparser.get_tlib_filename(loaded_typelib) + + # get DLL timestamp at the moment of wrapper generation + tlib_mtime = os.stat(full_filename).st_mtime - # get DLL timestamp at the moment of wrapper generation - tlib_mtime = os.stat(full_filename).st_mtime print >> self.output, "from comtypes import _check_version; _check_version(%r, %f)" % (version, tlib_mtime) return loops