diff options
author | montezdesousa <79287829+montezdesousa@users.noreply.github.com> | 2024-02-21 12:31:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-21 12:31:18 +0000 |
commit | 5f9d958260aabe2e1f4fe0f6571ea2b53c1ff803 (patch) | |
tree | 6d8d3240b3e6c1f9e633c16e21d17fba8820f637 | |
parent | ad2dae277d035e88bbccc1d36c8150e1dddba923 (diff) |
[Feature] - Create openbb assets folder (#6101)
* create openbb assets folder
* fix unittest
* rebuild
---------
Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
15 files changed, 135 insertions, 94 deletions
diff --git a/openbb_platform/core/openbb_core/app/static/package_builder.py b/openbb_platform/core/openbb_core/app/static/package_builder.py index 52a16185467..3caa6d31974 100644 --- a/openbb_platform/core/openbb_core/app/static/package_builder.py +++ b/openbb_platform/core/openbb_core/app/static/package_builder.py @@ -79,7 +79,9 @@ class PackageBuilder: def auto_build(self) -> None: """Trigger build if there are differences between built and installed extensions.""" if Env().AUTO_BUILD: - add, remove = PackageBuilder._diff(self.directory / "package") + add, remove = PackageBuilder._diff( + self.directory / "assets" / "extension_map.json" + ) if add: a = ", ".join(add) print(f"Extensions to add: {a}") # noqa: T201 @@ -98,7 +100,7 @@ class PackageBuilder: ) -> None: """Build the extensions for the Platform.""" self.console.log("\nBuilding extensions package...\n") - self._clean_package(modules) + self._clean(modules) ext_map = self._get_extension_map() self._save_extension_map(ext_map) self._save_module_map() @@ -107,8 +109,9 @@ class PackageBuilder: if self.lint: self._run_linters() - def _clean_package(self, modules: Optional[Union[str, List[str]]] = None) -> None: - """Delete the package folder or modules before building.""" + def _clean(self, modules: Optional[Union[str, List[str]]] = None) -> None: + """Delete the assets and package folder or modules before building.""" + shutil.rmtree(self.directory / "assets", ignore_errors=True) if modules: for module in modules: module_path = self.directory / "package" / f"{module}.py" @@ -141,7 +144,7 @@ class PackageBuilder: """Save the map of extensions available at build time.""" code = dumps(obj=dict(sorted(ext_map.items())), indent=4) self.console.log("Writing extension map...") - self._write(code=code, name="extension_map", extension="json") + self._write(code=code, name="extension_map", extension="json", folder="assets") def _save_module_map(self): """Save the module map.""" @@ -152,7 +155,7 @@ class PackageBuilder: } code = dumps(obj=dict(sorted(module_map.items())), indent=4) self.console.log("\nWriting module map...") - self._write(code=code, name="module_map", extension="json") + self._write(code=code, name="module_map", extension="json", folder="assets") def _save_modules( self, @@ -197,9 +200,11 @@ class PackageBuilder: linters.ruff() linters.black() - def _write(self, code: str, name: str, extension="py") -> None: + def _write( + self, code: str, name: str, extension: str = "py", folder: str = "package" + ) -> None: """Write the module to the package.""" - package_folder = self.directory / "package" + package_folder = self.directory / folder package_path = package_folder / f"{name}.{extension}" package_folder.mkdir(exist_ok=True) @@ -209,25 +214,24 @@ class PackageBuilder: file.write(code.replace("typing.", "")) @staticmethod - def _read_extension_map(package: Path) -> dict: - """Get extension map from package folder.""" - ext_map_file = Path(package, "extension_map.json") + def _read(path: Path) -> dict: + """Get content from folder.""" try: - with open(ext_map_file) as fp: - ext_map = load(fp) + with open(Path(path)) as fp: + content = load(fp) except Exception: - ext_map = {} + content = {} - return ext_map + return content @staticmethod - def _diff(package: Path) -> Tuple[Set[str], Set[str]]: + def _diff(path: Path) -> Tuple[Set[str], Set[str]]: """Check differences between built and installed extensions. Parameters ---------- - package: Path - The path to the package + path: Path + The path to the folder where the extension map is stored. Returns ------- @@ -235,7 +239,7 @@ class PackageBuilder: First element: set of installed extensions that are not in the package. Second element: set of extensions in the package that are not installed. """ - ext_map = PackageBuilder._read_extension_map(package) + ext_map = PackageBuilder._read(path) add: Set[str] = set() remove: Set[str] = set() diff --git a/openbb_platform/core/tests/app/static/test_package_builder.py b/openbb_platform/core/tests/app/static/test_package_builder.py index 44e7ab698d5..9057c932bcc 100644 --- a/openbb_platform/core/tests/app/static/test_package_builder.py +++ b/openbb_platform/core/tests/app/static/test_package_builder.py @@ -26,14 +26,14 @@ from typing_extensions import Annotated @pytest.fixture(scope="module") -def tmp_package_dir(tmp_path_factory): - return tmp_path_factory.mktemp("package") +def tmp_openbb_dir(tmp_path_factory): + return tmp_path_factory.mktemp("openbb") @pytest.fixture(scope="module") -def package_builder(tmp_package_dir): +def package_builder(tmp_openbb_dir): """Return package builder.""" - return PackageBuilder(tmp_package_dir) + return PackageBuilder(tmp_openbb_dir) def test_package_builder_init(package_builder): @@ -544,14 +544,16 @@ def test_generate(docstring_generator): assert "Returns" in doc -def test_read_extension_map(package_builder, tmp_package_dir): +def test_read_extension_map(package_builder, tmp_openbb_dir): """Test read extension map.""" PATH = "openbb_core.app.static.package_builder." open_mock = mock_open() with patch(PATH + "open", open_mock), patch(PATH + "load") as mock_load: - package_builder._read_extension_map(tmp_package_dir) - open_mock.assert_called_once_with(Path(tmp_package_dir, "extension_map.json")) + package_builder._read(Path(tmp_openbb_dir / "assets" / "extension_map.json")) + open_mock.assert_called_once_with( + Path(tmp_openbb_dir / "assets" / "extension_map.json") + ) mock_load.assert_called_once() @@ -606,7 +608,7 @@ def test_read_extension_map(package_builder, tmp_package_dir): ) def test_package_diff( package_builder, - tmp_package_dir, + tmp_openbb_dir, ext_built, ext_installed, ext_inst_version, @@ -619,21 +621,19 @@ def test_package_diff( return ext_installed.select(**{"group": group}) PATH = "openbb_core.app.static.package_builder." - with patch.object( - PackageBuilder, "_read_extension_map" - ) as mock_read_extension_map, patch( + with patch.object(PackageBuilder, "_read") as mock_read, patch( PATH + "entry_points", mock_entry_points - ), patch.object( - EntryPoint, "dist", new_callable=PropertyMock - ) as mock_obj: + ), patch.object(EntryPoint, "dist", new_callable=PropertyMock) as mock_obj: class MockPathDistribution: version = ext_inst_version mock_obj.return_value = MockPathDistribution() - mock_read_extension_map.return_value = ext_built + mock_read.return_value = ext_built - add, remove = package_builder._diff(tmp_package_dir) + add, remove = package_builder._diff( + Path(tmp_openbb_dir, "assets", "extension_map.json") + ) # We add whatever is not built, but is installed assert add == expected_add @@ -651,20 +651,22 @@ def test_package_diff( ({"this"}, {"that"}, False), ], ) -def test_auto_build(package_builder, tmp_package_dir, add, remove, openbb_auto_build): +def test_auto_build(package_builder, tmp_openbb_dir, add, remove, openbb_auto_build): """Test auto build.""" - with patch.object(PackageBuilder, "_diff") as mock_package_diff, patch.object( + with patch.object(PackageBuilder, "_diff") as mock_assets_diff, patch.object( PackageBuilder, "build" ) as mock_build, patch.object(Env, "AUTO_BUILD", openbb_auto_build): - mock_package_diff.return_value = add, remove + mock_assets_diff.return_value = add, remove package_builder.auto_build() if openbb_auto_build: - mock_package_diff.assert_called_once_with(Path(tmp_package_dir, "package")) + mock_assets_diff.assert_called_once_with( + Path(tmp_openbb_dir, "assets", "extension_map.json") + ) if add or remove: mock_build.assert_called_once() else: - mock_package_diff.assert_not_called() + mock_assets_diff.assert_not_called() mock_build.assert_not_called() diff --git a/openbb_platform/openbb/package/extension_map.json b/openbb_platform/openbb/assets/extension_map.json index 3a653d729ce..3a653d729ce 100644 --- a/openbb_platform/openbb/package/extension_map.json +++ b/openbb_platform/openbb/assets/extension_map.json diff --git a/openbb_platform/openbb/package/module_map.json b/openbb_platform/openbb/assets/module_map.json index 1188f16fbab..6b9c08e3199 100644 --- a/openbb_platform/openbb/package/module_map.json +++ b/openbb_platform/openbb/assets/module_map.json @@ -136,7 +136,6 @@ "index_market": "/index/market", "index_price": "/index/price", "index_price_historical": "/index/price/historical", - "index_sectors": "/index/sectors", "news": "/news", "news_company": "/news/company", "news_world": "/news/world", diff --git a/openbb_platform/openbb/package/equity.py b/openbb_platform/openbb/package/equity.py index b6bde8a8562..3b3e52a05e5 100644 --- a/openbb_platform/openbb/package/equity.py +++ b/openbb_platform/openbb/package/equity.py @@ -227,7 +227,7 @@ class ROUTER_equity(Container): symbol: Annotated[ Union[str, List[str]], OpenBBCustomParameter( - description="Symbol to get data for. Multiple items allowed: intrinio, yfinance." + description="Symbol to get data for. Multiple items allowed: fmp, intrinio, yfinance." ), ], provider: Optional[Literal["fmp", "intrinio", "yfinance"]] = None, @@ -238,7 +238,7 @@ class ROUTER_equity(Container): Parameters ---------- symbol : Union[str, List[str]] - Symbol to get data for. Multiple items allowed: intrinio, yfinance. + Symbol to get data for. Multiple items allowed: fmp, intrinio, yfinance. provider : Optional[Literal['fmp', 'intrinio', 'yfinance']] The provider to use for the query, by default None. If None, the provider specified in defaults is selected or 'fmp' if there is @@ -403,7 +403,9 @@ class ROUTER_equity(Container): }, extra_params=kwargs, extra_info={ - "symbol": {"multiple_items_allowed": ["intrinio", "yfinance"]} + "symbol": { + "multiple_items_allowed": ["fmp", "intrinio", "yfinance"] + } }, ) ) diff --git a/openbb_platform/openbb/package/equity_discovery.py b/openbb_platform/openbb/package/equity_discovery.py index 6b272d10c0b..2e152439734 100644 --- a/openbb_platform/openbb/package/equity_discovery.py +++ b/openbb_platform/openbb/package/equity_discovery.py @@ -77,7 +77,7 @@ class ROUTER_equity_discovery(Container): Percent change. volume : float The trading volume. - market_cap : Optional[str] + market_cap : Optional[float] Market Cap displayed in billions. (provider: yfinance) avg_volume_3_months : Optional[float] Average volume over the last 3 months in millions. (provider: yfinance) @@ -158,7 +158,7 @@ class ROUTER_equity_discovery(Container): Percent change. volume : float The trading volume. - market_cap : Optional[str] + market_cap : Optional[float] Market Cap. (provider: yfinance) avg_volume_3_months : Optional[float] Average volume over the last 3 months in millions. (provider: yfinance) @@ -341,7 +341,7 @@ class ROUTER_equity_discovery(Container): Percent change. volume : float The trading volume. - market_cap : Optional[str] + market_cap : Optional[float] Market Cap. (provider: yfinance) avg_volume_3_months : Optional[float] Average volume over the last 3 months in millions. (provider: yfinance) @@ -422,7 +422,7 @@ class ROUTER_equity_discovery(Container): Percent change. volume : float The trading volume. - market_cap : Optional[str] + market_cap : Optional[float] Market Cap. (provider: yfinance) avg_volume_3_months : Optional[float] Average volume over the last 3 months in millions. (provider: yfinance) @@ -503,7 +503,7 @@ class ROUTER_equity_discovery(Container): Percent change. volume : float The trading volume. - market_cap : Optional[str] + market_cap : Optional[float] Market Cap. (provider: yfinance) avg_volume_3_months : Optional[float] Average volume over the last 3 months in millions. (provider: yfinance) @@ -584,7 +584,7 @@ class ROUTER_equity_discovery(Container): Percent change. volume : float The trading volume. - market_cap : Optional[str] + market_cap : Optional[float] Market Cap. (provider: yfinance) avg_volume_3_months : Optional[float] Average volume over the last 3 months in millions. (provider: yfinance) diff --git a/openbb_platform/openbb/package/equity_fundamental.py b/openbb_platform/openbb/package/equity_fundamental.py index 008cda94948..8e3b669d4ea 100644 --- a/openbb_platform/openbb/package/equity_fundamental.py +++ b/openbb_platform/openbb/package/equity_fundamental.py @@ -1270,7 +1270,10 @@ class ROUTER_equity_fundamental(Container): def historical_attributes( self, symbol: Annotated[ - str, OpenBBCustomParameter(description="Symbol to get data for.") + Union[str, List[str]], + OpenBBCustomParameter( + description="Symbol to get data for. Multiple items allowed: intrinio." + ), ], tag: Annotated[ Union[str, List[str]], @@ -1313,8 +1316,8 @@ class ROUTER_equity_fundamental(Container): Parameters ---------- - symbol : str - Symbol to get data for. + symbol : Union[str, List[str]] + Symbol to get data for. Multiple items allowed: intrinio. tag : Union[str, List[str]] Intrinio data tag ID or code. Multiple items allowed: intrinio. start_date : Union[datetime.date, None, str] @@ -1386,7 +1389,10 @@ class ROUTER_equity_fundamental(Container): "sort": sort, }, extra_params=kwargs, - extra_info={"tag": {"multiple_items_allowed": ["intrinio"]}}, + extra_info={ + "symbol": {"multiple_items_allowed": ["intrinio"]}, + "tag": {"multiple_items_allowed": ["intrinio"]}, + }, ) ) @@ -2033,7 +2039,10 @@ class ROUTER_equity_fundamental(Container): def latest_attributes( self, symbol: Annotated[ - str, OpenBBCustomParameter(description="Symbol to get data for.") + Union[str, List[str]], + OpenBBCustomParameter( + description="Symbol to get data for. Multiple items allowed: intrinio." + ), ], tag: Annotated[ Union[str, List[str]], @@ -2048,8 +2057,8 @@ class ROUTER_equity_fundamental(Container): Parameters ---------- - symbol : str - Symbol to get data for. + symbol : Union[str, List[str]] + Symbol to get data for. Multiple items allowed: intrinio. tag : Union[str, List[str]] Intrinio data tag ID or code. Multiple items allowed: intrinio. provider : Optional[Literal['intrinio']] @@ -2101,7 +2110,10 @@ class ROUTER_equity_fundamental(Container): "tag": tag, }, extra_params=kwargs, - extra_info={"tag": {"multiple_items_allowed": ["intrinio"]}}, + extra_info={ + "symbol": {"multiple_items_allowed": ["intrinio"]}, + "tag": {"multiple_items_allowed": ["intrinio"]}, + }, ) ) diff --git a/openbb_platform/openbb/package/equity_ownership.py b/openbb_platform/openbb/package/equity_ownership.py index ca38f7f2311..bec7986b08c 100644 --- a/openbb_platform/openbb/package/equity_ownership.py +++ b/openbb_platform/openbb/package/equity_ownership.py @@ -74,7 +74,7 @@ class ROUTER_equity_ownership(Container): InsiderTrading -------------- - symbol : str + symbol : Optional[str] Symbol representing the entity requested in the data. company_cik : Optional[Union[int, str]] CIK number of the company. diff --git a/openbb_platform/openbb/package/equity_price.py b/openbb_platform/openbb/package/equity_price.py index bb1f681acd7..712204e4dbf 100644 --- a/openbb_platform/openbb/package/equity_price.py +++ b/openbb_platform/openbb/package/equity_price.py @@ -335,7 +335,10 @@ class ROUTER_equity_price(Container): def performance( self, symbol: Annotated[ - str, OpenBBCustomParameter(description="Symbol to get data for.") + Union[str, List[str]], + OpenBBCustomParameter( + description="Symbol to get data for. Multiple items allowed: fmp." + ), ], provider: Optional[Literal["fmp"]] = None, **kwargs @@ -344,8 +347,8 @@ class ROUTER_equity_price(Container): Parameters ---------- - symbol : str - Symbol to get data for. + symbol : Union[str, List[str]] + Symbol to get data for. Multiple items allowed: fmp. provider : Optional[Literal['fmp']] The provider to use for the query, by default None. If None, the provider specified in defaults is selected or 'fmp' if there is @@ -418,6 +421,7 @@ class ROUTER_equity_price(Container): "symbol": symbol, }, extra_params=kwargs, + extra_info={"symbol": {"multiple_items_allowed": ["fmp"]}}, ) ) diff --git a/openbb_platform/openbb/package/etf.py b/openbb_platform/openbb/package/etf.py index e076e815c9c..f50f4f2376b 100644 --- a/openbb_platform/openbb/package/etf.py +++ b/openbb_platform/openbb/package/etf.py @@ -32,7 +32,10 @@ class ROUTER_etf(Container): def countries( self, symbol: Annotated[ - str, OpenBBCustomParameter(description="Symbol to get data for. (ETF)") + Union[str, List[str]], + OpenBBCustomParameter( + description="Symbol to get data for. (ETF) Multiple items allowed: fmp." + ), ], provider: Optional[Literal["fmp"]] = None, **kwargs @@ -41,8 +44,8 @@ class ROUTER_etf(Container): Parameters ---------- - symbol : str - Symbol to get data for. (ETF) + symbol : Union[str, List[str]] + Symbol to get data for. (ETF) Multiple items allowed: fmp. provider : Optional[Literal['fmp']] The provider to use for the query, by default None. If None, the provider specified in defaults is selected or 'fmp' if there is @@ -87,6 +90,7 @@ class ROUTER_etf(Container): "symbol": symbol, }, extra_params=kwargs, + extra_info={"symbol": {"multiple_items_allowed": ["fmp"]}}, ) ) @@ -237,6 +241,9 @@ class ROUTER_etf(Container): ------- >>> from openbb import obb >>> obb.etf.historical(symbol="SPY") + >>> obb.etf.historical("SPY", provider="yfinance") + >>> #### This function accepts multiple tickers. #### + >>> obb.etf.historical("SPY,IWM,QQQ,DJIA", provider="yfinance") """ # noqa: E501 return self._run( @@ -558,7 +565,10 @@ class ROUTER_etf(Container): def holdings_performance( self, symbol: Annotated[ - str, OpenBBCustomParameter(description="Symbol to get data for.") + Union[str, List[str]], + OpenBBCustomParameter( + description="Symbol to get data for. Multiple items allowed: fmp." + ), ], provider: Optional[Literal["fmp"]] = None, **kwargs @@ -567,8 +577,8 @@ class ROUTER_etf(Container): Parameters ---------- - symbol : str - Symbol to get data for. + symbol : Union[str, List[str]] + Symbol to get data for. Multiple items allowed: fmp. provider : Optional[Literal['fmp']] The provider to use for the query, by default None. If None, the provider specified in defaults is selected or 'fmp' if there is @@ -641,6 +651,7 @@ class ROUTER_etf(Container): "symbol": symbol, }, extra_params=kwargs, + extra_info={"symbol": {"multiple_items_allowed": ["fmp"]}}, ) ) @@ -808,7 +819,10 @@ class ROUTER_etf(Container): def price_performance( self, symbol: Annotated[ - str, OpenBBCustomParameter(description="Symbol to get data for.") + Union[str, List[str]], + OpenBBCustomParameter( + description="Symbol to get data for. Multiple items allowed: fmp." + ), ], provider: Optional[Literal["fmp"]] = None, **kwargs @@ -817,8 +831,8 @@ class ROUTER_etf(Container): Parameters ---------- - symbol : str - Symbol to get data for. + symbol : Union[str, List[str]] + Symbol to get data for. Multiple items allowed: fmp. provider : Optional[Literal['fmp']] The provider to use for the query, by default None. If None, the provider specified in defaults is selected or 'fmp' if there is @@ -891,6 +905,7 @@ class ROUTER_etf(Container): "symbol": symbol, }, extra_params=kwargs, + extra_info={"symbol": {"multiple_items_allowed": ["fmp"]}}, ) ) diff --git a/openbb_platform/openbb/package/fixedincome_government.py b/openbb_platform/openbb/package/fixedincome_government.py index ed4cc770d9c..205cb3e4308 100644 --- a/openbb_platform/openbb/package/fixedincome_government.py +++ b/openbb_platform/openbb/package/fixedincome_government.py @@ -69,30 +69,32 @@ class ROUTER_fixedincome_government(Container): ------------- date : date The date of the data. + week_4 : Optional[float] + 4 week Treasury bills rate (secondary market). month_1 : Optional[float] - 1 month treasury rate. + 1 month Treasury rate. month_2 : Optional[float] - 2 month treasury rate. + 2 month Treasury rate. month_3 : Optional[float] - 3 month treasury rate. + 3 month Treasury rate. month_6 : Optional[float] - 6 month treasury rate. + 6 month Treasury rate. year_1 : Optional[float] - 1 year treasury rate. + 1 year Treasury rate. year_2 : Optional[float] - 2 year treasury rate. + 2 year Treasury rate. year_3 : Optional[float] - 3 year treasury rate. + 3 year Treasury rate. year_5 : Optional[float] - 5 year treasury rate. + 5 year Treasury rate. year_7 : Optional[float] - 7 year treasury rate. + 7 year Treasury rate. year_10 : Optional[float] - 10 year treasury rate. + 10 year Treasury rate. year_20 : Optional[float] - 20 year treasury rate. + 20 year Treasury rate. year_30 : Optional[float] - 30 year treasury rate. + 30 year Treasury rate. Example ------- diff --git a/openbb_platform/openbb/package/index.py b/openbb_platform/openbb/package/index.py index c88ed |