Files
OpenBB/openbb_platform/poetry_update.py
2023-10-17 11:43:08 +02:00

30 lines
928 B
Python

import os
import sys
from pathlib import Path
from typing import List, Optional
def update_lock_file(packages: Optional[List[str]] = None) -> None:
"""Update the poetry lock files in all the packages or in the given packages."""
for path in Path.cwd().rglob("pyproject.toml"):
if packages and path.parent.name not in packages:
print(f"Skipping {path.parent.name}") # noqa: T201
continue
print(f"\nUpdating lock file in {path.parent.name}") # noqa: T201
os.chdir(path.parent)
os.system("poetry lock --no-update") # noqa: S605, S607
# Fix line endings and encoding
lock_file = path.parent / "poetry.lock"
lock_file.write_text(
lock_file.read_text(),
encoding="utf-8",
newline="\n",
)
if __name__ == "__main__":
args = sys.argv[1:]
update_lock_file(packages=args if args else None)