From 4c4f57fa78879b0700affc5552f8dd2145608d82 Mon Sep 17 00:00:00 2001 From: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Date: Thu, 16 May 2024 18:14:30 +0100 Subject: [BugFix] - `dev_install.py` updates (#6424) * fix: use tomlkit instead of toml & add --cli * fix: remove cli option, poetry groups ignored by pip * fix: redirect unittest patch * adding --cli to the dev install --------- Co-authored-by: hjoaquim --- cli/openbb_cli/cli.py | 9 +++-- cli/poetry.lock | 80 +++++++++++++++++++----------------------- cli/pyproject.toml | 2 +- cli/tests/test_cli.py | 16 ++++----- openbb_platform/dev_install.py | 80 +++++++++++++++++++++++++++++++++--------- 5 files changed, 115 insertions(+), 72 deletions(-) diff --git a/cli/openbb_cli/cli.py b/cli/openbb_cli/cli.py index c301be893f9..0d9e3e3d0fd 100644 --- a/cli/openbb_cli/cli.py +++ b/cli/openbb_cli/cli.py @@ -2,12 +2,15 @@ import sys -from openbb_cli.config.setup import bootstrap -from openbb_cli.controllers.cli_controller import launch - def main(): """Use the main entry point for the OpenBB CLI.""" + print("Loading...\n") # noqa: T201 + + # pylint: disable=import-outside-toplevel + from openbb_cli.config.setup import bootstrap + from openbb_cli.controllers.cli_controller import launch + bootstrap() dev = "--dev" in sys.argv[1:] diff --git a/cli/poetry.lock b/cli/poetry.lock index 2ff7f9d5b19..3426b56602b 100644 --- a/cli/poetry.lock +++ b/cli/poetry.lock @@ -263,13 +263,13 @@ files = [ [[package]] name = "astroid" -version = "3.2.0" +version = "3.2.1" description = "An abstract syntax tree for Python with inference support." optional = false python-versions = ">=3.8.0" files = [ - {file = "astroid-3.2.0-py3-none-any.whl", hash = "sha256:16ee8ca5c75ac828783028cc1f967777f0e507c6886a295ad143e0f405b975a2"}, - {file = "astroid-3.2.0.tar.gz", hash = "sha256:f7f829f8506ade59f1b3c6c93d8fac5b1ebc721685fa9af23e9794daf1d450a3"}, + {file = "astroid-3.2.1-py3-none-any.whl", hash = "sha256:b452064132234819f023b94f4bd045b250ea0009f372b4377cfcd87f10806ca5"}, + {file = "astroid-3.2.1.tar.gz", hash = "sha256:902564b36796ba1eab3ad2c7a694861fbd926f574d5dbb5fa1d86778a2ba2d91"}, ] [package.dependencies] @@ -6356,62 +6356,54 @@ repair = ["scipy (>=1.6.3)"] [[package]] name = "zipp" -version = "3.18.1" +version = "3.18.2" description = "Backport of pathlib-compatible object wrapper for zip files" optional = false python-versions = ">=3.8" files = [ - {file = "zipp-3.18.1-py3-none-any.whl", hash = "sha256:206f5a15f2af3dbaee80769fb7dc6f249695e940acca08dfb2a4769fe61e538b"}, - {file = "zipp-3.18.1.tar.gz", hash = "sha256:2884ed22e7d8961de1c9a05142eb69a247f120291bc0206a00a7642f09b5b715"}, + {file = "zipp-3.18.2-py3-none-any.whl", hash = "sha256:dce197b859eb796242b0622af1b8beb0a722d52aa2f57133ead08edd5bf5374e"}, + {file = "zipp-3.18.2.tar.gz", hash = "sha256:6278d9ddbcfb1f1089a88fde84481528b07b0e10474e09dcfe53dad4069fa059"}, ] [package.extras] docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] -testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ignore-flaky", "pytest-mypy", "pytest-ruff (>=0.2.1)"] +testing = ["big-O", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ignore-flaky", "pytest-mypy", "pytest-ruff (>=0.2.1)"] [[package]] name = "zope-interface" -version = "6.3" +version = "6.4" description = "Interfaces for Python" optional = false python-versions = ">=3.7" files = [ - {file = "zope.interface-6.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2f32010ffb87759c6a3ad1c65ed4d2e38e51f6b430a1ca11cee901ec2b42e021"}, - {file = "zope.interface-6.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e78a183a3c2f555c2ad6aaa1ab572d1c435ba42f1dc3a7e8c82982306a19b785"}, - {file = "zope.interface-6.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:afa0491a9f154cf8519a02026dc85a416192f4cb1efbbf32db4a173ba28b289a"}, - {file = "zope.interface-6.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:62e32f02b3f26204d9c02c3539c802afc3eefb19d601a0987836ed126efb1f21"}, - {file = "zope.interface-6.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c40df4aea777be321b7e68facb901bc67317e94b65d9ab20fb96e0eb3c0b60a1"}, - {file = "zope.interface-6.3-cp310-cp310-win_amd64.whl", hash = "sha256:46034be614d1f75f06e7dcfefba21d609b16b38c21fc912b01a99cb29e58febb"}, - {file = "zope.interface-6.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:600101f43a7582d5b9504a7c629a1185a849ce65e60fca0f6968dfc4b76b6d39"}, - {file = "zope.interface-6.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4d6b229f5e1a6375f206455cc0a63a8e502ed190fe7eb15e94a312dc69d40299"}, - {file = "zope.interface-6.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:10cde8dc6b2fd6a1d0b5ca4be820063e46ddba417ab82bcf55afe2227337b130"}, - {file = "zope.interface-6.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:40aa8c8e964d47d713b226c5baf5f13cdf3a3169c7a2653163b17ff2e2334d10"}, - {file = "zope.interface-6.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d165d7774d558ea971cb867739fb334faf68fc4756a784e689e11efa3becd59e"}, - {file = "zope.interface-6.3-cp311-cp311-win_amd64.whl", hash = "sha256:69dedb790530c7ca5345899a1b4cb837cc53ba669051ea51e8c18f82f9389061"}, - {file = "zope.interface-6.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:8d407e0fd8015f6d5dfad481309638e1968d70e6644e0753f229154667dd6cd5"}, - {file = "zope.interface-6.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:72d5efecad16c619a97744a4f0b67ce1bcc88115aa82fcf1dc5be9bb403bcc0b"}, - {file = "zope.interface-6.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:567d54c06306f9c5b6826190628d66753b9f2b0422f4c02d7c6d2b97ebf0a24e"}, - {file = "zope.interface-6.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:483e118b1e075f1819b3c6ace082b9d7d3a6a5eb14b2b375f1b80a0868117920"}, - {file = "zope.interface-6.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2bb78c12c1ad3a20c0d981a043d133299117b6854f2e14893b156979ed4e1d2c"}, - {file = "zope.interface-6.3-cp312-cp312-win_amd64.whl", hash = "sha256:ad4524289d8dbd6fb5aa17aedb18f5643e7d48358f42c007a5ee51a2afc2a7c5"}, - {file = "zope.interface-6.3-cp37-cp37m-macosx_11_0_x86_64.whl", hash = "sha256:a56fe1261230093bfeedc1c1a6cd6f3ec568f9b07f031c9a09f46b201f793a85"}, - {file = "zope.interface-6.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:014bb94fe6bf1786da1aa044eadf65bc6437bcb81c451592987e5be91e70a91e"}, - {file = "zope.interface-6.3-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:22e8a218e8e2d87d4d9342aa973b7915297a08efbebea5b25900c73e78ed468e"}, - {file = "zope.interface-6.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f95bebd0afe86b2adc074df29edb6848fc4d474ff24075e2c263d698774e108d"}, - {file = "zope.interface-6.3-cp37-cp37m-win_amd64.whl", hash = "sha256:d0e7321557c702bd92dac3c66a2f22b963155fdb4600133b6b29597f62b71b12"}, - {file = "zope.interface-6.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:187f7900b63845dcdef1be320a523dbbdba94d89cae570edc2781eb55f8c2f86"}, - {file = "zope.interface-6.3-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:a058e6cf8d68a5a19cb5449f42a404f0d6c2778b897e6ce8fadda9cea308b1b0"}, - {file = "zope.interface-6.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e8fa0fb05083a1a4216b4b881fdefa71c5d9a106e9b094cd4399af6b52873e91"}, - {file = "zope.interface-6.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:26c9a37fb395a703e39b11b00b9e921c48f82b6e32cc5851ad5d0618cd8876b5"}, - {file = "zope.interface-6.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1b0c4c90e5eefca2c3e045d9f9ed9f1e2cdbe70eb906bff6b247e17119ad89a1"}, - {file = "zope.interface-6.3-cp38-cp38-win_amd64.whl", hash = "sha256:5683aa8f2639016fd2b421df44301f10820e28a9b96382a6e438e5c6427253af"}, - {file = "zope.interface-6.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:2c3cfb272bcb83650e6695d49ae0d14dd06dc694789a3d929f23758557a23d92"}, - {file = "zope.interface-6.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:01a0b3dd012f584afcf03ed814bce0fc40ed10e47396578621509ac031be98bf"}, - {file = "zope.interface-6.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4137025731e824eee8d263b20682b28a0bdc0508de9c11d6c6be54163e5b7c83"}, - {file = "zope.interface-6.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3c8731596198198746f7ce2a4487a0edcbc9ea5e5918f0ab23c4859bce56055c"}, - {file = "zope.interface-6.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bf34840e102d1d0b2d39b1465918d90b312b1119552cebb61a242c42079817b9"}, - {file = "zope.interface-6.3-cp39-cp39-win_amd64.whl", hash = "sha256:a1adc14a2a9d5e95f76df625a9b39f4709267a483962a572e3f3001ef90ea6e6"}, - {file = "zope.interface-6.3.tar.gz", hash = "sha256:f83d6b4b22262d9a826c3bd4b2fbfafe1d0000f085ef8e44cd1328eea274ae6a"}, + {file = "zope.interface-6.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:72faa868fcfde49a29d287dce3c83180322467eecd725dd351098efe96e8d4bb"}, + {file = "zope.interface-6.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:855b7233fa5d0d1f3be8c14fadf4718dee1c928e1d75f1584bea6ecec6dcc4af"}, + {file = "zope.interface-6.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:36ee6e507a9fd4f1f0aab8e8dfc801d162e7211c27503cbfb47e1d558941a7fa"}, + {file = "zope.interface-6.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:604fa920478dfc0c76cdb7c203572400a8317ffcdac288245c408b42b3d9aee9"}, + {file = "zope.interface-6.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c04bd4ee4766d285e83c6d8c042663a98efb934389e05ccd643fefb066c88a9d"}, + {file = "zope.interface-6.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4782e173c2fde4f649c2a9a68082445bc1f2c27f41907de06bf1ba82585847f2"}, + {file = "zope.interface-6.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:646cd83d24065d074f22f61fe101d20dbf4b729ca7831cc782ec986eb9156f93"}, + {file = "zope.interface-6.4-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b0f61ccbc26e08031d0e72b6a0cbf9b4030f035913cb2b39f940aa42eb8e0063"}, + {file = "zope.interface-6.4-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:414e6dccdf4a5c96c0c98da68ba040dbf9ba7511b61b34e228f11b0ed90c439d"}, + {file = "zope.interface-6.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f5092f2712e1fd07579fc3101b18e9c95857c853e836847598bf992c8e672434"}, + {file = "zope.interface-6.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:21732994aa3ca43bbb6b36335c288023428a3c5b7322b637c7b0a03053937578"}, + {file = "zope.interface-6.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fe636b49c333bfc5b0913590e36a2f151167c462fb36d9f4acc66029e45c974b"}, + {file = "zope.interface-6.4-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:57f34b7997f8de7d2db08363eaccd05dad20f106e39efe95bed4fac84af2d022"}, + {file = "zope.interface-6.4-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6494dc0314e782ce4fb0e624b4ce2458f54d074382f50a920c7700c05cbcef28"}, + {file = "zope.interface-6.4-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7cda82ab32f984985f09e4ec20a4f9665b26779a1b8e443b34a148de256f2052"}, + {file = "zope.interface-6.4-cp313-cp313t-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f78e1eac48c4f4e0168a91cabcd8d1aedb972836df5c8769071fc6173294a0a3"}, + {file = "zope.interface-6.4-cp37-cp37m-macosx_11_0_x86_64.whl", hash = "sha256:8e246357f52952ae5fa950d19eda8572594c49e6cb1e5462508e6cec561a37de"}, + {file = "zope.interface-6.4-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:93f28d84517dcd6c240979bd9b2f262a373832baef856fe663a24b9171d7f04d"}, + {file = "zope.interface-6.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4cd56eb9a23767958c9a0654306b9a4a74def485f645b3a7378cc6ab661ef31c"}, + {file = "zope.interface-6.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:502d2c9c4231d022b20225dba5c6c736236ed65e1d7e2f6f402b5aa6a7040ec9"}, + {file = "zope.interface-6.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:ee1e3ca6c98efe213a96dece89100a8aa52e210ac354861d8039d69bd1d6e5ff"}, + {file = "zope.interface-6.4-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:62e6b756663deade5270f67899753437b39d970f9eecd49e19fae3b880310cf0"}, + {file = "zope.interface-6.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f33af86ed460eb28dc9da1de1f3305795271a19c665161c1d973a737596b2081"}, + {file = "zope.interface-6.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:86e85eada0eb551950df05d72dc0e892320f14daa78bc434059e834d4b1f9300"}, + {file = "zope.interface-6.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3945f4fda92c1b6fb0cb6eaaaf72599e5c2c2059654bdc42bc09c6e711c214c8"}, + {file = "zope.interface-6.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5fbbb290751f5c4ed81e54ae73fe8557c4a85973f5ab019edbb0f746244ecea6"}, + {file = "zope.interface-6.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6e4cc017206c1429a6d8fdd8a25c6efc15512065eec0a8d45c350df96a0911ed"}, + {file = "zope_interface-6.4.tar.gz", hash = "sha256:b11f2b67ccc990a1522fa8cd3f5d185a068459f944ab2d0e7a1b15d31bcb4af4"}, ] [package.dependencies] diff --git a/cli/pyproject.toml b/cli/pyproject.toml index 36f21bb2c41..80c345c0fd7 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -19,7 +19,7 @@ python = "^3.8.1,<3.12" # OpenBB dependencies openbb = { version = "^4.2.0", extras = ["all"] } -# Terminal dependencies +# CLI dependencies prompt-toolkit = "^3.0.16" rich = "^13" python-dotenv = "^1.0.0" diff --git a/cli/tests/test_cli.py b/cli/tests/test_cli.py index 1fe19344f0f..39936df00e2 100644 --- a/cli/tests/test_cli.py +++ b/cli/tests/test_cli.py @@ -5,8 +5,8 @@ from unittest.mock import patch from openbb_cli.cli import main -@patch("openbb_cli.cli.bootstrap") -@patch("openbb_cli.cli.launch") +@patch("openbb_cli.config.setup.bootstrap") +@patch("openbb_cli.controllers.cli_controller.launch") @patch("sys.argv", ["openbb", "--dev", "--debug"]) def test_main_with_dev_and_debug(mock_launch, mock_bootstrap): """Test the main function with dev and debug flags.""" @@ -15,8 +15,8 @@ def test_main_with_dev_and_debug(mock_launch, mock_bootstrap): mock_launch.assert_called_once_with(True, True) -@patch("openbb_cli.cli.bootstrap") -@patch("openbb_cli.cli.launch") +@patch("openbb_cli.config.setup.bootstrap") +@patch("openbb_cli.controllers.cli_controller.launch") @patch("sys.argv", ["openbb"]) def test_main_without_arguments(mock_launch, mock_bootstrap): """Test the main function without arguments.""" @@ -25,8 +25,8 @@ def test_main_without_arguments(mock_launch, mock_bootstrap): mock_launch.assert_called_once_with(False, False) -@patch("openbb_cli.cli.bootstrap") -@patch("openbb_cli.cli.launch") +@patch("openbb_cli.config.setup.bootstrap") +@patch("openbb_cli.controllers.cli_controller.launch") @patch("sys.argv", ["openbb", "--dev"]) def test_main_with_dev_only(mock_launch, mock_bootstrap): """Test the main function with dev flag only.""" @@ -35,8 +35,8 @@ def test_main_with_dev_only(mock_launch, mock_bootstrap): mock_launch.assert_called_once_with(True, False) -@patch("openbb_cli.cli.bootstrap") -@patch("openbb_cli.cli.launch") +@patch("openbb_cli.config.setup.bootstrap") +@patch("openbb_cli.controllers.cli_controller.launch") @patch("sys.argv", ["openbb", "--debug"]) def test_main_with_debug_only(mock_launch, mock_bootstrap): """Test the main function with debug flag only.""" diff --git a/openbb_platform/dev_install.py b/openbb_platform/dev_install.py index 0b8695366fd..1a18d7925e4 100644 --- a/openbb_platform/dev_install.py +++ b/openbb_platform/dev_install.py @@ -4,12 +4,14 @@ import subprocess import sys from pathlib import Path -import toml +from tomlkit import dumps, load, loads PLATFORM_PATH = Path(__file__).parent.resolve() LOCK = PLATFORM_PATH / "poetry.lock" PYPROJECT = PLATFORM_PATH / "pyproject.toml" - +CLI_PATH = Path(__file__).parent.parent.resolve() / "cli" +CLI_PYPROJECT = CLI_PATH / "pyproject.toml" +CLI_LOCK = CLI_PATH / "poetry.lock" LOCAL_DEPS = """ [tool.poetry.dependencies] @@ -68,7 +70,8 @@ def extract_dev_dependencies(local_dep_path): """Extract development dependencies from a given package's pyproject.toml.""" package_pyproject_path = PLATFORM_PATH / local_dep_path if package_pyproject_path.exists(): - package_pyproject_toml = toml.load(package_pyproject_path / "pyproject.toml") + with open(package_pyproject_path / "pyproject.toml") as f: + package_pyproject_toml = load(f) return ( package_pyproject_toml.get("tool", {}) .get("poetry", {}) @@ -82,7 +85,7 @@ def extract_dev_dependencies(local_dep_path): def get_all_dev_dependencies(): """Aggregate development dependencies from all local packages.""" all_dev_dependencies = {} - local_deps = toml.loads(LOCAL_DEPS)["tool"]["poetry"]["dependencies"] + local_deps = loads(LOCAL_DEPS).get("tool", {}).get("poetry", {})["dependencies"] for _, package_info in local_deps.items(): if "path" in package_info: dev_deps = extract_dev_dependencies(Path(package_info["path"])) @@ -90,25 +93,28 @@ def get_all_dev_dependencies(): return all_dev_dependencies -def install_local(_extras: bool = False): +def install_platform_local(_extras: bool = False): """Install the Platform locally for development purposes.""" original_lock = LOCK.read_text() original_pyproject = PYPROJECT.read_text() - pyproject_toml = toml.load(PYPROJECT) - local_deps = toml.loads(LOCAL_DEPS)["tool"]["poetry"]["dependencies"] - pyproject_toml["tool"]["poetry"]["dependencies"].update(local_deps) + local_deps = loads(LOCAL_DEPS).get("tool", {}).get("poetry", {})["dependencies"] + with open(PYPROJECT) as f: + pyproject_toml = load(f) + pyproject_toml.get("tool", {}).get("poetry", {}).get("dependencies", {}).update( + local_deps + ) if _extras: dev_dependencies = get_all_dev_dependencies() - pyproject_toml["tool"]["poetry"].setdefault("group", {}).setdefault( - "dev", {} - ).setdefault("dependencies", {}) - pyproject_toml["tool"]["poetry"]["group"]["dev"]["dependencies"].update( - dev_dependencies - ) + pyproject_toml.get("tool", {}).get("poetry", {}).setdefault( + "group", {} + ).setdefault("dev", {}).setdefault("dependencies", {}) + pyproject_toml.get("tool", {}).get("poetry", {})["group"]["dev"][ + "dependencies" + ].update(dev_dependencies) - TEMP_PYPROJECT = toml.dumps(pyproject_toml) + TEMP_PYPROJECT = dumps(pyproject_toml) try: with open(PYPROJECT, "w", encoding="utf-8", newline="\n") as f: @@ -137,7 +143,49 @@ def install_local(_extras: bool = False): f.write(original_lock) +def install_platform_cli(): + """Install the CLI locally for development purposes.""" + original_lock = CLI_LOCK.read_text() + original_pyproject = CLI_PYPROJECT.read_text() + + with open(CLI_PYPROJECT) as f: + pyproject_toml = load(f) + + # remove "openbb" from dependencies + pyproject_toml.get("tool", {}).get("poetry", {}).get("dependencies", {}).pop( + "openbb", None + ) + + TEMP_PYPROJECT = dumps(pyproject_toml) + + try: + with open(CLI_PYPROJECT, "w", encoding="utf-8", newline="\n") as f: + f.write(TEMP_PYPROJECT) + + CMD = [sys.executable, "-m", "poetry"] + + subprocess.run( + CMD + ["lock", "--no-update"], cwd=CLI_PATH, check=True # noqa: S603 + ) + subprocess.run(CMD + ["install"], cwd=CLI_PATH, check=True) # noqa: S603 + + except (Exception, KeyboardInterrupt) as e: + print(e) # noqa: T201 + print("Restoring pyproject.toml and poetry.lock") # noqa: T201 + + finally: + # Revert pyproject.toml and poetry.lock to their original state. + with open(CLI_PYPROJECT, "w", encoding="utf-8", newline="\n") as f: + f.write(original_pyproject) + + with open(CLI_LOCK, "w", encoding="utf-8", newline="\n") as f: + f.write(original_lock) + + if __name__ == "__main__": args = sys.argv[1:] extras = any(arg.lower() in ["-e", "--extras"] for arg in args) - install_local(extras) + cli = any(arg.lower() in ["-c", "--cli"] for arg in args) + install_platform_local(extras) + if cli: + install_platform_cli() -- cgit v1.2.3