comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

Self heal

Open vijairaj opened this issue 8 years ago • 6 comments

Fixes #114

vijairaj avatar Mar 13 '17 13:03 vijairaj

Hey, with this patch I have full files however for some reason import doesn't work on the first try only after that (it generates the source successfully into the cache dir but can't import them only after the fist run)

(I know this is almost a year old issue and maybe it is not even related to it ...)

kviktor avatar Jan 05 '18 17:01 kviktor

@kviktor, is the issue consistent? Can you please add more details describing the failure seen during the first time import.

vijairaj avatar Jan 07 '18 05:01 vijairaj

#300 prevents partial files from being generated.

Processing order has changed.

previously: open file -> write header -> parse type library -> generate code -> write body and footer -> close file currently: parse type library -> generate code including header and footer -> open file -> write code -> close file

The interval between opening a file, writing code, and closing it is much shorter, so "an interruption in between" is much rarer.

junkmd avatar Jun 19 '22 05:06 junkmd

@junkmd -- While the changed order definitely makes the issue very rare but the self heal mechanism can act as 2nd level of protection against the small odds or when the file is corrupted later.

vijairaj avatar Jul 03 '22 00:07 vijairaj

@vijairaj Certainly, importing from an empty or partial .py file can still occur in this situation, so I agree with the inclusion of self heal logic. However, a long time has passed since this PR was first posted, the syntax has become Python 3 compliant, and the design of the codegenerator has changed. If we were to reintroduce it now, what would be the best way to implement it?

junkmd avatar Jul 03 '22 03:07 junkmd

@vijairaj

While I am waiting for a review of the PR I have currently submitted, I thought about what would happen if I applied your proposed logic to the current master branch.

This code worked at runtime, but there are still problems. https://github.com/enthought/comtypes/compare/944e279..2669789

  • The code calling another module's _comtypes_validate_file is written in a strange position.

  • To solve the import failing problem in my env(is related to mentioned by @kviktor(https://github.com/enthought/comtypes/pull/116#issuecomment-355617346)?), instead of calling _comtypes_validate_file in _my_import, calling _comtypes_validate_file within trying to create or import the wrapper module.

  • _comtypes_validate_file definition is not PEP8-compliant.

  • Tests have not yet been created. I haven't figured out how to prepare the "partial module file" and how to see repaired it.

What is your opinion?

junkmd avatar Jul 30 '22 12:07 junkmd

@vijairaj @kviktor

As mentioned in #114, good suggestion about the ability to restore partial modules.

However, it is difficult to implement and also difficult to validate with unittest. As for testing, if only Python3 is supported, there is unittest.mock, so it could be done by patching sys.modules and import-related processes.

And the current code and module generation process design has changed significantly since this PR was submitted, causing conflicts with the proposed code.

Due to no recent activity, I close this. If you wish to add this feature, please rebase, resolve conflicts and re-open or submit a new PR.

junkmd avatar Dec 08 '22 12:12 junkmd