diff --git a/.github/scripts/get_min_versions.py b/.github/scripts/get_min_versions.py new file mode 100644 index 0000000000000..fb68755ac2876 --- /dev/null +++ b/.github/scripts/get_min_versions.py @@ -0,0 +1,65 @@ +import sys + +import tomllib +from packaging.version import parse as parse_version +import re + +MIN_VERSION_LIBS = ["langchain-core", "langchain-community", "langchain"] + + +def get_min_version(version: str) -> str: + # case ^x.x.x + _match = re.match(r"^\^(\d+(?:\.\d+){0,2})$", version) + if _match: + return _match.group(1) + + # case >=x.x.x,=(\d+(?:\.\d+){0,2}),<(\d+(?:\.\d+){0,2})$", version) + if _match: + _min = _match.group(1) + _max = _match.group(2) + assert parse_version(_min) < parse_version(_max) + return _min + + # case x.x.x + _match = re.match(r"^(\d+(?:\.\d+){0,2})$", version) + if _match: + return _match.group(1) + + raise ValueError(f"Unrecognized version format: {version}") + + +def get_min_version_from_toml(toml_path: str): + # Parse the TOML file + with open(toml_path, "rb") as file: + toml_data = tomllib.load(file) + + # Get the dependencies from tool.poetry.dependencies + dependencies = toml_data["tool"]["poetry"]["dependencies"] + + # Initialize a dictionary to store the minimum versions + min_versions = {} + + # Iterate over the libs in MIN_VERSION_LIBS + for lib in MIN_VERSION_LIBS: + # Check if the lib is present in the dependencies + if lib in dependencies: + # Get the version string + version_string = dependencies[lib] + + # Use parse_version to get the minimum supported version from version_string + min_version = get_min_version(version_string) + + # Store the minimum version in the min_versions dictionary + min_versions[lib] = min_version + + return min_versions + + +# Get the TOML file path from the command line argument +toml_file = sys.argv[1] + +# Call the function to get the minimum versions +min_versions = get_min_version_from_toml(toml_file) + +print(" ".join([f"{lib}=={version}" for lib, version in min_versions.items()])) diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml index c140f93ba589a..b32842ebf5f74 100644 --- a/.github/workflows/_release.yml +++ b/.github/workflows/_release.yml @@ -15,7 +15,7 @@ on: default: 'libs/langchain' env: - PYTHON_VERSION: "3.10" + PYTHON_VERSION: "3.11" POETRY_VERSION: "1.7.1" jobs: @@ -181,10 +181,15 @@ jobs: run: make integration_tests working-directory: ${{ inputs.working-directory }} + - name: Get minimum versions + id: check-version + run: echo "min-versions=$(python $GITHUB_WORKSPACE/.github/scripts/get_min_versions.py pyproject.toml)"" >> $GITHUB_OUTPUT + - name: Run unit tests with minimum dependency versions - if: ${{ (inputs.working-directory == 'libs/langchain') || (inputs.working-directory == 'libs/community') || (inputs.working-directory == 'libs/experimental') }} + env: + MIN_VERSIONS: ${{ steps.check-version.outputs.min-versions }} run: | - poetry run pip install -r _test_minimum_requirements.txt + poetry run pip install $MIN_VERSIONS make tests working-directory: ${{ inputs.working-directory }} diff --git a/libs/community/_test_minimum_requirements.txt b/libs/community/_test_minimum_requirements.txt deleted file mode 100644 index 3c490af63d806..0000000000000 --- a/libs/community/_test_minimum_requirements.txt +++ /dev/null @@ -1 +0,0 @@ -langchain-core==0.1.19 diff --git a/libs/experimental/_test_minimum_requirements.txt b/libs/experimental/_test_minimum_requirements.txt deleted file mode 100644 index 078f131ef8dcd..0000000000000 --- a/libs/experimental/_test_minimum_requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -langchain-core==0.1.16 -langchain==0.1.5 diff --git a/libs/langchain/_test_minimum_requirements.txt b/libs/langchain/_test_minimum_requirements.txt deleted file mode 100644 index 84c789c84d7ee..0000000000000 --- a/libs/langchain/_test_minimum_requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -langchain-core==0.1.16 -langchain-community==0.0.17