Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core[patch]: pydantic ^2.5 #26396

Merged
merged 46 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7573c81
core[patch]: pydantic ^2.5
baskaryan Sep 12, 2024
2828517
test pydantic
baskaryan Sep 12, 2024
ccc24a6
undo
baskaryan Sep 12, 2024
ff6ebc7
nit
baskaryan Sep 12, 2024
7e5bc32
fix
baskaryan Sep 12, 2024
81e7920
install requests
baskaryan Sep 12, 2024
4d6a046
fix
baskaryan Sep 12, 2024
fd80171
fix
baskaryan Sep 12, 2024
105986e
fix
baskaryan Sep 12, 2024
29436fe
fix
baskaryan Sep 12, 2024
0e30424
fix
baskaryan Sep 12, 2024
5834433
fix
baskaryan Sep 12, 2024
f17b059
max patch
baskaryan Sep 12, 2024
6cfa0f1
fix
baskaryan Sep 12, 2024
be70b4a
nit
baskaryan Sep 12, 2024
eb8d9e2
Merge branch 'v0.3rc' into bagatur/pydantic_2_5
baskaryan Sep 12, 2024
7eb3878
rm enum
baskaryan Sep 12, 2024
1e02d07
fix
baskaryan Sep 12, 2024
d388cdd
fmt
baskaryan Sep 12, 2024
13fd954
fmt
baskaryan Sep 12, 2024
6771d5b
normalize
baskaryan Sep 12, 2024
19d87e4
more
baskaryan Sep 12, 2024
93f274f
snapshots
baskaryan Sep 12, 2024
2012ea4
fmt
baskaryan Sep 12, 2024
1b2056c
redo
baskaryan Sep 13, 2024
e328f9d
update
baskaryan Sep 13, 2024
ba2b9cd
fmt
baskaryan Sep 13, 2024
83f869c
rm warning error
baskaryan Sep 13, 2024
9b9aba4
fix
baskaryan Sep 13, 2024
3bd5637
fmt
baskaryan Sep 13, 2024
71cc697
fix
baskaryan Sep 13, 2024
a34cad1
fix
baskaryan Sep 13, 2024
0e6dae9
fix
baskaryan Sep 13, 2024
2da709c
fix
baskaryan Sep 13, 2024
9c3e403
fix
baskaryan Sep 13, 2024
ae6f6d9
fix
baskaryan Sep 13, 2024
7116827
use action output
baskaryan Sep 13, 2024
2f880c0
Merge branch 'v0.3rc' into bagatur/pydantic_2_5
baskaryan Sep 13, 2024
70d034a
fix
baskaryan Sep 13, 2024
47cea6e
clear output
baskaryan Sep 13, 2024
eeb2564
fix
baskaryan Sep 13, 2024
2fe4551
nit
baskaryan Sep 13, 2024
3cfe268
nit
baskaryan Sep 13, 2024
0663d9d
fix
baskaryan Sep 13, 2024
399cfc9
unskip
baskaryan Sep 13, 2024
f3067a1
undo
baskaryan Sep 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 74 additions & 18 deletions .github/scripts/check_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import json
import os
import sys
import tomllib
from collections import defaultdict
from typing import Dict, List, Set
from pathlib import Path
import tomllib

from get_min_versions import get_min_version_from_toml


LANGCHAIN_DIRS = [
Expand Down Expand Up @@ -103,33 +105,84 @@ def add_dependents(dirs_to_eval: Set[str], dependents: dict) -> List[str]:


def _get_configs_for_single_dir(job: str, dir_: str) -> List[Dict[str, str]]:
if dir_ == "libs/core":
return [
{"working-directory": dir_, "python-version": f"3.{v}"}
for v in range(9, 13)
]
min_python = "3.9"
max_python = "3.12"
if job == "test-pydantic":
return _get_pydantic_test_configs(dir_)

if dir_ == "libs/core":
py_versions = ["3.9", "3.10", "3.11", "3.12"]
# custom logic for specific directories
if dir_ == "libs/partners/milvus":
elif dir_ == "libs/partners/milvus":
# milvus poetry doesn't allow 3.12 because they
# declare deps in funny way
max_python = "3.11"
py_versions = ["3.9", "3.11"]

if dir_ in ["libs/community", "libs/langchain"] and job == "extended-tests":
elif dir_ in ["libs/community", "libs/langchain"] and job == "extended-tests":
# community extended test resolution in 3.12 is slow
# even in uv
max_python = "3.11"
py_versions = ["3.9", "3.11"]

if dir_ == "libs/community" and job == "compile-integration-tests":
elif dir_ == "libs/community" and job == "compile-integration-tests":
# community integration deps are slow in 3.12
max_python = "3.11"
py_versions = ["3.9", "3.11"]
else:
py_versions = ["3.9", "3.12"]

return [
{"working-directory": dir_, "python-version": min_python},
{"working-directory": dir_, "python-version": max_python},
return [{"working-directory": dir_, "python-version": py_v} for py_v in py_versions]


def _get_pydantic_test_configs(
dir_: str, *, python_version: str = "3.11"
) -> List[Dict[str, str]]:
with open("./libs/core/poetry.lock", "rb") as f:
core_poetry_lock_data = tomllib.load(f)
for package in core_poetry_lock_data["package"]:
if package["name"] == "pydantic":
core_max_pydantic_minor = package["version"].split(".")[1]
break

with open(f"./{dir_}/poetry.lock", "rb") as f:
dir_poetry_lock_data = tomllib.load(f)

for package in dir_poetry_lock_data["package"]:
if package["name"] == "pydantic":
dir_max_pydantic_minor = package["version"].split(".")[1]
break

core_min_pydantic_minor = get_min_version_from_toml(
"./libs/core/pyproject.toml", "release", python_version, include=["pydantic"]
)["pydantic"].split(".")[1]
dir_min_pydantic_minor = (
get_min_version_from_toml(
f"./{dir_}/pyproject.toml", "release", python_version, include=["pydantic"]
)
.get("pydantic", "0.0.0")
.split(".")[1]
)

custom_mins = {
# depends on pydantic-settings 2.4 which requires pydantic 2.7
"libs/community": 7,
}

max_pydantic_minor = min(
int(dir_max_pydantic_minor),
int(core_max_pydantic_minor),
)
min_pydantic_minor = max(
int(dir_min_pydantic_minor),
int(core_min_pydantic_minor),
custom_mins.get(dir_, 0),
)

configs = [
{
"working-directory": dir_,
"pydantic-version": f"2.{v}.0",
"python-version": python_version,
}
for v in range(min_pydantic_minor, max_pydantic_minor + 1)
]
return configs


def _get_configs_for_multi_dirs(
Expand All @@ -140,7 +193,7 @@ def _get_configs_for_multi_dirs(
dirs_to_run["lint"] | dirs_to_run["test"] | dirs_to_run["extended-test"],
dependents,
)
elif job in ["test", "compile-integration-tests", "dependencies"]:
elif job in ["test", "compile-integration-tests", "dependencies", "test-pydantic"]:
dirs = add_dependents(
dirs_to_run["test"] | dirs_to_run["extended-test"], dependents
)
Expand Down Expand Up @@ -169,6 +222,7 @@ def _get_configs_for_multi_dirs(
dirs_to_run["lint"] = all_package_dirs()
dirs_to_run["test"] = all_package_dirs()
dirs_to_run["extended-test"] = set(LANGCHAIN_DIRS)

for file in files:
if any(
file.startswith(dir_)
Expand All @@ -186,6 +240,7 @@ def _get_configs_for_multi_dirs(
if any(file.startswith(dir_) for dir_ in LANGCHAIN_DIRS):
# add that dir and all dirs after in LANGCHAIN_DIRS
# for extended testing

found = False
for dir_ in LANGCHAIN_DIRS:
if dir_ == "libs/core" and IGNORE_CORE_DEPENDENTS:
Expand Down Expand Up @@ -240,6 +295,7 @@ def _get_configs_for_multi_dirs(
"extended-tests",
"compile-integration-tests",
"dependencies",
"test-pydantic",
]
}
map_job_to_configs["test-doc-imports"] = (
Expand Down
41 changes: 39 additions & 2 deletions .github/scripts/get_min_versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from typing import Optional

if sys.version_info >= (3, 11):
import tomllib
Expand All @@ -7,6 +8,9 @@
import tomli as tomllib

from packaging.version import parse as parse_version
from packaging.specifiers import SpecifierSet
from packaging.version import Version

import re

MIN_VERSION_LIBS = [
Expand Down Expand Up @@ -46,7 +50,13 @@ def get_min_version(version: str) -> str:
raise ValueError(f"Unrecognized version format: {version}")


def get_min_version_from_toml(toml_path: str, versions_for: str):
def get_min_version_from_toml(
toml_path: str,
versions_for: str,
python_version: str,
*,
include: Optional[list] = None,
):
# Parse the TOML file
with open(toml_path, "rb") as file:
toml_data = tomllib.load(file)
Expand All @@ -65,11 +75,20 @@ def get_min_version_from_toml(toml_path: str, versions_for: str):
continue
# Check if the lib is present in the dependencies
if lib in dependencies:
if include and lib not in include:
continue
# Get the version string
version_string = dependencies[lib]

if isinstance(version_string, dict):
version_string = version_string["version"]
if isinstance(version_string, list):
version_string = [
vs
for vs in version_string
if check_python_version(python_version, vs["python"])
][0]["version"]


# Use parse_version to get the minimum supported version from version_string
min_version = get_min_version(version_string)
Expand All @@ -80,13 +99,31 @@ def get_min_version_from_toml(toml_path: str, versions_for: str):
return min_versions


def check_python_version(version_string, constraint_string):
"""
Check if the given Python version matches the given constraints.

:param version_string: A string representing the Python version (e.g. "3.8.5").
:param constraint_string: A string representing the package's Python version constraints (e.g. ">=3.6, <4.0").
:return: True if the version matches the constraints, False otherwise.
"""
try:
version = Version(version_string)
constraints = SpecifierSet(constraint_string)
return version in constraints
except Exception as e:
print(f"Error: {e}")
return False


if __name__ == "__main__":
# Get the TOML file path from the command line argument
toml_file = sys.argv[1]
versions_for = sys.argv[2]
python_version = sys.argv[3]
assert versions_for in ["release", "pull_request"]

# Call the function to get the minimum versions
min_versions = get_min_version_from_toml(toml_file, versions_for)
min_versions = get_min_version_from_toml(toml_file, versions_for, python_version)

print(" ".join([f"{lib}=={version}" for lib, version in min_versions.items()]))
3 changes: 2 additions & 1 deletion .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ jobs:

- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
id: setup-python
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
Expand Down Expand Up @@ -231,7 +232,7 @@ jobs:
id: min-version
run: |
poetry run pip install packaging
min_versions="$(poetry run python $GITHUB_WORKSPACE/.github/scripts/get_min_versions.py pyproject.toml release)"
min_versions="$(poetry run python $GITHUB_WORKSPACE/.github/scripts/get_min_versions.py pyproject.toml release ${{ steps.setup-python.outputs.installed-python-version }})"
echo "min-versions=$min_versions" >> "$GITHUB_OUTPUT"
echo "min-versions=$min_versions"

Expand Down
32 changes: 18 additions & 14 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ jobs:

- name: Set up Python ${{ inputs.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
id: setup-python
with:
python-version: ${{ inputs.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: core

- name: Install dependencies
shell: bash
run: poetry install --with test
Expand All @@ -54,24 +54,15 @@ jobs:
run: |
make test

- name: Ensure the tests did not create any additional files
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moves it to end so it checks min tests also

shell: bash
run: |
set -eu

STATUS="$(git status)"
echo "$STATUS"

# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'

- name: Get minimum versions
working-directory: ${{ inputs.working-directory }}
id: min-version
shell: bash
run: |
poetry run pip install packaging tomli
min_versions="$(poetry run python $GITHUB_WORKSPACE/.github/scripts/get_min_versions.py pyproject.toml pull_request)"
echo "Python version ${{ steps.setup-python.outputs.installed-python-version }}"
python_version="$(poetry run python --version | awk '{print $2}')"
min_versions="$(poetry run python $GITHUB_WORKSPACE/.github/scripts/get_min_versions.py pyproject.toml pull_request $python_version)"
echo "min-versions=$min_versions" >> "$GITHUB_OUTPUT"
echo "min-versions=$min_versions"

Expand All @@ -83,3 +74,16 @@ jobs:
poetry run pip install --force-reinstall $MIN_VERSIONS --editable .
make tests
working-directory: ${{ inputs.working-directory }}

- name: Ensure the tests did not create any additional files
shell: bash
run: |
set -eu

STATUS="$(git status)"
echo "$STATUS"

# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'

64 changes: 64 additions & 0 deletions .github/workflows/_test_pydantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: test pydantic intermediate versions

on:
workflow_call:
inputs:
working-directory:
required: true
type: string
description: "From which folder this pipeline executes"
python-version:
required: false
type: string
description: "Python version to use"
default: "3.11"
pydantic-version:
required: true
type: string
description: "Pydantic version to test."

env:
POETRY_VERSION: "1.7.1"

jobs:
build:
defaults:
run:
working-directory: ${{ inputs.working-directory }}
runs-on: ubuntu-latest
name: "make test # pydantic: ~=${{ inputs.pydantic-version }}, python: ${{ inputs.python-version }}, "
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ inputs.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ inputs.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: core

- name: Install dependencies
shell: bash
run: poetry install --with test

- name: Overwrite pydantic version
shell: bash
run: poetry run pip install pydantic~=${{ inputs.pydantic-version }}

- name: Run core tests
shell: bash
run: |
make test

- name: Ensure the tests did not create any additional files
shell: bash
run: |
set -eu

STATUS="$(git status)"
echo "$STATUS"

# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'
Loading
Loading