mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-28 20:23:36 +00:00
fixes for docstring generation
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -23,6 +24,7 @@ PACKAGE_GLOBS = (
|
||||
ROUTERS_PATH = Path("openbb_platform/extensions")
|
||||
ALWAYS_INSTALLED_ROUTERS = frozenset({"openbb-news"})
|
||||
UV_BUILD_LOG = "uv_build_frontend=debug"
|
||||
REQUIREMENT_NAME_RE = re.compile(r"^\s*([A-Za-z0-9][A-Za-z0-9._-]*)")
|
||||
|
||||
|
||||
def log(message: str) -> None:
|
||||
@@ -146,8 +148,24 @@ def is_optional_router(package: Path, pyproject: dict) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def get_install_args(package: Path, pyproject: dict) -> list[str]:
|
||||
"""Return the uv arguments that install a package with its extras and dev group.
|
||||
def normalize_name(name: str) -> str:
|
||||
"""Return the PEP 503 normalized form of a distribution name.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
The distribution name.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
The lowercase name with runs of ``-``, ``_``, and ``.`` collapsed to ``-``.
|
||||
"""
|
||||
return re.sub(r"[-_.]+", "-", name).lower()
|
||||
|
||||
|
||||
def get_editable_target(package: Path, pyproject: dict) -> str:
|
||||
"""Return the editable install target for a package, with all of its extras.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -158,15 +176,62 @@ def get_install_args(package: Path, pyproject: dict) -> list[str]:
|
||||
|
||||
Returns
|
||||
-------
|
||||
list[str]
|
||||
The editable requirement, followed by the dev group when the package has one.
|
||||
str
|
||||
The package path, followed by ``[extra,...]`` when it declares extras.
|
||||
"""
|
||||
extras = sorted(pyproject.get("project", {}).get("optional-dependencies", {}))
|
||||
target = package.as_posix() + (f"[{','.join(extras)}]" if extras else "")
|
||||
args = ["--editable", target]
|
||||
if "dev" in pyproject.get("dependency-groups", {}):
|
||||
args += ["--group", f"{package.as_posix()}/pyproject.toml:dev"]
|
||||
return args
|
||||
return package.as_posix() + (f"[{','.join(extras)}]" if extras else "")
|
||||
|
||||
|
||||
def resolve_dev_requirements(
|
||||
pyprojects: dict[Path, dict], selected: list[Path]
|
||||
) -> tuple[list[Path], list[str], list[str]]:
|
||||
"""Resolve the ``dev`` dependency groups of the selected packages.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
pyprojects : dict[Path, dict]
|
||||
The parsed pyproject.toml of every tracked package, by directory.
|
||||
selected : list[Path]
|
||||
The packages being installed.
|
||||
|
||||
Returns
|
||||
-------
|
||||
tuple[list[Path], list[str], list[str]]
|
||||
Tracked packages that are only dev dependencies and install editable,
|
||||
requirements to install from the index, and local path-sourced
|
||||
requirements outside the tracked packages, such as test fixtures,
|
||||
that are left out.
|
||||
"""
|
||||
tracked = {
|
||||
normalize_name(pyproject["project"]["name"]): package
|
||||
for package, pyproject in pyprojects.items()
|
||||
}
|
||||
editables: list[Path] = []
|
||||
requirements: list[str] = []
|
||||
skipped: list[str] = []
|
||||
for package in selected:
|
||||
pyproject = pyprojects[package]
|
||||
sources = {
|
||||
normalize_name(name): source
|
||||
for name, source in pyproject.get("tool", {})
|
||||
.get("uv", {})
|
||||
.get("sources", {})
|
||||
.items()
|
||||
}
|
||||
for requirement in pyproject.get("dependency-groups", {}).get("dev", []):
|
||||
match = REQUIREMENT_NAME_RE.match(requirement)
|
||||
name = normalize_name(match.group(1)) if match else ""
|
||||
if name in tracked:
|
||||
target = tracked[name]
|
||||
if target not in selected and target not in editables:
|
||||
editables.append(target)
|
||||
elif isinstance(sources.get(name), dict) and "path" in sources[name]:
|
||||
if requirement not in skipped:
|
||||
skipped.append(requirement)
|
||||
elif requirement not in requirements:
|
||||
requirements.append(requirement)
|
||||
return editables, requirements, skipped
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> None:
|
||||
@@ -185,17 +250,43 @@ def main(argv: list[str] | None = None) -> None:
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
log(f"Installing into {sys.executable}")
|
||||
pyprojects = {
|
||||
package: load_toml(REPO_PATH / package / "pyproject.toml")
|
||||
for package in get_tracked_packages()
|
||||
}
|
||||
selected = [
|
||||
package
|
||||
for package, pyproject in pyprojects.items()
|
||||
if args.routers or not is_optional_router(package, pyproject)
|
||||
]
|
||||
install_args: list[str] = []
|
||||
skipped: list[str] = []
|
||||
for package in get_tracked_packages():
|
||||
pyproject = load_toml(REPO_PATH / package / "pyproject.toml")
|
||||
if args.routers or not is_optional_router(package, pyproject):
|
||||
install_args += get_install_args(package, pyproject)
|
||||
log(f" + {package.as_posix()}")
|
||||
else:
|
||||
skipped.append(package.name)
|
||||
if skipped:
|
||||
log(f"Skipping routers (pass --routers to include): {', '.join(skipped)}")
|
||||
for package in selected:
|
||||
install_args += [
|
||||
"--editable",
|
||||
get_editable_target(package, pyprojects[package]),
|
||||
]
|
||||
log(f" + {package.as_posix()}")
|
||||
skipped_routers = [
|
||||
package.name for package in pyprojects if package not in selected
|
||||
]
|
||||
editables, requirements, skipped_local = resolve_dev_requirements(
|
||||
pyprojects, selected
|
||||
)
|
||||
for package in editables:
|
||||
install_args += [
|
||||
"--editable",
|
||||
get_editable_target(package, pyprojects[package]),
|
||||
]
|
||||
log(f" + {package.as_posix()} (dev dependency)")
|
||||
install_args += requirements
|
||||
log(f"Dev requirements: {', '.join(requirements)}")
|
||||
if skipped_routers:
|
||||
log(
|
||||
"Skipping routers (pass --routers to include): "
|
||||
f"{', '.join(skipped_routers)}"
|
||||
)
|
||||
if skipped_local:
|
||||
log(f"Skipping local test packages: {', '.join(skipped_local)}")
|
||||
run_step(
|
||||
"Resolving, building, and installing with uv "
|
||||
"(package builds and their hook output stream below)",
|
||||
|
||||
Reference in New Issue
Block a user