Skip to content

Commit

Permalink
Move pytest dependencies from openbb level to to core dev deps level (O…
Browse files Browse the repository at this point in the history
…penBB-finance#5829)

* Move pytest to core dev deps

* removing openbb-core from devtools

* Fix dev_install script not picking developer dependencies

---------

Co-authored-by: Henrique Joaquim <[email protected]>
  • Loading branch information
piiq and hjoaquim authored Nov 30, 2023
1 parent 5e92623 commit a784bba
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 272 deletions.
65 changes: 64 additions & 1 deletion openbb_platform/core/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion openbb_platform/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ black = "^23.11.0"
ruff = "^0.1.6"

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.0"
pytest-subtests = "^0.11.0"
pytest-recorder = "^0.2.4"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
79 changes: 49 additions & 30 deletions openbb_platform/dev_install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Install for development script."""
# noqa: S603,PLW1510,T201
import subprocess
import sys
from pathlib import Path
Expand Down Expand Up @@ -57,61 +56,81 @@
openbb-technical = { path = "./extensions/technical", 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 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")
return (
package_pyproject_toml.get("tool", {})
.get("poetry", {})
.get("group", {})
.get("dev", {})
.get("dependencies", {})
)
return {}


def install_local(_extras: bool = False):
"""Install the Platform locally for development purposes.
def get_all_dev_dependencies():
"""Aggregate development dependencies from all local packages."""
all_dev_dependencies = {}
local_deps = toml.loads(LOCAL_DEPS)["tool"]["poetry"]["dependencies"]
for _, package_info in local_deps.items():
if "path" in package_info:
dev_deps = extract_dev_dependencies(Path(package_info["path"]))
all_dev_dependencies.update(dev_deps)
return all_dev_dependencies

Installs the Platform 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 Platform with the extra dependencies, by default False
"""
def install_local(_extras: bool = False):
"""Install the Platform locally for development purposes."""
original_lock = LOCK.read_text()
original_pyproject = PYPROJECT.read_text()
extras_args = ["-E", "all"] if _extras else []

pyproject_toml = toml.load(PYPROJECT)
local_deps = toml.loads(LOCAL_DEPS)["tool"]["poetry"]["dependencies"]
pyproject_toml["tool"]["poetry"]["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
)

TEMP_PYPROJECT = toml.dumps(pyproject_toml)

try:
# we create a temporary pyproject.toml
with open(PYPROJECT, "w", encoding="utf-8", newline="\n") as f:
f.write(TEMP_PYPROJECT)

CMD = [sys.executable, "-m", "poetry"]
extras_args = ["-E", "all"] if _extras else []

subprocess.run( # noqa: PLW1510
subprocess.run(
CMD + ["lock", "--no-update"], cwd=PLATFORM_PATH, check=True # noqa: S603
)
subprocess.run( # noqa: PLW1510
subprocess.run(
CMD + ["install"] + extras_args, cwd=PLATFORM_PATH, check=True # 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(original_pyproject)
finally:
# Revert pyproject.toml and poetry.lock to their original state
with open(PYPROJECT, "w", encoding="utf-8", newline="\n") as f:
f.write(original_pyproject)

# we restore the original poetry.lock
with open(LOCK, "w", encoding="utf-8", newline="\n") as f:
f.write(original_lock)
with open(LOCK, "w", encoding="utf-8", newline="\n") as f:
f.write(original_lock)


if __name__ == "__main__":
args = sys.argv[1:]

# pylint: disable=use-a-generator
extras = any([arg.lower() in ["-e", "--extras"] for arg in args])

extras = any(arg.lower() in ["-e", "--extras"] for arg in args)
install_local(extras)
1 change: 0 additions & 1 deletion openbb_platform/extensions/devtools/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ ipykernel = "^6.26.0"
types-python-dateutil = "^2.8.19.14"
types-toml = "^0.10.8.7"
poetry = "^1.7.0"
openbb-core = "^1.0.0rc0"


[build-system]
Expand Down
Loading

0 comments on commit a784bba

Please sign in to comment.