Self heal
Fixes #114
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, is the issue consistent? Can you please add more details describing the failure seen during the first time import.
#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 -- 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
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?
@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_fileis 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_filein_my_import, calling_comtypes_validate_filewithin trying to create or import the wrapper module. -
_comtypes_validate_filedefinition is notPEP8-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?
@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.