Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new extension mechanism for #425 #427

Merged
merged 4 commits into from Mar 29, 2017
Merged

Added new extension mechanism for #425 #427

merged 4 commits into from Mar 29, 2017

Conversation

Stiivi
Copy link
Member

@Stiivi Stiivi commented Mar 28, 2017

This pull-requests introduces new extensions interface. The old pkg_resource based discovery was removed as it is not standard. We are now using the __init_subclass__() method to register the subclasses.

Added new class Extensible and all top-level abstract classes for extensions should inherit from this class. The top-level abstract classes have to provide their own __extension_type__ class variable.

Extensions are created by subclassing one of the abstract class and explicitly providing extension name:

class MyStore(Store, name="my"):
    ...

The extensions are retrieved through:

store: Store
store = Store.concrete_extension("my")(...)
# Or initialize from configuration:
store = Store.concrete_extension("my").create_with_params(config)

To manually register extension:

from cubes.ext import get_registry()

registry = get_registry("store")
registry.register_extension("my", MyStore)

To register extension that lives in a module that is guaranteed to be loadable by standard Python means, but we don't want it to be loaded if not needed:

registry.register_lazy_extension("my", "my_extensions.store")

Note that we don't need to specify class as it will be automatically registered by loading that module when needed.

Other changes:

  • The slicer ext-info command was renamed to extension and an option --try-import to test load-ability of the extensions was added.

* Removed old pkg_resource based extension discovery (non-standard)
* Use __init_subclass__ hook to register subclasses
* Preliminary implementation of conf parameters passing and conversion

Proposed interface: extensibles have to be subclasses of Extensible.
Abstract subclasses must have abstract=True flag specified and concrete
subclasses must have their name= specified.

See tests/test_ext.py for an example.
* ExtensionRegistry is now per-extension type
* Added get_registry()
* Added registration of modules to be loaded
* Updated builtin extension classes to use the new extension system
* Renamed the slicer `ext-info` command to `extension` and reflected
  changes.
@Stiivi Stiivi requested a review from jjmontesl March 28, 2017 04:06
@Stiivi Stiivi added this to the 2.0 milestone Mar 28, 2017
@Stiivi Stiivi self-assigned this Mar 28, 2017
@Stiivi Stiivi changed the title Extensible Added new extension mechanism for #425 Mar 28, 2017
@Stiivi Stiivi merged commit f0fa7cb into 2.0 Mar 29, 2017
@Stiivi Stiivi deleted the extensible branch April 6, 2017 01:57
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.

None yet

1 participant