mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-08 18:32:21 +00:00
add version to built packages (#5408)
* add version to built packages * remove file
This commit is contained in:
@@ -5,7 +5,10 @@ import os
|
||||
from pathlib import Path
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from openbb_core.app.static.utils import auto_build as _auto_build, build as _build
|
||||
from openbb_core.app.static.build_utils import (
|
||||
auto_build as _auto_build,
|
||||
build as _build,
|
||||
)
|
||||
from openbb_core.app.static.app_factory import (
|
||||
create_app as _create_app,
|
||||
BaseApp as _BaseApp,
|
||||
|
||||
20
openbb_sdk/openbb/package/extension_map.json
vendored
20
openbb_sdk/openbb/package/extension_map.json
vendored
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"openbb_core_extension": [
|
||||
"crypto",
|
||||
"economy",
|
||||
"fixedincome",
|
||||
"forex",
|
||||
"news",
|
||||
"stocks"
|
||||
"crypto@0.1.0",
|
||||
"economy@0.1.0",
|
||||
"fixedincome@0.1.0",
|
||||
"forex@0.1.0",
|
||||
"news@0.1.0",
|
||||
"stocks@0.1.0"
|
||||
],
|
||||
"openbb_provider_extension": [
|
||||
"benzinga",
|
||||
"fmp",
|
||||
"fred",
|
||||
"polygon"
|
||||
"benzinga@0.1.0",
|
||||
"fmp@0.1.0",
|
||||
"fred@0.1.0",
|
||||
"polygon@0.1.0"
|
||||
]
|
||||
}
|
||||
@@ -41,7 +41,9 @@ def package_diff(package: Path) -> Tuple[Set[str], Set[str]]:
|
||||
groups = ("openbb_core_extension", "openbb_provider_extension")
|
||||
for g in groups:
|
||||
built = set(ext_map.get(g, {}))
|
||||
installed = entry_points(group=g).names
|
||||
installed = set(
|
||||
f"{e.name}@{getattr(e.dist, 'version', '')}" for e in entry_points(group=g)
|
||||
)
|
||||
add = add.union(installed - built)
|
||||
remove = remove.union(built - installed)
|
||||
|
||||
@@ -75,7 +75,15 @@ class PackageBuilder:
|
||||
def save_extension_map(self):
|
||||
"""Save the map of extensions available at build time"""
|
||||
groups = ("openbb_core_extension", "openbb_provider_extension")
|
||||
ext_map = {g: sorted(list(entry_points(group=g).names)) for g in groups}
|
||||
ext_map = {
|
||||
g: sorted(
|
||||
[
|
||||
f"{e.name}@{getattr(e.dist, 'version', '')}"
|
||||
for e in entry_points(group=g)
|
||||
]
|
||||
)
|
||||
for g in groups
|
||||
}
|
||||
code = dumps(obj=dict(sorted(ext_map.items())), indent=4)
|
||||
self.console.log("Writing extension map...")
|
||||
self.write_to_package(code=code, name="extension_map", extension="json")
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import mock_open, patch
|
||||
from unittest.mock import PropertyMock, mock_open, patch
|
||||
|
||||
import pytest
|
||||
from importlib_metadata import EntryPoint, EntryPoints
|
||||
from openbb_core.app.static.utils import auto_build, get_ext_map, package_diff
|
||||
from openbb_core.app.static.build_utils import auto_build, get_ext_map, package_diff
|
||||
from openbb_core.env import Env
|
||||
|
||||
PATH = "openbb_core.app.static.utils."
|
||||
PATH = "openbb_core.app.static.build_utils."
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@@ -29,17 +29,17 @@ def test_get_ext_map(tmp_dir):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"ext_built, ext_installed, expected_add, expected_remove",
|
||||
"ext_built, ext_installed, ext_inst_version, expected_add, expected_remove",
|
||||
[
|
||||
(
|
||||
{
|
||||
"openbb_core_extension": [
|
||||
"ext_1",
|
||||
"ext_2",
|
||||
"ext_1@0.0.0",
|
||||
"ext_2@0.0.0",
|
||||
],
|
||||
"openbb_provider_extension": [
|
||||
"prov_1",
|
||||
"prov_2",
|
||||
"prov_1@0.0.0",
|
||||
"prov_2@1.1.1",
|
||||
],
|
||||
},
|
||||
EntryPoints(
|
||||
@@ -52,13 +52,14 @@ def test_get_ext_map(tmp_dir):
|
||||
),
|
||||
)
|
||||
),
|
||||
set(),
|
||||
{"ext_1", "prov_1"},
|
||||
"0.0.0",
|
||||
{"prov_2@0.0.0"},
|
||||
{"ext_1@0.0.0", "prov_1@0.0.0", "prov_2@1.1.1"},
|
||||
),
|
||||
(
|
||||
{
|
||||
"openbb_core_extension": ["ext_1"],
|
||||
"openbb_provider_extension": ["prov_2"],
|
||||
"openbb_core_extension": ["ext_1@9.9.9"],
|
||||
"openbb_provider_extension": ["prov_2@0.0.0"],
|
||||
},
|
||||
EntryPoints(
|
||||
(
|
||||
@@ -70,12 +71,20 @@ def test_get_ext_map(tmp_dir):
|
||||
),
|
||||
)
|
||||
),
|
||||
{"ext_2", "prov_1"},
|
||||
{"ext_1", "prov_2"},
|
||||
"5.5.5",
|
||||
{"ext_2@5.5.5", "prov_1@5.5.5"},
|
||||
{"ext_1@9.9.9", "prov_2@0.0.0"},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_package_diff(tmp_dir, ext_built, ext_installed, expected_add, expected_remove):
|
||||
def test_package_diff(
|
||||
tmp_dir,
|
||||
ext_built,
|
||||
ext_installed,
|
||||
ext_inst_version,
|
||||
expected_add,
|
||||
expected_remove,
|
||||
):
|
||||
"""Test package differences."""
|
||||
|
||||
def mock_entry_points(group):
|
||||
@@ -83,7 +92,12 @@ def test_package_diff(tmp_dir, ext_built, ext_installed, expected_add, expected_
|
||||
|
||||
with patch(PATH + "get_ext_map") as mock_get_ext_map, patch(
|
||||
PATH + "entry_points", mock_entry_points
|
||||
):
|
||||
), patch.object(EntryPoint, "dist", new_callable=PropertyMock) as mock_obj:
|
||||
|
||||
class MockPathDistribution:
|
||||
version = ext_inst_version
|
||||
|
||||
mock_obj.return_value = MockPathDistribution()
|
||||
mock_get_ext_map.return_value = ext_built
|
||||
|
||||
add, remove = package_diff(tmp_dir)
|
||||
Reference in New Issue
Block a user