Skip to content

Commit 6420a96

Browse files
committed
expose register at top-level
1 parent 0e55a0d commit 6420a96

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

phoebe/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,27 @@ def add_distl_docstring(obj):
888888
add_distl_docstring(uniform_around)
889889
add_distl_docstring(gaussian_around)
890890

891+
# expose registering pluggable features`
892+
def register_feature(feature_cls, kind=None) -> None:
893+
"""
894+
Register a feature class to be available in the Bundle.
895+
896+
Arguments
897+
-----------
898+
* `feature_cls` (class): the class to register
899+
* `kind` (string, optional): the kind to register the class under. If None,
900+
the class will be registered under its default kind.
901+
"""
902+
903+
from phoebe.features.dataset_features import _register_feature as ds_register_feature
904+
from phoebe.features.component_features import _register_feature as comp_register_feature
905+
feature_type = getattr(feature_cls, '_phoebe_custom_feature', None)
906+
if feature_type == 'dataset':
907+
ds_register_feature(feature_cls, kind=kind)
908+
elif feature_type == 'component':
909+
comp_register_feature(feature_cls, kind=kind)
910+
else:
911+
raise TypeError("could not find matching feature type for {}".format(feature_cls))
891912

892913
# expose available "kinds" per-context
893914
def _get_phoebe_funcs(module, devel=False):

phoebe/features/component_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
logger.addHandler(logging.NullHandler())
99

1010

11-
__all__ = ['register_feature', 'ComponentFeature', 'Spot', 'Pulsation']
11+
__all__ = ['ComponentFeature', 'Spot', 'Pulsation']
1212

1313
_skip_filter_checks = {'check_default': False, 'check_visible': False}
1414

15-
def register_feature(feature_cls, kind=None):
15+
def _register_feature(feature_cls, kind=None):
1616
if kind is None:
1717
kind = feature_cls.__name__.lower()
1818

phoebe/features/dataset_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from phoebe.parameters import constraint
1010
import phoebe.parameters.feature as _parameters_feature
1111

12-
__all__ = ['register_feature', 'DatasetFeature']
12+
__all__ = ['DatasetFeature']
1313

1414
_skip_filter_checks = {'check_default': False, 'check_visible': False}
1515

16-
def register_feature(feature_cls, kind=None):
16+
def _register_feature(feature_cls, kind=None):
1717
if kind is None:
1818
kind = feature_cls.__name__.lower()
1919

0 commit comments

Comments
 (0)