Merge remote-tracking branch 'upstream/feature/openbb-sdk-v4' into feature/sdk-j2

This commit is contained in:
James Maslek
2023-08-15 08:58:40 -04:00
10 changed files with 173 additions and 490 deletions

View File

@@ -12,9 +12,9 @@ on:
types: [opened, synchronize, edited]
push:
branches:
- 'feature/*'
- 'hotfix/*'
- 'release/*'
- "feature/*"
- "hotfix/*"
- "release/*"
merge_group:
types: [checks_requested]
@@ -74,4 +74,4 @@ jobs:
id: json-yaml-validate
uses: GrantBirki/json-yaml-validate@v2.0.0
with:
exclude_file: json_validate_exclude.txt
exclude_file: json_validate_exclude.txt

View File

@@ -17,6 +17,17 @@ repos:
rev: "v0.0.256"
hooks:
- id: ruff
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
name: pydocstyle
entry: pydocstyle
language: python
types: [python]
files: '^openbb_sdk/.*\.py$'
exclude: 'tests/.*\.py|openbb_sdk/test_.*\.py'
args: ["--config=pyproject.toml"]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:

33
openbb_sdk/install_all.bat vendored Normal file
View File

@@ -0,0 +1,33 @@
@echo off
setlocal enabledelayedexpansion
REM Check if CONDA_PREFIX is set to check for an active conda environment
IF NOT DEFINED CONDA_PREFIX (
echo No active conda environment detected.
exit /b
)
REM Add path to the Python executable in the active conda environment
SET "PYTHON_PATH=%CONDA_PREFIX%\python.exe"
REM Verify the python executable exists
IF NOT EXIST "%PYTHON_PATH%" (
echo Python executable not found in active conda environment.
exit /b
)
echo Installing all packages in editable mode ...
for /d /r %%d in (openbb_*) do (
REM Extract the parent directory from the full path
for %%i in ("%%~dpd") do set "parentdir=%%~dpi"
REM Move up one level to the parent directory
set "parentdir=!parentdir:~0,-1!"
for %%j in (!parentdir!) do set "dirname=%%~nxj"
echo Installing !dirname!
pushd "!parentdir!"
"%PYTHON_PATH%" -m pip install -U -e . >NUL 2>&1
popd
)

View File

@@ -12,7 +12,7 @@
- [Install extension](#install-extension)
- [4. Usage](#4-usage)
- [4.1 Static version](#41-static-version)
- [4.1.1. Command output](#411-command-output)
- [4.1.1. OBBject](#411-obbject)
- [Helpers](#helpers)
- [4.1.2. Utilities](#412-utilities)
- [Settings](#settings)
@@ -163,7 +163,7 @@ output = obb.stocks.load(
)
```
### 4.1.1. Command output
### 4.1.1. OBBject
Each command will always return a `OBBject`. There you will find:

View File

@@ -1,5 +1,5 @@
from dataclasses import dataclass, make_dataclass
from typing import Any, Dict, List, Literal, Optional, Tuple, Type, Union
from typing import Any, Dict, List, Literal, Optional, Tuple, Type, TypeVar, Union
from fastapi import Query
from openbb_provider.query_executor import QueryExecutor
@@ -7,13 +7,15 @@ from openbb_provider.registry_map import MapType, RegistryMap
from pydantic import BaseConfig, BaseModel, Extra, Field, create_model
from pydantic.fields import ModelField
TupleFieldType = TypeVar("TupleFieldType", bound=Tuple[str, type, Any])
@dataclass
class DataclassField:
"""Dataclass field."""
name: str
type_: Any
type_: type
default: Any
@@ -169,7 +171,7 @@ class ProviderInterface:
return DataclassField(
name=current_name,
type_=merged_type,
type_=merged_type, # type: ignore
default=merged_default,
)
@@ -220,10 +222,10 @@ class ProviderInterface:
def _extract_params(
cls,
providers: Any,
) -> Tuple[Dict[str, Tuple[str, type, Any]], Dict[str, Tuple[str, type, Any]]]:
) -> Tuple[Dict[str, TupleFieldType], Dict[str, TupleFieldType]]:
"""Extract parameters from map."""
standard: Dict[str, Tuple[str, Any, Any]] = {}
extra: Dict[str, Tuple[str, Any, Any]] = {}
standard: Dict[str, TupleFieldType] = {}
extra: Dict[str, TupleFieldType] = {}
for provider_name, model_details in providers.items():
if provider_name == "openbb":
@@ -267,9 +269,9 @@ class ProviderInterface:
def _extract_data(
cls,
providers: Any,
) -> Tuple[Dict[str, Tuple[str, type, Any]], Dict[str, Tuple[str, type, Any]]]:
standard: Dict[str, Tuple[str, Any, Any]] = {}
extra: Dict[str, Tuple[str, Any, Any]] = {}
) -> Tuple[Dict[str, TupleFieldType], Dict[str, TupleFieldType]]:
standard: Dict[str, TupleFieldType] = {}
extra: Dict[str, TupleFieldType] = {}
for provider_name, model_details in providers.items():
if provider_name == "openbb":
@@ -326,8 +328,9 @@ class ProviderInterface:
"""
result: Dict = {}
# TODO: Consider multiprocessing this loop to speed startup
for model_name, providers in map_.items():
standard: dict
extra: dict
standard, extra = self._extract_params(providers)
result[model_name] = {
@@ -392,6 +395,8 @@ class ProviderInterface:
result: Dict = {}
for model_name, providers in map_.items():
standard: dict
extra: dict
standard, extra = self._extract_data(providers)
result[model_name] = {
"standard": make_dataclass( # type: ignore

View File

@@ -5,8 +5,10 @@ from dataclasses import dataclass
from inspect import _empty
import pytest
from openbb_core.app.provider_interface import get_provider_interface
from openbb_core.app.static.package_builder import (
ClassDefinition,
DocstringGenerator,
ImportDefinition,
Linters,
MethodDefinition,
@@ -446,4 +448,84 @@ def test_mypy(linters):
linters.mypy()
# TODO: Implement unit test for the DocstringGenerator class once refactored.
@pytest.fixture(scope="module")
def docstring_generator():
"""Return package builder."""
return DocstringGenerator()
def test_docstring_generator_init(docstring_generator):
"""Test docstring generator init."""
assert docstring_generator
def test_get_object_description(docstring_generator):
"""Test build docstring."""
docstring = docstring_generator.get_object_description()
assert docstring
def test_get_available_providers(docstring_generator):
"""Test get available providers."""
provider_assert = ["fmp", "polygon"]
some_mapping = {"fmp": 1, "openbb": 2, "polygon": 3}
providers = docstring_generator.get_available_providers(query_mapping=some_mapping)
assert providers
for provider in provider_assert:
assert provider in providers
def test_reorder_dictionary(docstring_generator):
"""Test reorder dictionary."""
some_mapping = {"fmp": 1, "openbb": 2, "polygon": 3}
reordered = docstring_generator.reorder_dictionary(
dictionary=some_mapping, key_to_move_first="openbb"
)
assert reordered
assert list(reordered.keys())[0] == "openbb"
def test_extract_field_details(docstring_generator):
"""Test extract field details."""
mapping = get_provider_interface().map
section_docstring = docstring_generator.extract_field_details(
model_name="GlobalNews",
provider="openbb",
section_name="QueryParams",
section_docstring="some_param: str\n Some param description\n",
mapping=mapping,
)
assert section_docstring
assert "some_param" in section_docstring
def test_generate_provider_docstrings(docstring_generator):
"""Test generate provider docstrings."""
docstring = ""
model_name = "GlobalNews"
provider_interface_mapping = get_provider_interface().map
query_mapping = provider_interface_mapping.get(model_name, None)
docstring = docstring_generator.generate_provider_docstrings(
docstring=docstring,
query_mapping=query_mapping,
model_name=model_name,
provider_interface_mapping=provider_interface_mapping,
)
assert docstring
assert "openbb" in docstring
assert "GlobalNews" in docstring
def test_generate_command_docstring(docstring_generator):
"""Test generate command docstring."""
def some_func():
"""Some func docstring."""
pass
docstring = docstring_generator.generate_command_docstring(
func=some_func, model_name="GlobalNews"
)
assert docstring
assert "openbb" in docstring.__doc__

484
poetry.lock generated vendored

File diff suppressed because it is too large Load Diff

2
pyproject.toml vendored
View File

@@ -170,7 +170,7 @@ build-backend = "poetry.core.masonry.api"
[tool.pydocstyle]
convention = "numpy"
match = '((?!test_).)*\.py'
ignore = "D401"
add-ignore = "D401"
[tool.ruff]

View File

@@ -14,7 +14,7 @@ ansiwrap==0.8.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9
antlr4-python3-runtime==4.11.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
anyio==3.7.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
appdirs==1.4.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
appnope==0.1.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and sys_platform == "darwin" or python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and platform_system == "Darwin"
appnope==0.1.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (sys_platform == "darwin" or platform_system == "Darwin")
arch==5.6.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
argon2-cffi-bindings==21.2.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
argon2-cffi==21.3.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
@@ -122,7 +122,7 @@ google-auth-oauthlib==1.0.0 ; python_full_version >= "3.8.1" and python_full_ver
google-auth==2.22.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
graphlib-backport==1.0.3 ; python_full_version >= "3.8.1" and python_version < "3.9"
graphviz==0.20.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
greenlet==2.0.2 ; python_full_version >= "3.8.1" and platform_machine == "aarch64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "ppc64le" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "x86_64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "amd64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "AMD64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "win32" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "WIN32" and python_full_version != "3.9.7" and python_version < "3.11"
greenlet==2.0.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (platform_machine == "win32" or platform_machine == "WIN32" or platform_machine == "AMD64" or platform_machine == "amd64" or platform_machine == "x86_64" or platform_machine == "ppc64le" or platform_machine == "aarch64")
grpcio==1.56.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
h11==0.14.0 ; python_full_version >= "3.8.1" and python_version < "3.11" and python_full_version != "3.9.7"
hijri-converter==2.3.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
@@ -257,7 +257,7 @@ property-cached==1.6.4 ; python_full_version >= "3.8.1" and python_full_version
prophet==1.1.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
protobuf==3.20.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
psutil==5.9.5 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
ptyprocess==0.7.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and sys_platform != "win32" or python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and os_name != "nt"
ptyprocess==0.7.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (sys_platform != "win32" or os_name != "nt")
pure-eval==0.2.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
py==1.11.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pyarrow==12.0.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"

6
requirements.txt vendored
View File

@@ -8,7 +8,7 @@ altair==5.0.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7
ansiwrap==0.8.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
anyio==3.7.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
appdirs==1.4.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
appnope==0.1.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and sys_platform == "darwin" or python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and platform_system == "Darwin"
appnope==0.1.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (sys_platform == "darwin" or platform_system == "Darwin")
arch==5.6.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
argon2-cffi-bindings==21.2.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
argon2-cffi==21.3.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
@@ -80,7 +80,7 @@ future==0.18.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.
gitdb==4.0.10 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
gitpython==3.1.32 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
graphlib-backport==1.0.3 ; python_full_version >= "3.8.1" and python_version < "3.9"
greenlet==2.0.2 ; python_full_version >= "3.8.1" and platform_machine == "aarch64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "ppc64le" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "x86_64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "amd64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "AMD64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "win32" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "WIN32" and python_full_version != "3.9.7" and python_version < "3.11"
greenlet==2.0.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (platform_machine == "win32" or platform_machine == "WIN32" or platform_machine == "AMD64" or platform_machine == "amd64" or platform_machine == "x86_64" or platform_machine == "ppc64le" or platform_machine == "aarch64")
grpcio==1.56.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
h11==0.14.0 ; python_full_version >= "3.8.1" and python_version < "3.11" and python_full_version != "3.9.7"
hijri-converter==2.3.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
@@ -178,7 +178,7 @@ prompt-toolkit==3.0.39 ; python_full_version >= "3.8.1" and python_full_version
property-cached==1.6.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
protobuf==3.20.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
psutil==5.9.5 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
ptyprocess==0.7.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and sys_platform != "win32" or python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and os_name != "nt"
ptyprocess==0.7.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (sys_platform != "win32" or os_name != "nt")
pure-eval==0.2.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pyarrow==12.0.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pyasn1==0.5.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"