enthought / comtypes

A pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.
Other
283 stars 96 forks source link

redundant processes for finding typelib-path and resolving it #358

Open junkmd opened 1 year ago

junkmd commented 1 year ago

Related to #327, I am refactoring tools.codegenerator and client._generate.

These modules include processing to turn passed relative paths into absolute paths and to find absolute paths to type libraries.

However, there are redundant processes as below.

https://github.com/enthought/comtypes/blob/fed3de69ccc61e37187b4a219daa120a97740663/comtypes/tools/tlbparser.py#L716-L724 https://github.com/enthought/comtypes/blob/fed3de69ccc61e37187b4a219daa120a97740663/comtypes/client/_generate.py#L110-L122 https://github.com/enthought/comtypes/blob/fed3de69ccc61e37187b4a219daa120a97740663/comtypes/tools/codegenerator.py#L267-L286 https://github.com/enthought/comtypes/blob/fed3de69ccc61e37187b4a219daa120a97740663/comtypes/tools/codegenerator.py#L242-L265

I would like to make sure that only client._generate does path-related processing for type libraries, and that tools.codegenerator only takes the path and generates code.

junkmd commented 1 year ago

@vasily-v-ryabov

I propose that it is no more defining typelib_path as relative path in _generate_typelib_path. I would like to hear your opinion. (because you have been committed 6c1788afb7789b91959fb8ecb039538c90ca0754 and have added the following comments.) https://github.com/enthought/comtypes/blob/6c1788afb7789b91959fb8ecb039538c90ca0754/comtypes/tools/codegenerator.py#L222-L227

Rationale

Currently, there is still a conditional branch that makes the definition of typelib_path a path relative to the .../comtypes/gen directory, as shown below. https://github.com/enthought/comtypes/blob/fed3de69ccc61e37187b4a219daa120a97740663/comtypes/tools/codegenerator.py#L248-L265

Perhaps this is because there used to be a situation where tools.codegenerator was called as a script.

if __name__ == "__main__:" line is currently not in tools.codegenerator.

So currently it seems filename is already None or absolute path at the caller(client._generate.GetModule).