infra: add test deps to add_dependents (#24283)

This commit is contained in:
Erick Friis 2024-07-16 00:48:53 +02:00 committed by GitHub
parent d2f671271e
commit 1d7a3ae7ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@ import sys
import tomllib import tomllib
from collections import defaultdict from collections import defaultdict
from typing import Dict, List, Set from typing import Dict, List, Set
from pathlib import Path
LANGCHAIN_DIRS = [ LANGCHAIN_DIRS = [
@ -26,17 +27,48 @@ def all_package_dirs() -> Set[str]:
def dependents_graph() -> dict: def dependents_graph() -> dict:
"""
Construct a mapping of package -> dependents, such that we can
run tests on all dependents of a package when a change is made.
"""
dependents = defaultdict(set) dependents = defaultdict(set)
for path in glob.glob("./libs/**/pyproject.toml", recursive=True): for path in glob.glob("./libs/**/pyproject.toml", recursive=True):
if "template" in path: if "template" in path:
continue continue
# load regular and test deps from pyproject.toml
with open(path, "rb") as f: with open(path, "rb") as f:
pyproject = tomllib.load(f)["tool"]["poetry"] pyproject = tomllib.load(f)["tool"]["poetry"]
pkg_dir = "libs" + "/".join(path.split("libs")[1].split("/")[:-1]) pkg_dir = "libs" + "/".join(path.split("libs")[1].split("/")[:-1])
for dep in pyproject["dependencies"]: for dep in [
*pyproject["dependencies"].keys(),
*pyproject["group"]["test"]["dependencies"].keys(),
]:
if "langchain" in dep: if "langchain" in dep:
dependents[dep].add(pkg_dir) dependents[dep].add(pkg_dir)
continue
# load extended deps from extended_testing_deps.txt
package_path = Path(path).parent
extended_requirement_path = package_path / "extended_testing_deps.txt"
if extended_requirement_path.exists():
with open(extended_requirement_path, "r") as f:
extended_deps = f.read().splitlines()
for depline in extended_deps:
if depline.startswith("-e "):
# editable dependency
assert depline.startswith(
"-e ../partners/"
), "Extended test deps should only editable install partner packages"
partner = depline.split("partners/")[1]
dep = f"langchain-{partner}"
else:
dep = depline.split("==")[0]
if "langchain" in dep:
dependents[dep].add(pkg_dir)
return dependents return dependents