Files
OpenBB/openbb_sdk/dev_install.py
teh_coderer 6a9308c3e7 Feature/sdk v4 pydantic v2 (#5458)
* init

* Update provider_interface.py

* docstring

* pydantic v2

* Update __init__.py

* build package v2 support

* `alises` to `aliases`

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>

* `alises` to `aliases`

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>

* `alises` to `aliases`

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>

* updates

* Update registry.py

* validate_arguments -> validate_call

* update terminal classes

* response_model_by_alias = False

* query_params by alias

* Update major_indices_constituents.py

* add alias to Query in `provider_interface`

* yfinance

* build package, add param defaults and correct `OBBject` results type

* fix cpi validation errors

* Update risk_premium.py

* fix `forex_pairs` active query param annotation, set default when only 1 provider

* fix and refactor intrinio `options_chains`

* Update poetry.lock

* fix benzinga news, build package, add intrinio fred_historical fetcher

* Update extension_map.json

* ruff

* Update unit_test_generator.py

* updates

* add `default=None` on Optional fields

* `parse_obj` -> `model_validate`

* add alias to dup fields on providers with `__alias_dict__`, fix `test_generate_model_docstring`

* Update package_builder.py

* fix validation errors, fix tests

* tests http

* `fred_historical` record

* Update test_intrinio_fetchers.py

* Update test_intrinio_fetchers.py

* Update test_intrinio_fetchers.py

* Update available_indices.py

* Update stock_historical.py

* build package

* build package without optional

* change `SystemSettings` -> `MockSystemSettings` in `test_system_settings.py`

* `openbb_figure.py`/`backend.py` terminal changes  , update deps/lock files

* `linearmodels>4.26`  auto installs `setuptools-scm` which cause error messages

* clean up

* `dev_install.py` for local development

* ruff

* dup `# noqa`

* build

* Update bitquery_model.py

* records

* rec

* f

* worky?

* update `integration_test_generator.py` and `unit_test_generator.py`

* renamed test to tests in file

* fix import due to change in file name

---------

Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
2023-09-27 09:40:07 +01:00

98 lines
3.5 KiB
Python

# noqa: S603,PLW1510,T201
import subprocess
import sys
from pathlib import Path
import toml
SDK_PATH = Path(__file__).parent.resolve()
LOCK = SDK_PATH / "poetry.lock"
PYPROJECT = SDK_PATH / "pyproject.toml"
LOCAL_DEPS = """
[tool.poetry.dependencies]
python = ">=3.8,<3.12"
openbb-provider = { path = "./sdk/provider", develop = true }
openbb-core = { path = "./sdk/core", develop = true }
openbb-benzinga = { path = "./providers/benzinga", develop = true }
openbb-fmp = { path = "./providers/fmp", develop = true }
openbb-fred = { path = "./providers/fred", develop = true }
openbb-intrinio = { path = "./providers/intrinio", develop = true }
openbb-polygon = { path = "./providers/polygon", develop = true }
openbb-crypto = { path = "./extensions/crypto", develop = true }
openbb-economy = { path = "./extensions/economy", develop = true }
openbb-forex = { path = "./extensions/forex", develop = true }
openbb-fixedincome = { path = "./extensions/fixedincome", develop = true }
openbb-news = { path = "./extensions/news", develop = true }
openbb-stocks = { path = "./extensions/stocks", develop = true }
# Community dependencies
openbb-alpha-vantage = { path = "./providers/alpha_vantage", optional = true, develop = true }
openbb-cboe = { path = "./providers/cboe", optional = true, develop = true }
openbb-quandl = { path = "./providers/quandl", optional = true, develop = true }
openbb-yfinance = { path = "./providers/yfinance", optional = true, develop = true }
openbb-charting = { path = "./extensions/charting", optional = true, develop = true }
openbb-futures = { path = "./extensions/futures", optional = true, develop = true }
openbb-qa = { path = "./extensions/qa", optional = true, develop = true }
openbb-ta = { path = "./extensions/ta", optional = true, develop = true }
openbb-econometrics = { path = "./extensions/econometrics", optional = true, develop = true }
"""
pyproject_toml = toml.load(PYPROJECT)
pyproject_toml["tool"]["poetry"]["dependencies"] = toml.loads(LOCAL_DEPS)["tool"][
"poetry"
]["dependencies"]
TEMP_PYPROJECT = toml.dumps(pyproject_toml)
def install_local(extras: bool = False):
"""Install the SDK locally for development purposes.
Installs the SDK in editable mode, instead of copying the source code to
the site-packages directory. This makes any changes immediately available
to the interpreter.
Parameters
----------
extras : bool, optional
Whether to install the SDK with the extra dependencies, by default False
"""
orginal_lock = LOCK.read_text()
orginal_pyproject = PYPROJECT.read_text()
extras_args = ["-E", "all"] if extras else []
try:
# we create a temporary pyproject.toml
PYPROJECT.write_text(TEMP_PYPROJECT)
CMD = [sys.executable, "-m", "poetry"]
subprocess.run( # noqa: PLW1510
CMD + ["lock", "--no-update"], cwd=SDK_PATH # noqa: S603
)
subprocess.run( # noqa: PLW1510
CMD + ["install"] + extras_args, cwd=SDK_PATH # noqa: S603
)
except (Exception, KeyboardInterrupt) as e:
print(e) # noqa: T201
print("Restoring pyproject.toml and poetry.lock") # noqa: T201
# we restore the original pyproject.toml
with open(PYPROJECT, "w", encoding="utf-8", newline="\n") as f:
f.write(orginal_pyproject)
# we restore the original poetry.lock
with open(LOCK, "w", encoding="utf-8", newline="\n") as f:
f.write(orginal_lock)
if __name__ == "__main__":
args = sys.argv[1:]
extras = any([arg.lower() in ["-e", "--extras"] for arg in args])
install_local(extras)