From 24eea2e3981ba1addf5ffd01d1a9ad450cc8fadc Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Mon, 18 Nov 2024 17:43:08 -0800 Subject: [PATCH] infra: allow non-langchainai packages (#28199) --- .github/scripts/prep_api_docs_build.py | 36 ++++++++++++++------------ .github/workflows/api_doc_build.yml | 4 +-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.github/scripts/prep_api_docs_build.py b/.github/scripts/prep_api_docs_build.py index 2c2655e2155a4..0ddd7ac053de5 100644 --- a/.github/scripts/prep_api_docs_build.py +++ b/.github/scripts/prep_api_docs_build.py @@ -11,7 +11,9 @@ def load_packages_yaml() -> Dict[str, Any]: """Load and parse the packages.yml file.""" 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: @@ -23,24 +25,19 @@ def get_target_dir(package_name: str) -> Path: 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.""" - for package in packages["packages"]: - if package["repo"] != "langchain-ai/langchain": - target_dir = get_target_dir(package["name"]) - if target_dir.exists(): - print(f"Removing {target_dir}") - shutil.rmtree(target_dir) + for package in packages: + + target_dir = get_target_dir(package["name"]) + if target_dir.exists(): + print(f"Removing {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.""" - for package in packages["packages"]: - # Skip if it's the main langchain repo or disabled - if package["repo"] == "langchain-ai/langchain" or package.get( - "disabled", False - ): - continue + for package in packages: repo_name = package["repo"].split("/")[1] source_path = package["path"] @@ -68,7 +65,14 @@ def main(): """Main function to orchestrate the library sync process.""" try: # 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(packages) diff --git a/.github/workflows/api_doc_build.yml b/.github/workflows/api_doc_build.yml index 26e2b19cb4602..959f35a94bd37 100644 --- a/.github/workflows/api_doc_build.yml +++ b/.github/workflows/api_doc_build.yml @@ -37,9 +37,9 @@ jobs: # Get unique repositories 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 - if [ "$repo" != "langchain-ai/langchain" ]; then + if [[ "$repo" != "langchain-ai/langchain" && "$repo" == langchain-ai/* ]]; then REPO_NAME=$(echo $repo | cut -d'/' -f2) echo "Checking out $repo to $REPO_NAME" git clone --depth 1 https://github.com/$repo.git $REPO_NAME