Skip to content

Commit

Permalink
Fix pydantic2 cog builds (#2115)
Browse files Browse the repository at this point in the history
* Add integration test for pydantic2

* Upgrade fastapi to >= 0.100

* This version of fastapi will work with pydantic2

* Add predict.py int-test

* Fix pip freeze test
  • Loading branch information
8W9aG authored Jan 21, 2025
1 parent 85b85bf commit b7aa7c3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ requires-python = ">=3.8"
dependencies = [
# intentionally loose. perhaps these should be vendored to not collide with user code?
"attrs>=20.1,<24",
"fastapi>=0.75.2,<0.116.0",
"fastapi>=0.100,<0.116.0",
"pydantic>=1.9,<3",
"PyYAML",
"requests>=2,<3",
Expand Down
6 changes: 6 additions & 0 deletions test-integration/test_integration/fixtures/pydantic2/cog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build:
gpu: false
python_version: "3.12"
python_packages:
- "pydantic>2"
predict: "predict.py:Predictor"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from cog import BasePredictor


class Predictor(BasePredictor):
def predict(self, s: str) -> str:
return "hello " + s
14 changes: 13 additions & 1 deletion test-integration/test_integration/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def test_pip_freeze(docker_image):
)
assert (
pip_freeze
== "anyio==4.4.0\nattrs==23.2.0\ncertifi==2024.8.30\ncharset-normalizer==3.3.2\nclick==8.1.7\nexceptiongroup==1.2.2\nfastapi==0.98.0\nh11==0.14.0\nhttptools==0.6.1\nidna==3.8\npydantic==1.10.18\npython-dotenv==1.0.1\nPyYAML==6.0.2\nrequests==2.32.3\nsniffio==1.3.1\nstarlette==0.27.0\nstructlog==24.4.0\ntyping_extensions==4.12.2\nurllib3==2.2.2\nuvicorn==0.30.6\nuvloop==0.20.0\nwatchfiles==0.24.0\nwebsockets==13.0.1\n"
== "anyio==4.4.0\nattrs==23.2.0\ncertifi==2024.8.30\ncharset-normalizer==3.3.2\nclick==8.1.7\nexceptiongroup==1.2.2\nfastapi==0.115.6\nh11==0.14.0\nhttptools==0.6.1\nidna==3.8\npydantic==1.10.18\npython-dotenv==1.0.1\nPyYAML==6.0.2\nrequests==2.32.3\nsniffio==1.3.1\nstarlette==0.41.3\nstructlog==24.4.0\ntyping_extensions==4.12.2\nurllib3==2.2.2\nuvicorn==0.30.6\nuvloop==0.20.0\nwatchfiles==0.24.0\nwebsockets==13.0.1\n"
)


Expand Down Expand Up @@ -422,3 +422,15 @@ def test_fast_build(docker_image):
os.remove(weights_file)

assert build_process.returncode == 0


def test_pydantic2(docker_image):
project_dir = Path(__file__).parent / "fixtures/pydantic2"

build_process = subprocess.run(
["cog", "build", "-t", docker_image],
cwd=project_dir,
capture_output=True,
)

assert build_process.returncode == 0

0 comments on commit b7aa7c3

Please sign in to comment.