Skip to content

Commit

Permalink
Issue 350 plugins can import most commonly used flex measures classes…
Browse files Browse the repository at this point in the history
… from a central place (#354)

* Let common classes be imported from a central place in flexmeasures

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Add test

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Consider Annotation and GenericAssetType as common classes, too

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Feb 4, 2022
1 parent e74c522 commit 6e9e62b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -21,6 +21,7 @@ Bugfixes

Infrastructure / Support
----------------------
* Plugins can import common FlexMeasures classes (like ``Asset`` and ``Sensor``) from a central place, using ``from flexmeasures import Asset, Sensor`` [see `PR #354 <http://www.github.com/FlexMeasures/flexmeasures/pull/354>`_]

* Adapt CLI command for entering some initial structure (``flexmeasures add structure``) to new datamodel [see `PR #349 <http://www.github.com/FlexMeasures/flexmeasures/pull/349>`_]

Expand Down
9 changes: 9 additions & 0 deletions flexmeasures/__init__.py
@@ -1,5 +1,14 @@
from importlib_metadata import version, PackageNotFoundError

from flexmeasures.data.models.annotations import Annotation # noqa F401
from flexmeasures.data.models.user import Account, AccountRole, User # noqa F401
from flexmeasures.data.models.data_sources import DataSource as Source # noqa F401
from flexmeasures.data.models.generic_assets import ( # noqa F401
GenericAsset as Asset,
GenericAssetType as AssetType,
)
from flexmeasures.data.models.time_series import Sensor # noqa F401


__version__ = "Unknown"

Expand Down
Empty file added flexmeasures/config/__init__.py
Empty file.
Empty file.
19 changes: 19 additions & 0 deletions flexmeasures/config/tests/test_package.py
@@ -0,0 +1,19 @@
import pytest


@pytest.mark.parametrize(
"class_name",
[
"Account",
"AccountRole",
"Asset",
"Sensor",
"Source",
"User",
],
)
def test_class_imports(class_name: str):
"""Make sure that plugins can import these classes as `from flexmeasures import <class_name>`."""
import flexmeasures as fm

assert hasattr(fm, class_name)

0 comments on commit 6e9e62b

Please sign in to comment.