DataBrewery / cubes

[NOT MAINTAINED] Light-weight Python OLAP framework for multi-dimensional data analysis
http://cubes.databrewery.org
Other
1.49k stars 314 forks source link

Added new extension mechanism for #425 #427

Closed Stiivi closed 7 years ago

Stiivi commented 7 years ago

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: