Add new hotfix module to automatically handle some Convention updates #157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After #156 plugins such as emsarray-smc will be broken because they no longer implement all of the required abstract methods. Ultimately the plugin should be updated to correctly implement the new interface, but until that happens it would be polite if the plugin could still be used given this is a backwards incompatible change otherwise. This pull request is a work in progress towards implementing Convention hotfixes for changes such as these.
In the case of #156 a functioning Convention subclass can be made from the previous implementation using
Convention.polygons
and somesuper()
call shenanigans.Actually getting this hotfix in place is a bit tricky. If an Abstract Base Class is not fully implemented then an error is thrown in object.new at instantiation time. The class itself needs patching before any instances can be instantiated. Specific Convention subclasses can be instantiated in two different ways: automatically by emsarray through autodetecting the appropriate Convention subclass from all the registered conventions, and manually constructing and binding a Convention subclass to a dataset.
Doing metaclass magic isn't possible. The metaclass magic has no way of knowing whether the subclass is final or not. It could be an intermediary subclass such as CFGrid which is further specialised. Patching the CFGrid class would be inappropriate as the CFGrid1D or CFGrid2D classes may provide the implementations.
One approach is to patch the class at the time the class is registered only works for automatically instantiated classes as these go through the registry. This approach has the added benefit of being backwards compatible with the existing Convention plugins which might need patching without any modification. This approach doesn't work for manually instantiated convention classes though, as the class as defined in a module has not been modified. Mutating the classes in place sounds like a bad idea.
Another approach is to add a new decorator that can modify the Convention subclass at the time the class is declared. This would effectively be the same as decorating the class with the
hotfix_convention()
method defined in this WIP pull request. A better name would have to be found in that case. The decorator could also register the convention class. This approach has the downside of needing an update to plugins in order to enable the backwards compatible fixes, which kind of negates the point at least for this round of changes, but does offer more power going forward. Also, it is the only option that actually works in all cases.