Skip to content

Commit

Permalink
infra: add test deps to add_dependents (langchain-ai#24283)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Jul 15, 2024
1 parent d2f6712 commit 1d7a3ae
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion .github/scripts/check_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tomllib
from collections import defaultdict
from typing import Dict, List, Set
from pathlib import Path


LANGCHAIN_DIRS = [
Expand All @@ -26,17 +27,48 @@ def all_package_dirs() -> Set[str]:


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)

for path in glob.glob("./libs/**/pyproject.toml", recursive=True):
if "template" in path:
continue

# load regular and test deps from pyproject.toml
with open(path, "rb") as f:
pyproject = tomllib.load(f)["tool"]["poetry"]

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:
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


Expand Down

0 comments on commit 1d7a3ae

Please sign in to comment.