Skip to content

Commit b7aa7c3

Browse files
authored
Fix pydantic2 cog builds (#2115)
* 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
1 parent 85b85bf commit b7aa7c3

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ requires-python = ">=3.8"
2323
dependencies = [
2424
# intentionally loose. perhaps these should be vendored to not collide with user code?
2525
"attrs>=20.1,<24",
26-
"fastapi>=0.75.2,<0.116.0",
26+
"fastapi>=0.100,<0.116.0",
2727
"pydantic>=1.9,<3",
2828
"PyYAML",
2929
"requests>=2,<3",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build:
2+
gpu: false
3+
python_version: "3.12"
4+
python_packages:
5+
- "pydantic>2"
6+
predict: "predict.py:Predictor"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from cog import BasePredictor
2+
3+
4+
class Predictor(BasePredictor):
5+
def predict(self, s: str) -> str:
6+
return "hello " + s

test-integration/test_integration/test_build.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def test_pip_freeze(docker_image):
385385
)
386386
assert (
387387
pip_freeze
388-
== "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"
388+
== "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"
389389
)
390390

391391

@@ -422,3 +422,15 @@ def test_fast_build(docker_image):
422422
os.remove(weights_file)
423423

424424
assert build_process.returncode == 0
425+
426+
427+
def test_pydantic2(docker_image):
428+
project_dir = Path(__file__).parent / "fixtures/pydantic2"
429+
430+
build_process = subprocess.run(
431+
["cog", "build", "-t", docker_image],
432+
cwd=project_dir,
433+
capture_output=True,
434+
)
435+
436+
assert build_process.returncode == 0

0 commit comments

Comments
 (0)