Skip to content

Conversation

@mementum
Copy link

@mementum mementum commented Apr 9, 2016

No description provided.

@cfarrow
Copy link

cfarrow commented Apr 12, 2016

Thanks. It looks like the declaration of __verbose__ can be removed. With that change, this is good to merge.

@junkmd
Copy link
Collaborator

junkmd commented Nov 27, 2022

@mementum
Hi.
I have very recently become a collaborator of comtypes.

A long time has passed since this PR was posted.
You would have wanted to change the way to display # Generating ... messages from using print to logger.
They have been achieved by other PRs!

def _create_wrapper_module(tlib, pathname):
# type: (typeinfo.ITypeLib, Optional[str]) -> types.ModuleType
"""helper which creates and imports the real typelib wrapper module."""
modulename = codegenerator.name_wrapper_module(tlib)
if modulename in sys.modules:
return sys.modules[modulename]
try:
return _my_import(modulename)
except Exception as details:
logger.info("Could not import %s: %s", modulename, details)
# generate the module since it doesn't exist or is out of date
logger.info("# Generating %s", modulename)
p = tlbparser.TypeLibParser(tlib)
if pathname is None:
pathname = tlbparser.get_tlib_filename(tlib)
items = list(p.parse().values())
codegen = codegenerator.CodeGenerator(_get_known_symbols())
code = codegen.generate_code(items, filename=pathname)
for ext_tlib in codegen.externals: # generates dependency COM-lib modules
GetModule(ext_tlib)
if comtypes.client.gen_dir is None:
return _create_module_in_memory(modulename, code)
return _create_module_in_file(modulename, code)

def _create_friendly_module(tlib, modulename):
# type: (typeinfo.ITypeLib, str) -> types.ModuleType
"""helper which creates and imports the friendly-named module."""
try:
mod = _my_import(modulename)
except Exception as details:
logger.info("Could not import %s: %s", modulename, details)
else:
return mod
# the module is always regenerated if the import fails
logger.info("# Generating %s", modulename)
# determine the Python module name
modname = codegenerator.name_wrapper_module(tlib).split(".")[-1]
code = "from comtypes.gen import %s\n" % modname
code += "globals().update(%s.__dict__)\n" % modname
code += "__name__ = '%s'" % modulename
if comtypes.client.gen_dir is None:
return _create_module_in_memory(modulename, code)
return _create_module_in_file(modulename, code)

These changes might have been influenced by your proposal.
Thank you very much for your contributions.

I would be happy to work on #104 instead of this.

@junkmd junkmd closed this Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants