infra: allow non-langchainai packages (#28199)

This commit is contained in:
Erick Friis 2024-11-18 17:43:08 -08:00 committed by GitHub
parent d9d689572a
commit 24eea2e398
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 18 deletions

View File

@ -11,7 +11,9 @@ from typing import Dict, Any
def load_packages_yaml() -> Dict[str, Any]: def load_packages_yaml() -> Dict[str, Any]:
"""Load and parse the packages.yml file.""" """Load and parse the packages.yml file."""
with open("langchain/libs/packages.yml", "r") as f: with open("langchain/libs/packages.yml", "r") as f:
return yaml.safe_load(f) all_packages = yaml.safe_load(f)
return {k: v for k, v in all_packages.items() if k["repo"]}
def get_target_dir(package_name: str) -> Path: def get_target_dir(package_name: str) -> Path:
@ -23,24 +25,19 @@ def get_target_dir(package_name: str) -> Path:
return base_path / "partners" / package_name_short return base_path / "partners" / package_name_short
def clean_target_directories(packages: Dict[str, Any]) -> None: def clean_target_directories(packages: list) -> None:
"""Remove old directories that will be replaced.""" """Remove old directories that will be replaced."""
for package in packages["packages"]: for package in packages:
if package["repo"] != "langchain-ai/langchain":
target_dir = get_target_dir(package["name"]) target_dir = get_target_dir(package["name"])
if target_dir.exists(): if target_dir.exists():
print(f"Removing {target_dir}") print(f"Removing {target_dir}")
shutil.rmtree(target_dir) shutil.rmtree(target_dir)
def move_libraries(packages: Dict[str, Any]) -> None: def move_libraries(packages: list) -> None:
"""Move libraries from their source locations to the target directories.""" """Move libraries from their source locations to the target directories."""
for package in packages["packages"]: for package in packages:
# Skip if it's the main langchain repo or disabled
if package["repo"] == "langchain-ai/langchain" or package.get(
"disabled", False
):
continue
repo_name = package["repo"].split("/")[1] repo_name = package["repo"].split("/")[1]
source_path = package["path"] source_path = package["path"]
@ -68,7 +65,14 @@ def main():
"""Main function to orchestrate the library sync process.""" """Main function to orchestrate the library sync process."""
try: try:
# Load packages configuration # Load packages configuration
packages = load_packages_yaml() package_yaml = load_packages_yaml()
packages = [
p
for p in package_yaml["packages"]
if not p.get("disabled", False)
and p["repo"].startswith("langchain-ai/")
and p["repo"] != "langchain-ai/langchain"
]
# Clean target directories # Clean target directories
clean_target_directories(packages) clean_target_directories(packages)

View File

@ -37,9 +37,9 @@ jobs:
# Get unique repositories # Get unique repositories
REPOS=$(echo "$REPOS_UNSORTED" | sort -u) REPOS=$(echo "$REPOS_UNSORTED" | sort -u)
# Checkout each unique repository # Checkout each unique repository that is in langchain-ai org
for repo in $REPOS; do for repo in $REPOS; do
if [ "$repo" != "langchain-ai/langchain" ]; then if [[ "$repo" != "langchain-ai/langchain" && "$repo" == langchain-ai/* ]]; then
REPO_NAME=$(echo $repo | cut -d'/' -f2) REPO_NAME=$(echo $repo | cut -d'/' -f2)
echo "Checking out $repo to $REPO_NAME" echo "Checking out $repo to $REPO_NAME"
git clone --depth 1 https://github.com/$repo.git $REPO_NAME git clone --depth 1 https://github.com/$repo.git $REPO_NAME