mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
Feature/move package (#5374)
* move package to openbb_sdk * avoid test writing files * black * revert toml changes, will do it in another PR * run build in a separate process * change error msg * rename func * change msg * rename func + msg * change param name * update readme * lazy load some deps * Update README.md * modules is better * doc
This commit is contained in:
6
openbb_sdk/README.md
vendored
6
openbb_sdk/README.md
vendored
@@ -133,13 +133,13 @@ When developing a specific extension `cd` into the extension directory and run:
|
||||
|
||||
`pip install -U -e .`
|
||||
|
||||
While we're still developing, it is required to create the static python interface:
|
||||
While we're still developing, it is often required to reinstall extensions:
|
||||
|
||||
```python
|
||||
python -c "import openbb; openbb._rebuild_python_interface()"
|
||||
python -c "import openbb; openbb.build()"
|
||||
```
|
||||
|
||||
Currently you need to do this before the first launch and every time you install or uninstall a new extension.
|
||||
You need to do this every time you install or uninstall a new extension or to reinstall all extensions.
|
||||
|
||||
### Import time
|
||||
|
||||
|
||||
@@ -6,15 +6,23 @@ from typing import List, Optional, Union
|
||||
|
||||
from openbb_core.app.static.app_factory import create_app as __create_app
|
||||
|
||||
sdk = __create_app()
|
||||
obb = sdk
|
||||
try:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from openbb.package.__extensions__ import Extensions
|
||||
|
||||
obb = sdk = __create_app(Extensions)
|
||||
except (ImportError, ModuleNotFoundError):
|
||||
print(
|
||||
"Failed to import extensions." " Run `openbb.build()` to build extensions code."
|
||||
)
|
||||
obb = sdk = __create_app()
|
||||
|
||||
|
||||
def _rebuild_python_interface(
|
||||
def build(
|
||||
modules: Optional[Union[str, List[str]]] = None,
|
||||
lint: bool = True,
|
||||
) -> None:
|
||||
"""Rebuild the Python SDK.
|
||||
"""Build extension modules.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -25,6 +33,18 @@ def _rebuild_python_interface(
|
||||
lint : bool, optional
|
||||
Whether to lint the code, by default True
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
from multiprocessing import Pool
|
||||
from openbb_core.app.static.package_builder import PackageBuilder
|
||||
|
||||
PackageBuilder.build(modules=modules, lint=lint)
|
||||
current_dir = Path(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
# `build` is run in a separate process to avoid consecutive runs in the same
|
||||
# interpreter to reuse methods already in memory. This was causing docstrings
|
||||
# to have repeated lines.
|
||||
with Pool(processes=1) as pool:
|
||||
pool.apply(
|
||||
PackageBuilder(current_dir).build,
|
||||
args=(modules, lint),
|
||||
)
|
||||
|
||||
@@ -22,54 +22,54 @@ class Extensions(Container):
|
||||
|
||||
@property
|
||||
def crypto(self): # route = "/crypto"
|
||||
from openbb_core.app.static.package import crypto
|
||||
from openbb.package import crypto
|
||||
|
||||
return crypto.CLASS_crypto(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def economy(self): # route = "/economy"
|
||||
from openbb_core.app.static.package import economy
|
||||
from openbb.package import economy
|
||||
|
||||
return economy.CLASS_economy(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def fixedincome(self): # route = "/fixedincome"
|
||||
from openbb_core.app.static.package import fixedincome
|
||||
from openbb.package import fixedincome
|
||||
|
||||
return fixedincome.CLASS_fixedincome(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def forex(self): # route = "/forex"
|
||||
from openbb_core.app.static.package import forex
|
||||
from openbb.package import forex
|
||||
|
||||
return forex.CLASS_forex(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def futures(self): # route = "/futures"
|
||||
from openbb_core.app.static.package import futures
|
||||
from openbb.package import futures
|
||||
|
||||
return futures.CLASS_futures(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def news(self): # route = "/news"
|
||||
from openbb_core.app.static.package import news
|
||||
from openbb.package import news
|
||||
|
||||
return news.CLASS_news(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def qa(self): # route = "/qa"
|
||||
from openbb_core.app.static.package import qa
|
||||
from openbb.package import qa
|
||||
|
||||
return qa.CLASS_qa(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def stocks(self): # route = "/stocks"
|
||||
from openbb_core.app.static.package import stocks
|
||||
from openbb.package import stocks
|
||||
|
||||
return stocks.CLASS_stocks(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def ta(self): # route = "/ta"
|
||||
from openbb_core.app.static.package import ta
|
||||
from openbb.package import ta
|
||||
|
||||
return ta.CLASS_ta(command_runner=self._command_runner)
|
||||
@@ -3,13 +3,12 @@
|
||||
import datetime
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_crypto(Container):
|
||||
@@ -3,15 +3,14 @@
|
||||
import datetime
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
import openbb_core.app.model.command_context
|
||||
import openbb_core.app.model.results.empty
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_economy(Container):
|
||||
@@ -3,13 +3,12 @@
|
||||
import datetime
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_fixedincome(Container):
|
||||
@@ -3,13 +3,12 @@
|
||||
import datetime
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_forex(Container):
|
||||
@@ -3,13 +3,12 @@
|
||||
import datetime
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_futures(Container):
|
||||
@@ -31,38 +31,6 @@
|
||||
"qa_summary": "/qa/summary",
|
||||
"crypto_load": "/crypto/load",
|
||||
"crypto": "/crypto",
|
||||
"ta_atr": "/ta/atr",
|
||||
"ta": "/ta",
|
||||
"ta_fib": "/ta/fib",
|
||||
"ta_obv": "/ta/obv",
|
||||
"ta_fisher": "/ta/fisher",
|
||||
"ta_adosc": "/ta/adosc",
|
||||
"ta_tv": "/ta/tv",
|
||||
"ta_bbands": "/ta/bbands",
|
||||
"ta_multi": "/ta/multi",
|
||||
"ta_zlma": "/ta/zlma",
|
||||
"ta_aroon": "/ta/aroon",
|
||||
"ta_sma": "/ta/sma",
|
||||
"ta_demark": "/ta/demark",
|
||||
"ta_vwap": "/ta/vwap",
|
||||
"ta_recom": "/ta/recom",
|
||||
"ta_macd": "/ta/macd",
|
||||
"ta_hma": "/ta/hma",
|
||||
"ta_donchian": "/ta/donchian",
|
||||
"ta_ichimoku": "/ta/ichimoku",
|
||||
"ta_clenow": "/ta/clenow",
|
||||
"ta_ad": "/ta/ad",
|
||||
"ta_adx": "/ta/adx",
|
||||
"ta_wma": "/ta/wma",
|
||||
"ta_cci": "/ta/cci",
|
||||
"ta_rsi": "/ta/rsi",
|
||||
"ta_summary": "/ta/summary",
|
||||
"ta_stoch": "/ta/stoch",
|
||||
"ta_rsp": "/ta/rsp",
|
||||
"ta_kc": "/ta/kc",
|
||||
"ta_cg": "/ta/cg",
|
||||
"ta_cones": "/ta/cones",
|
||||
"ta_ema": "/ta/ema",
|
||||
"news_globalnews": "/news/globalnews",
|
||||
"news": "/news",
|
||||
"news_sectornews": "/news/sectornews",
|
||||
@@ -208,6 +176,38 @@
|
||||
"stocks_search": "/stocks/search",
|
||||
"stocks_quote": "/stocks/quote",
|
||||
"stocks_info": "/stocks/info",
|
||||
"ta_atr": "/ta/atr",
|
||||
"ta": "/ta",
|
||||
"ta_fib": "/ta/fib",
|
||||
"ta_obv": "/ta/obv",
|
||||
"ta_fisher": "/ta/fisher",
|
||||
"ta_adosc": "/ta/adosc",
|
||||
"ta_tv": "/ta/tv",
|
||||
"ta_bbands": "/ta/bbands",
|
||||
"ta_multi": "/ta/multi",
|
||||
"ta_zlma": "/ta/zlma",
|
||||
"ta_aroon": "/ta/aroon",
|
||||
"ta_sma": "/ta/sma",
|
||||
"ta_demark": "/ta/demark",
|
||||
"ta_vwap": "/ta/vwap",
|
||||
"ta_recom": "/ta/recom",
|
||||
"ta_macd": "/ta/macd",
|
||||
"ta_hma": "/ta/hma",
|
||||
"ta_donchian": "/ta/donchian",
|
||||
"ta_ichimoku": "/ta/ichimoku",
|
||||
"ta_clenow": "/ta/clenow",
|
||||
"ta_ad": "/ta/ad",
|
||||
"ta_adx": "/ta/adx",
|
||||
"ta_wma": "/ta/wma",
|
||||
"ta_cci": "/ta/cci",
|
||||
"ta_rsi": "/ta/rsi",
|
||||
"ta_summary": "/ta/summary",
|
||||
"ta_stoch": "/ta/stoch",
|
||||
"ta_rsp": "/ta/rsp",
|
||||
"ta_kc": "/ta/kc",
|
||||
"ta_cg": "/ta/cg",
|
||||
"ta_cones": "/ta/cones",
|
||||
"ta_ema": "/ta/ema",
|
||||
"economy_corecpi": "/economy/corecpi",
|
||||
"economy": "/economy",
|
||||
"economy_const": "/economy/const",
|
||||
@@ -2,16 +2,15 @@
|
||||
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
import pydantic
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
import openbb_core.app.model.command_context
|
||||
import openbb_core.app.model.results.empty
|
||||
import pydantic
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_news(Container):
|
||||
@@ -2,17 +2,16 @@
|
||||
|
||||
from typing import List, Literal, Union
|
||||
|
||||
import openbb_core.app.model.results.empty
|
||||
import openbb_provider
|
||||
import openbb_qa.qa_models
|
||||
import pandas
|
||||
import pydantic
|
||||
import pydantic.types
|
||||
from pydantic import validate_arguments
|
||||
|
||||
import openbb_core.app.model.results.empty
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
|
||||
|
||||
class CLASS_qa(Container):
|
||||
@@ -3,16 +3,15 @@
|
||||
import datetime
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
import pydantic
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
import openbb_core.app.model.command_context
|
||||
import openbb_core.app.model.results.empty
|
||||
import pydantic
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_stocks(Container):
|
||||
@@ -39,37 +38,37 @@ class CLASS_stocks(Container):
|
||||
|
||||
@property
|
||||
def ca(self): # route = "/stocks/ca"
|
||||
from openbb_core.app.static.package import stocks_ca
|
||||
from openbb.package import stocks_ca
|
||||
|
||||
return stocks_ca.CLASS_stocks_ca(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def dd(self): # route = "/stocks/dd"
|
||||
from openbb_core.app.static.package import stocks_dd
|
||||
from openbb.package import stocks_dd
|
||||
|
||||
return stocks_dd.CLASS_stocks_dd(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def disc(self): # route = "/stocks/disc"
|
||||
from openbb_core.app.static.package import stocks_disc
|
||||
from openbb.package import stocks_disc
|
||||
|
||||
return stocks_disc.CLASS_stocks_disc(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def dps(self): # route = "/stocks/dps"
|
||||
from openbb_core.app.static.package import stocks_dps
|
||||
from openbb.package import stocks_dps
|
||||
|
||||
return stocks_dps.CLASS_stocks_dps(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def fa(self): # route = "/stocks/fa"
|
||||
from openbb_core.app.static.package import stocks_fa
|
||||
from openbb.package import stocks_fa
|
||||
|
||||
return stocks_fa.CLASS_stocks_fa(command_runner=self._command_runner)
|
||||
|
||||
@property
|
||||
def gov(self): # route = "/stocks/gov"
|
||||
from openbb_core.app.static.package import stocks_gov
|
||||
from openbb.package import stocks_gov
|
||||
|
||||
return stocks_gov.CLASS_stocks_gov(command_runner=self._command_runner)
|
||||
|
||||
@@ -192,7 +191,7 @@ class CLASS_stocks(Container):
|
||||
|
||||
@property
|
||||
def ins(self): # route = "/stocks/ins"
|
||||
from openbb_core.app.static.package import stocks_ins
|
||||
from openbb.package import stocks_ins
|
||||
|
||||
return stocks_ins.CLASS_stocks_ins(command_runner=self._command_runner)
|
||||
|
||||
@@ -664,7 +663,7 @@ class CLASS_stocks(Container):
|
||||
|
||||
@property
|
||||
def options(self): # route = "/stocks/options"
|
||||
from openbb_core.app.static.package import stocks_options
|
||||
from openbb.package import stocks_options
|
||||
|
||||
return stocks_options.CLASS_stocks_options(command_runner=self._command_runner)
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import BaseModel, validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
import openbb_core.app.model.command_context
|
||||
import openbb_core.app.model.results.empty
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import BaseModel, validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_stocks_ca(Container):
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_stocks_dd(Container):
|
||||
@@ -1,12 +1,11 @@
|
||||
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###
|
||||
|
||||
|
||||
from pydantic import validate_arguments
|
||||
|
||||
import openbb_core.app.model.results.empty
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
|
||||
|
||||
class CLASS_stocks_disc(Container):
|
||||
@@ -1,12 +1,11 @@
|
||||
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###
|
||||
|
||||
|
||||
from pydantic import validate_arguments
|
||||
|
||||
import openbb_core.app.model.results.empty
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
|
||||
|
||||
class CLASS_stocks_dps(Container):
|
||||
@@ -3,17 +3,16 @@
|
||||
import datetime
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
import pydantic
|
||||
import pydantic.main
|
||||
from pydantic import BaseModel, validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
import openbb_core.app.model.command_context
|
||||
import openbb_core.app.model.results.empty
|
||||
import pydantic
|
||||
import pydantic.main
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import BaseModel, validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_stocks_fa(Container):
|
||||
@@ -1,12 +1,11 @@
|
||||
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###
|
||||
|
||||
|
||||
from pydantic import validate_arguments
|
||||
|
||||
import openbb_core.app.model.results.empty
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
|
||||
|
||||
class CLASS_stocks_gov(Container):
|
||||
@@ -1,12 +1,11 @@
|
||||
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###
|
||||
|
||||
|
||||
from pydantic import validate_arguments
|
||||
|
||||
import openbb_core.app.model.results.empty
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
|
||||
|
||||
class CLASS_stocks_ins(Container):
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
import openbb_core.app.model.command_context
|
||||
import openbb_core.app.model.results.empty
|
||||
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
from typing_extensions import Annotated
|
||||
|
||||
|
||||
class CLASS_stocks_options(Container):
|
||||
@@ -2,16 +2,15 @@
|
||||
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
import openbb_core.app.model.results.empty
|
||||
import openbb_provider
|
||||
import pandas
|
||||
import pydantic
|
||||
import pydantic.types
|
||||
from pydantic import validate_arguments
|
||||
|
||||
import openbb_core.app.model.results.empty
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.filters import filter_inputs
|
||||
from pydantic import validate_arguments
|
||||
|
||||
|
||||
class CLASS_ta(Container):
|
||||
@@ -1,26 +1,22 @@
|
||||
"""App factory."""
|
||||
# pylint: disable=W0231:super-init-not-called
|
||||
|
||||
from typing import Optional, Type, TypeVar
|
||||
|
||||
from openbb_core.app.command_runner import CommandRunner
|
||||
from openbb_core.app.model.system_settings import SystemSettings
|
||||
from openbb_core.app.model.user_settings import UserSettings
|
||||
from openbb_core.app.static.account import Account
|
||||
from openbb_core.app.static.container import Container
|
||||
from openbb_core.app.static.coverage import Coverage
|
||||
|
||||
E = TypeVar("E", bound=Type[Container])
|
||||
|
||||
def create_app():
|
||||
|
||||
def create_app(extensions: Optional[E] = None):
|
||||
"""Create the app."""
|
||||
try:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from openbb_core.app.static.package.__extensions__ import Extensions
|
||||
except ImportError as e:
|
||||
raise Exception(
|
||||
"If you are seeing this exception, you should probably be doing: "
|
||||
"from openbb_core.app.static.package_builder import PackageBuilder\n"
|
||||
"PackageBuilder.build()"
|
||||
) from e
|
||||
|
||||
class App(Extensions):
|
||||
class App(extensions or Container): # type: ignore
|
||||
# fmt: off
|
||||
"""OpenBB SDK.
|
||||
|
||||
@@ -40,7 +36,10 @@ Extensions:"""
|
||||
|
||||
def __repr__(self) -> str:
|
||||
# pylint: disable=E1101
|
||||
return (self.__doc__ or "") + (super().__doc__ or "")
|
||||
ext_doc = (
|
||||
super().__doc__ if extensions else "\n No extensions installed."
|
||||
)
|
||||
return (self.__doc__ or "") + (ext_doc or "")
|
||||
|
||||
@property
|
||||
def account(self) -> Account:
|
||||
|
||||
@@ -36,22 +36,24 @@ from openbb_core.app.router import RouterLoader
|
||||
class PackageBuilder:
|
||||
"""Build the extension package for the SDK."""
|
||||
|
||||
@classmethod
|
||||
def __init__(self, directory: Optional[Path] = None) -> None:
|
||||
self.directory = directory or Path(__file__).parent
|
||||
|
||||
def build(
|
||||
cls,
|
||||
self,
|
||||
modules: Optional[Union[str, List[str]]] = None,
|
||||
lint: bool = True,
|
||||
) -> None:
|
||||
"""Build the extensions for the SDK."""
|
||||
print("\nBuilding extensions package...\n")
|
||||
cls.save_module_map()
|
||||
cls.save_modules(modules)
|
||||
cls.save_package()
|
||||
if lint:
|
||||
cls.run_linters()
|
||||
|
||||
@classmethod
|
||||
def save_module_map(cls):
|
||||
self.save_module_map()
|
||||
self.save_modules(modules)
|
||||
self.save_package()
|
||||
if lint:
|
||||
self.run_linters(self.directory)
|
||||
|
||||
def save_module_map(self):
|
||||
"""Save the module map."""
|
||||
route_map = PathHandler.build_route_map()
|
||||
path_list = PathHandler.build_path_list(route_map=route_map)
|
||||
@@ -61,12 +63,11 @@ class PackageBuilder:
|
||||
module_code = dumps(obj=module_map, indent=4)
|
||||
module_name = "module_map"
|
||||
print("Writing module map...")
|
||||
cls.write_to_package(
|
||||
self.write_to_package(
|
||||
module_code=module_code, module_name=module_name, extension="json"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def save_modules(cls, modules: Optional[Union[str, List[str]]] = None):
|
||||
def save_modules(self, modules: Optional[Union[str, List[str]]] = None):
|
||||
"""Save the modules."""
|
||||
print("\nWriting modules...")
|
||||
route_map = PathHandler.build_route_map()
|
||||
@@ -87,26 +88,25 @@ class PackageBuilder:
|
||||
module_code = ModuleBuilder.build(path=path)
|
||||
module_name = PathHandler.build_module_name(path=path)
|
||||
print(f"({path})", end=" " * (MAX_LEN - len(path)))
|
||||
cls.write_to_package(module_code=module_code, module_name=module_name)
|
||||
self.write_to_package(module_code=module_code, module_name=module_name)
|
||||
|
||||
@classmethod
|
||||
def save_package(cls):
|
||||
def save_package(self):
|
||||
"""Save the package."""
|
||||
print("\nWriting package __init__...")
|
||||
code = "### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###\n"
|
||||
cls.write_to_package(module_code=code, module_name="__init__")
|
||||
|
||||
@classmethod
|
||||
def run_linters(cls):
|
||||
"""Run the linters."""
|
||||
print("\nRunning linters...")
|
||||
Linters.ruff()
|
||||
Linters.black()
|
||||
self.write_to_package(module_code=code, module_name="__init__")
|
||||
|
||||
@staticmethod
|
||||
def write_to_package(module_code: str, module_name, extension="py") -> None:
|
||||
def run_linters(directory: Path):
|
||||
"""Run the linters."""
|
||||
print("\nRunning linters...")
|
||||
linters = Linters(directory)
|
||||
linters.ruff()
|
||||
linters.black()
|
||||
|
||||
def write_to_package(self, module_code: str, module_name, extension="py") -> None:
|
||||
"""Write the module to the package."""
|
||||
package_folder = Path(__file__).parent / "package"
|
||||
package_folder = self.directory / "package"
|
||||
package_path = package_folder / f"{module_name}.{extension}"
|
||||
|
||||
package_folder.mkdir(exist_ok=True)
|
||||
@@ -406,7 +406,7 @@ class MethodDefinition:
|
||||
|
||||
code = "\n @property\n"
|
||||
code += f' def {function_name}(self): # route = "{path}"\n'
|
||||
code += f" from openbb_core.app.static.package import {module_name}\n"
|
||||
code += f" from openbb.package import {module_name}\n"
|
||||
code += f" return {module_name}.{class_name}(command_runner=self._command_runner)\n"
|
||||
|
||||
return code
|
||||
@@ -770,47 +770,46 @@ class Linters:
|
||||
"""Run the linters for the SDK."""
|
||||
|
||||
debug_mode = Env().DEBUG_MODE
|
||||
current_folder = str(Path(Path(__file__).parent, "package").absolute())
|
||||
|
||||
def __init__(self, directory: Path) -> None:
|
||||
self.directory = directory
|
||||
|
||||
@staticmethod
|
||||
def print_separator(symbol: str, length: int = 160):
|
||||
"""Print a separator."""
|
||||
print(symbol * length)
|
||||
|
||||
@classmethod
|
||||
def run(
|
||||
cls,
|
||||
self,
|
||||
linter: Literal["black", "ruff"],
|
||||
flags: Optional[List[str]] = None,
|
||||
):
|
||||
"""Run linter with flags."""
|
||||
if shutil.which(linter):
|
||||
print(f"\n* {linter}")
|
||||
if cls.debug_mode:
|
||||
if self.debug_mode:
|
||||
Linters.print_separator("^")
|
||||
|
||||
command = [linter, Linters.current_folder]
|
||||
command = [linter, self.directory]
|
||||
if flags:
|
||||
command.extend(flags)
|
||||
subprocess.run(command, check=False) # noqa: S603
|
||||
|
||||
if cls.debug_mode:
|
||||
if self.debug_mode:
|
||||
Linters.print_separator("-")
|
||||
else:
|
||||
print(f"\n* {linter} not found")
|
||||
|
||||
@classmethod
|
||||
def black(cls):
|
||||
def black(self):
|
||||
"""Run black."""
|
||||
flags = []
|
||||
if not cls.debug_mode:
|
||||
if not self.debug_mode:
|
||||
flags.append("--quiet")
|
||||
cls.run(linter="black", flags=flags)
|
||||
self.run(linter="black", flags=flags)
|
||||
|
||||
@classmethod
|
||||
def ruff(cls):
|
||||
def ruff(self):
|
||||
"""Run ruff."""
|
||||
flags = ["--fix"]
|
||||
if not cls.debug_mode:
|
||||
if not self.debug_mode:
|
||||
flags.append("--silent")
|
||||
cls.run(linter="ruff", flags=flags)
|
||||
self.run(linter="ruff", flags=flags)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
"""Test the path_tracking_file_handler.py file."""
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
@@ -25,14 +28,19 @@ logging_settings.session_id = "test_session_id"
|
||||
logging_settings.frequency = "H"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def handler():
|
||||
@pytest.fixture(scope="module")
|
||||
def mocked_path(tmp_path_factory):
|
||||
return tmp_path_factory.mktemp("mocked_path") / "mocked_file.log"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def handler(mocked_path):
|
||||
# patch `pathlib.Path.joinpath` to return a string containing the joined path
|
||||
with patch.object(Path, "joinpath", return_value=Path("mocked_path")):
|
||||
with patch.object(Path, "joinpath", return_value=mocked_path):
|
||||
return PathTrackingFileHandler(logging_settings)
|
||||
|
||||
|
||||
def test_build_log_file_path(handler):
|
||||
def test_build_log_file_path(handler, mocked_path):
|
||||
# Define a sample LoggingSettings object with mock attributes
|
||||
settings = MagicMock(spec=MockLoggingSettings)
|
||||
settings.app_name = "my_app"
|
||||
@@ -41,13 +49,11 @@ def test_build_log_file_path(handler):
|
||||
settings.session_id = "abc123"
|
||||
|
||||
# patch `pathlib.Path.joinpath` to return a string containing the joined path
|
||||
with patch.object(
|
||||
Path, "joinpath", return_value=Path("mocked_path")
|
||||
) as mock_joinpath:
|
||||
with patch.object(Path, "joinpath", return_value=mocked_path) as mock_joinpath:
|
||||
result_path = handler.build_log_file_path(settings)
|
||||
|
||||
# Assert the result is correct
|
||||
assert result_path == Path("mocked_path")
|
||||
assert result_path == mocked_path
|
||||
|
||||
mock_joinpath.assert_called_once_with("my_app_abc123")
|
||||
|
||||
|
||||
@@ -22,9 +22,14 @@ from typing_extensions import Annotated
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def package_builder():
|
||||
def tmp_package_dir(tmp_path_factory):
|
||||
return tmp_path_factory.mktemp("package")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def package_builder(tmp_package_dir):
|
||||
"""Return package builder."""
|
||||
return PackageBuilder()
|
||||
return PackageBuilder(tmp_package_dir)
|
||||
|
||||
|
||||
def test_package_builder_init(package_builder):
|
||||
@@ -58,7 +63,7 @@ def test_save_package(package_builder):
|
||||
|
||||
def test_run_linters(package_builder):
|
||||
"""Test run linters."""
|
||||
package_builder.run_linters()
|
||||
package_builder.run_linters(package_builder.directory)
|
||||
|
||||
|
||||
@pytest.mark.skip("We avoid writing to the package.")
|
||||
@@ -431,9 +436,9 @@ def test_build_module_class(path_handler):
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def linters():
|
||||
def linters(tmp_package_dir):
|
||||
"""Return linters."""
|
||||
return Linters()
|
||||
return Linters(tmp_package_dir)
|
||||
|
||||
|
||||
def test_linters_init(linters):
|
||||
|
||||
Reference in New Issue
Block a user