From b07243d7f55940bf19c83884c609328ccbe26edd Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Tue, 27 Feb 2024 13:37:50 +0100 Subject: [PATCH] Fix warnings --- giza/client.py | 14 +++++++------- giza/commands/deployments.py | 8 ++++---- giza/commands/models.py | 6 +++--- giza/commands/users.py | 2 +- giza/commands/versions.py | 6 +++--- giza/commands/workspaces.py | 2 +- giza/frameworks/cairo.py | 2 +- giza/frameworks/ezkl.py | 2 +- giza/schemas/deployments.py | 5 +++++ giza/schemas/jobs.py | 5 ++++- poetry.lock | 16 ++++++++-------- pyproject.toml | 2 +- tests/commands/test_versions.py | 2 +- tests/test_client.py | 18 +++++++++--------- 14 files changed, 49 insertions(+), 41 deletions(-) diff --git a/giza/client.py b/giza/client.py index a509204..3b0fd32 100644 --- a/giza/client.py +++ b/giza/client.py @@ -476,7 +476,7 @@ def create( ] ), headers=headers, - params=deployment_create.dict(), + params=deployment_create.model_dump(), files={"sierra": f} if f is not None else None, ) self._echo_debug(str(response)) @@ -826,7 +826,7 @@ def create(self, model_create: ModelCreate) -> Model: response = self.session.post( f"{self.url}/{self.MODELS_ENDPOINT}", headers=headers, - json=model_create.dict(), + json=model_create.model_dump(), ) self._echo_debug(str(response)) @@ -852,7 +852,7 @@ def update(self, model_id: int, model_update: ModelUpdate) -> Model: response = self.session.put( f"{self.url}/{self.MODELS_ENDPOINT}/{model_id}", headers=headers, - json=model_update.dict(), + json=model_update.model_dump(), ) self._echo_debug(str(response)) @@ -922,7 +922,7 @@ def create( response = self.session.post( f"{self.url}/{self.JOBS_ENDPOINT}", headers=headers, - params=job_create.dict(), + params=job_create.model_dump(), files=files, ) self._echo_debug(str(response)) @@ -1027,7 +1027,7 @@ def create( ] ), headers=headers, - params=job_create.dict(), + params=job_create.model_dump(), files={"file": f}, ) self._echo_debug(str(response)) @@ -1279,7 +1279,7 @@ def create( response = self.session.post( f"{self._get_version_url(model_id)}", headers=headers, - json=version_create.dict(), + json=version_create.model_dump(), params={"filename": filename} if filename else None, ) self._echo_debug(str(response)) @@ -1442,7 +1442,7 @@ def update( response = self.session.put( f"{self._get_version_url(model_id)}/{version_id}", headers=headers, - json=version_update.dict(), + json=version_update.model_dump(), ) self._echo_debug(str(response)) diff --git a/giza/commands/deployments.py b/giza/commands/deployments.py index 51adc10..8532ea6 100644 --- a/giza/commands/deployments.py +++ b/giza/commands/deployments.py @@ -104,7 +104,7 @@ def list( if debug: raise e sys.exit(1) - print_json(deployments.json()) + print_json(deployments.model_dump_json()) # giza/commands/deployments.py @@ -149,7 +149,7 @@ def get( if debug: raise e sys.exit(1) - print_json(deployment.json()) + print_json(deployment.model_dump_json()) @app.command( @@ -194,7 +194,7 @@ def list_proofs( if debug: raise e sys.exit(1) - print_json(proofs.json(exclude_unset=True)) + print_json(proofs.model_dump_json(exclude_unset=True)) @app.command( @@ -242,7 +242,7 @@ def get_proof( if debug: raise e sys.exit(1) - print_json(proof.json(exclude_unset=True)) + print_json(proof.model_dump_json(exclude_unset=True)) @app.command( diff --git a/giza/commands/models.py b/giza/commands/models.py index 9743c3c..ed9cd78 100644 --- a/giza/commands/models.py +++ b/giza/commands/models.py @@ -66,7 +66,7 @@ def get( if debug: raise e sys.exit(1) - print_json(model.json()) + print_json(model.model_dump_json()) @app.command( @@ -116,7 +116,7 @@ def list( if debug: raise e sys.exit(1) - print_json(models.json()) + print_json(models.model_dump_json()) @app.command( @@ -174,4 +174,4 @@ def create( if debug: raise e sys.exit(1) - print_json(model.json()) + print_json(model.model_dump_json()) diff --git a/giza/commands/users.py b/giza/commands/users.py index e8f62aa..6e8c5b9 100644 --- a/giza/commands/users.py +++ b/giza/commands/users.py @@ -199,7 +199,7 @@ def me(debug: Optional[bool] = DEBUG_OPTION) -> None: client = UsersClient(API_HOST, debug=debug) user = client.me() - print_json(user.json()) + print_json(user.model_dump_json()) @app.command( diff --git a/giza/commands/versions.py b/giza/commands/versions.py index bf35ac4..71c57d6 100644 --- a/giza/commands/versions.py +++ b/giza/commands/versions.py @@ -51,7 +51,7 @@ def get( with ExceptionHandler(debug=debug): client = VersionsClient(API_HOST) version: Version = client.get(model_id, version_id) - print_json(version.json()) + print_json(version.model_dump_json()) def transpile( @@ -180,7 +180,7 @@ def update( zip_path = zip_folder(model_path, tmp_dir) version = client.upload_cairo(model_id, version_id, zip_path) echo("Version updated ✅ ") - print_json(version.json()) + print_json(version.model_dump_json()) @app.command( @@ -201,7 +201,7 @@ def list( with ExceptionHandler(debug=debug): client = VersionsClient(API_HOST) versions: VersionList = client.list(model_id) - print_json(versions.json()) + print_json(versions.model_dump_json()) @app.command( diff --git a/giza/commands/workspaces.py b/giza/commands/workspaces.py index d464569..dc38ae1 100644 --- a/giza/commands/workspaces.py +++ b/giza/commands/workspaces.py @@ -57,7 +57,7 @@ def get( echo.error("⛔️Please delete the workspace and create a new one⛔️") else: echo.info(f"✅ Workspace URL: {workspace.url} ✅") - print_json(workspace.json()) + print_json(workspace.model_dump_json()) @app.command( diff --git a/giza/frameworks/cairo.py b/giza/frameworks/cairo.py index 3a2d87d..bd52a3d 100644 --- a/giza/frameworks/cairo.py +++ b/giza/frameworks/cairo.py @@ -144,7 +144,7 @@ def deploy( client = DeploymentsClient(API_HOST) deployments_list: DeploymentsList = client.list(model_id, version_id) - deployments: dict = json.loads(deployments_list.json()) + deployments: dict = json.loads(deployments_list.model_dump_json()) if len(deployments) > 0: echo.info( diff --git a/giza/frameworks/ezkl.py b/giza/frameworks/ezkl.py index d467d3a..a3f2332 100644 --- a/giza/frameworks/ezkl.py +++ b/giza/frameworks/ezkl.py @@ -343,7 +343,7 @@ def deploy( client = DeploymentsClient(API_HOST) deployments_list: DeploymentsList = client.list(model_id, version_id) - deployments: dict = json.loads(deployments_list.json()) + deployments: dict = json.loads(deployments_list.model_dump_json()) if len(deployments) > 0: echo.info( diff --git a/giza/schemas/deployments.py b/giza/schemas/deployments.py index 22cd168..efc7da0 100644 --- a/giza/schemas/deployments.py +++ b/giza/schemas/deployments.py @@ -15,6 +15,9 @@ class DeploymentCreate(BaseModel): service_name: Optional[str] = None framework: Framework = Framework.CAIRO + model_config = ConfigDict(from_attributes=True) + model_config["protected_namespaces"] = () + class Deployment(BaseModel): id: int @@ -24,7 +27,9 @@ class Deployment(BaseModel): service_name: Optional[str] = None model_id: Optional[int] = None version_id: Optional[int] = None + model_config = ConfigDict(from_attributes=True) + model_config["protected_namespaces"] = () class DeploymentsList(RootModel): diff --git a/giza/schemas/jobs.py b/giza/schemas/jobs.py index b50d0f9..b1652b9 100644 --- a/giza/schemas/jobs.py +++ b/giza/schemas/jobs.py @@ -1,7 +1,7 @@ import datetime from typing import Optional -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict from giza.utils.enums import Framework, JobKind, JobSize, JobStatus @@ -23,3 +23,6 @@ class JobCreate(BaseModel): model_id: Optional[int] = None version_id: Optional[int] = None proof_id: Optional[int] = None + + model_config = ConfigDict(from_attributes=True) + model_config["protected_namespaces"] = () diff --git a/poetry.lock b/poetry.lock index 11ef556..314708e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -590,13 +590,13 @@ gmpy2 = ["gmpy2"] [[package]] name = "email-validator" -version = "2.1.0.post1" +version = "2.1.1" description = "A robust email address syntax and deliverability validation library." optional = false python-versions = ">=3.8" files = [ - {file = "email_validator-2.1.0.post1-py3-none-any.whl", hash = "sha256:c973053efbeddfef924dc0bd93f6e77a1ea7ee0fce935aea7103c7a3d6d2d637"}, - {file = "email_validator-2.1.0.post1.tar.gz", hash = "sha256:a4b0bd1cf55f073b924258d19321b1f3aa74b4b5a71a42c305575dba920e1a44"}, + {file = "email_validator-2.1.1-py3-none-any.whl", hash = "sha256:97d882d174e2a65732fb43bfce81a3a834cbc1bde8bf419e30ef5ea976370a05"}, + {file = "email_validator-2.1.1.tar.gz", hash = "sha256:200a70680ba08904be6d1eef729205cc0d687634399a5924d842533efb824b84"}, ] [package.dependencies] @@ -671,13 +671,13 @@ files = [ [[package]] name = "ipykernel" -version = "6.29.2" +version = "6.29.3" description = "IPython Kernel for Jupyter" optional = false python-versions = ">=3.8" files = [ - {file = "ipykernel-6.29.2-py3-none-any.whl", hash = "sha256:50384f5c577a260a1d53f1f59a828c7266d321c9b7d00d345693783f66616055"}, - {file = "ipykernel-6.29.2.tar.gz", hash = "sha256:3bade28004e3ff624ed57974948116670604ac5f676d12339693f3142176d3f0"}, + {file = "ipykernel-6.29.3-py3-none-any.whl", hash = "sha256:5aa086a4175b0229d4eca211e181fb473ea78ffd9869af36ba7694c947302a21"}, + {file = "ipykernel-6.29.3.tar.gz", hash = "sha256:e14c250d1f9ea3989490225cc1a542781b095a18a19447fcf2b5eaf7d0ac5bd2"}, ] [package.dependencies] @@ -700,7 +700,7 @@ cov = ["coverage[toml]", "curio", "matplotlib", "pytest-cov", "trio"] docs = ["myst-parser", "pydata-sphinx-theme", "sphinx", "sphinx-autodoc-typehints", "sphinxcontrib-github-alt", "sphinxcontrib-spelling", "trio"] pyqt5 = ["pyqt5"] pyside6 = ["pyside6"] -test = ["flaky", "ipyparallel", "pre-commit", "pytest (>=7.0)", "pytest-asyncio (==0.23.4)", "pytest-cov", "pytest-timeout"] +test = ["flaky", "ipyparallel", "pre-commit", "pytest (>=7.0)", "pytest-asyncio (>=0.23.5)", "pytest-cov", "pytest-timeout"] [[package]] name = "ipython" @@ -1981,4 +1981,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "c35963e290756b8c385f4e4f4b8757041245fe5cb0119701b1fd8ba37bd377c9" +content-hash = "5a4a9505b15a9cd6686ccfa233462d2eff13429302be7d652cfa5fca18142527" diff --git a/pyproject.toml b/pyproject.toml index 3918cdf..3eeccca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ types-python-jose = "^3.3.4.8" types-requests = "^2.31.0.2" cookiecutter = "^2.5.0" semver = "^3.0.2" -pydantic = "^2.6.1" +pydantic = "^2" [tool.poetry.group.dev.dependencies] pre-commit = "^3.3.3" diff --git a/tests/commands/test_versions.py b/tests/commands/test_versions.py index d5903c4..3f7f10a 100644 --- a/tests/commands/test_versions.py +++ b/tests/commands/test_versions.py @@ -386,7 +386,7 @@ def test_versions_update_successful(): last_update="2021-08-31T15:00:00.000000", framework=Framework.CAIRO, ) - updated_version = version.copy() + updated_version = version.model_copy() updated_version.status = VersionStatus.COMPLETED with patch.object(VersionsClient, "get", return_value=version), patch.object( diff --git a/tests/test_client.py b/tests/test_client.py index ae56a4f..d84836e 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -255,7 +255,7 @@ def test_versions_client_get(tmpdir): last_update="2021-08-31T15:00:00.000000", framework=Framework.CAIRO, ) - response = ResponseStub(version.dict(), 200) + response = ResponseStub(version.model_dump(), 200) with patch("pathlib.Path.home", return_value=tmpdir), patch( "requests.Session.get", return_value=response ) as mock_request, patch("jose.jwt.decode"): @@ -276,7 +276,7 @@ def test_versions_client_list(tmpdir): framework=Framework.CAIRO, last_update="2021-08-31T15:00:00.000000", ) - response = ResponseStub([version.dict()], 200) + response = ResponseStub([version.model_dump()], 200) with patch("pathlib.Path.home", return_value=tmpdir), patch( "requests.Session.get", return_value=response ) as mock_request, patch("jose.jwt.decode"): @@ -299,7 +299,7 @@ def test_versions_client_create(tmpdir): framework=Framework.CAIRO, ) response = ResponseStub( - version.dict(), 201, headers={MODEL_URL_HEADER.lower(): "url"} + version.model_dump(), 201, headers={MODEL_URL_HEADER.lower(): "url"} ) with patch("pathlib.Path.home", return_value=tmpdir), patch( "requests.Session.post", return_value=response @@ -333,7 +333,7 @@ def test_versions_client_get_non_existent(tmpdir): def test_jobs_client_get(tmpdir): job_id = 1 job = Job(id=1, job_name="job", size=JobSize.S, status=JobStatus.STARTING) - response = ResponseStub(job.dict(), 200) + response = ResponseStub(job.model_dump(), 200) with patch("pathlib.Path.home", return_value=tmpdir), patch( "requests.Session.get", return_value=response ) as mock_request, patch("jose.jwt.decode"): @@ -346,7 +346,7 @@ def test_jobs_client_get(tmpdir): def test_jobs_client_list(tmpdir): job = Job(id=1, job_name="job", size=JobSize.S, status=JobStatus.STARTING) - response = ResponseStub([job.dict()], 200) + response = ResponseStub([job.model_dump()], 200) with patch("pathlib.Path.home", return_value=tmpdir), patch( "requests.Session.get", return_value=response ) as mock_request, patch("jose.jwt.decode"): @@ -359,7 +359,7 @@ def test_jobs_client_list(tmpdir): def test_jobs_client_create(tmpdir): job = Job(id=1, job_name="job", size=JobSize.S, status=JobStatus.STARTING) - response = ResponseStub(job.dict(), 201) + response = ResponseStub(job.model_dump(), 201) with patch("pathlib.Path.home", return_value=tmpdir), patch( "requests.Session.post", return_value=response ) as mock_request, patch("jose.jwt.decode"): @@ -381,7 +381,7 @@ def test_proof_client_get(tmpdir): cairo_execution_time=100, created_date=datetime.datetime.now(), ) - response = ResponseStub(proof.dict(), 200) + response = ResponseStub(proof.model_dump(), 200) with patch("pathlib.Path.home", return_value=tmpdir), patch( "requests.Session.get", return_value=response ) as mock_request, patch("jose.jwt.decode"): @@ -401,7 +401,7 @@ def test_proof_client_get_by_job_id(tmpdir): cairo_execution_time=100, created_date=datetime.datetime.now(), ) - response = ResponseStub([proof.dict()], 200) + response = ResponseStub([proof.model_dump()], 200) with patch("pathlib.Path.home", return_value=tmpdir), patch( "requests.Session.get", return_value=response ) as mock_request, patch("jose.jwt.decode"): @@ -421,7 +421,7 @@ def test_proof_client_list(tmpdir): cairo_execution_time=100, created_date=datetime.datetime.now(), ) - response = ResponseStub([proof.dict()], 200) + response = ResponseStub([proof.model_dump()], 200) with patch("pathlib.Path.home", return_value=tmpdir), patch( "requests.Session.get", return_value=response ) as mock_request, patch("jose.jwt.decode"):