Skip to content

Commit 3bfa565

Browse files
authored
Upgrade to pydantic 2 (#318)
1 parent a27f47c commit 3bfa565

File tree

81 files changed

+545
-398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+545
-398
lines changed

pctasks/cli/requirements.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ aiohttp==3.9.5
66
aiosignal==1.3.1
77
# via aiohttp
88
# from https://pypi.org/simple
9+
annotated-types==0.7.0
10+
# via pydantic
11+
# from https://pypi.org/simple
912
async-timeout==4.0.3
1013
# via aiohttp
1114
# from https://pypi.org/simple
@@ -163,10 +166,17 @@ pyasn1-modules==0.4.0
163166
pycparser==2.22
164167
# via cffi
165168
# from https://pypi.org/simple
166-
pydantic==1.10.15
169+
pydantic==2.10.6
167170
# via
168171
# pctasks-core
169172
# planetary-computer
173+
# pydantic-settings
174+
# from https://pypi.org/simple
175+
pydantic-core==2.27.2
176+
# via pydantic
177+
# from https://pypi.org/simple
178+
pydantic-settings==2.8.1
179+
# via pctasks-core
170180
# from https://pypi.org/simple
171181
pyjwt==2.8.0
172182
# via msal
@@ -191,7 +201,9 @@ python-dateutil==2.8.2
191201
# strictyaml
192202
# from https://pypi.org/simple
193203
python-dotenv==1.0.1
194-
# via planetary-computer
204+
# via
205+
# planetary-computer
206+
# pydantic-settings
195207
# from https://pypi.org/simple
196208
pytz==2024.1
197209
# via planetary-computer
@@ -225,14 +237,15 @@ stac-validator==3.3.2
225237
strictyaml==1.7.3
226238
# via pctasks-core
227239
# from https://pypi.org/simple
228-
typing-extensions==4.11.0
240+
typing-extensions==4.12.2
229241
# via
230242
# azure-core
231243
# azure-cosmos
232244
# azure-data-tables
233245
# azure-storage-blob
234246
# azure-storage-queue
235247
# pydantic
248+
# pydantic-core
236249
# from https://pypi.org/simple
237250
urllib3==2.2.1
238251
# via requests

pctasks/client/pctasks/client/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _yield_page_results(
174174
route,
175175
params=params,
176176
)
177-
result = record_list_response_type.parse_obj(resp)
177+
result = record_list_response_type.model_validate(resp)
178178
yield from result.records
179179
page_count += 1
180180
page_token = result.next_page_token
@@ -285,7 +285,7 @@ def get_workflow(self, workflow_id: str) -> Optional[WorkflowRecord]:
285285
result = self._call_api(
286286
"GET", WORKFLOW_ROUTE.format(workflow_id=workflow_id)
287287
)
288-
return WorkflowRecordResponse.parse_obj(result).record
288+
return WorkflowRecordResponse.model_validate(result).record
289289
except HTTPError as e:
290290
if e.response.status_code == 404:
291291
return None
@@ -369,7 +369,7 @@ def submit_workflow(
369369

370370
workflow_def = workflow.definition
371371

372-
request = request.copy()
372+
request = request.model_copy()
373373

374374
# Ensure arguments
375375
request.args = self.settings.add_default_args(
@@ -452,7 +452,7 @@ def get_workflow_run(
452452
route += f"?dataset={dataset_id}"
453453
try:
454454
result = self._call_api("GET", route)
455-
return WorkflowRunRecordResponse.parse_obj(result).record
455+
return WorkflowRunRecordResponse.model_validate(result).record
456456
except HTTPError as e:
457457
if e.response.status_code == 404:
458458
return None
@@ -497,7 +497,7 @@ def get_job_partition_run(
497497
)
498498
try:
499499
result = self._call_api("GET", route)
500-
return JobPartitionRunRecordResponse.parse_obj(result).record
500+
return JobPartitionRunRecordResponse.model_validate(result).record
501501
except HTTPError as e:
502502
if e.response.status_code == 404:
503503
return None

pctasks/client/pctasks/client/profile/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def set_profile(ctx: click.Context, profile: str) -> None:
141141
rprint(f"[red]Profile [bold]{profile}[/bold] does not exists[/red]")
142142
ctx.exit(1)
143143

144-
profile_only_config = settings_config.copy(update={"settings_file": None})
144+
profile_only_config = settings_config.model_copy(update={"settings_file": None})
145145
profile_settings_file = profile_only_config.get_settings_file()
146146
if not Path(profile_settings_file).exists():
147147
raise click.UsageError(
@@ -160,7 +160,7 @@ def show_profile(ctx: click.Context, profile: str) -> None:
160160
rprint(f"[red]Profile [bold]{profile}[/bold] does not exists[/red]")
161161
ctx.exit(1)
162162

163-
profile_only_config = settings_config.copy(update={"settings_file": None})
163+
profile_only_config = settings_config.model_copy(update={"settings_file": None})
164164
yaml_txt = profile_only_config.get_settings_file().read_text()
165165
console = Console()
166166
console.print(Syntax(yaml_txt, "yaml"))

pctasks/client/pctasks/client/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict, Optional
22
from urllib.parse import urlparse
33

4-
from pydantic import validator
4+
from pydantic import field_validator
55

66
from pctasks.core.models.workflow import WorkflowDefinition
77
from pctasks.core.settings import PCTasksSettings
@@ -21,7 +21,7 @@ def section_name(cls) -> str:
2121
default_args: Optional[Dict[str, str]] = None
2222
default_page_size: int = DEFAULT_PAGE_SIZE
2323

24-
@validator("endpoint")
24+
@field_validator("endpoint", mode="after")
2525
def _validate_endpoint(cls, v: str) -> str:
2626
try:
2727
parsed = urlparse(v)

pctasks/client/pctasks/client/workflow/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def cli_handle_workflow(
264264
workflow_id = workflow_def.workflow_id
265265

266266
else:
267-
workflow_def = workflow_def.copy(update={"workflow_id": workflow_id})
267+
workflow_def = workflow_def.model_copy(update={"workflow_id": workflow_id})
268268

269269
if not client:
270270
client = PCTasksClient(settings=ClientSettings.from_context(ctx.obj))

pctasks/client/pctasks/client/workflow/template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def template_workflow_dict(
2424
base_path = base_path or Path(".")
2525
workflow_dict = LocalTemplater(base_path).template_dict(workflow_dict)
2626

27-
return WorkflowDefinition.parse_obj(workflow_dict)
27+
return WorkflowDefinition.model_validate(workflow_dict)
2828

2929

3030
def template_workflow_contents(

pctasks/client/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers = [
2626
dependencies = [
2727
"pctasks.core @ {root:parent:uri}/core",
2828
"pctasks.cli @ {root:parent:uri}/cli",
29-
"pydantic[dotenv]>=1.8,<2.0.0",
29+
"pydantic[dotenv]>=2.0.0",
3030
"rich>=11.2.0",
3131
]
3232

pctasks/client/requirements.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ aiohttp==3.9.5
66
aiosignal==1.3.1
77
# via aiohttp
88
# from https://pypi.org/simple
9+
annotated-types==0.7.0
10+
# via pydantic
11+
# from https://pypi.org/simple
912
async-timeout==4.0.3
1013
# via aiohttp
1114
# from https://pypi.org/simple
@@ -173,11 +176,18 @@ pyasn1-modules==0.4.0
173176
pycparser==2.22
174177
# via cffi
175178
# from https://pypi.org/simple
176-
pydantic==1.10.15
179+
pydantic==2.10.6
177180
# via
178181
# pctasks-client (./pctasks/client/pyproject.toml)
179182
# pctasks-core
180183
# planetary-computer
184+
# pydantic-settings
185+
# from https://pypi.org/simple
186+
pydantic-core==2.27.2
187+
# via pydantic
188+
# from https://pypi.org/simple
189+
pydantic-settings==2.8.1
190+
# via pctasks-core
181191
# from https://pypi.org/simple
182192
pygments==2.17.2
183193
# via rich
@@ -207,7 +217,7 @@ python-dateutil==2.8.2
207217
python-dotenv==1.0.1
208218
# via
209219
# planetary-computer
210-
# pydantic
220+
# pydantic-settings
211221
# from https://pypi.org/simple
212222
pytz==2024.1
213223
# via planetary-computer
@@ -244,14 +254,15 @@ stac-validator==3.3.2
244254
strictyaml==1.7.3
245255
# via pctasks-core
246256
# from https://pypi.org/simple
247-
typing-extensions==4.11.0
257+
typing-extensions==4.12.2
248258
# via
249259
# azure-core
250260
# azure-cosmos
251261
# azure-data-tables
252262
# azure-storage-blob
253263
# azure-storage-queue
254264
# pydantic
265+
# pydantic-core
255266
# from https://pypi.org/simple
256267
urllib3==2.2.1
257268
# via requests

pctasks/client/tests/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from pctasks.dev.blob import get_azurite_code_storage
1010
from pctasks.dev.test_utils import assert_workflow_is_successful
1111

12+
# from pctasks.dev.test_utils import assert_workflow_is_successful
13+
1214
HERE = pathlib.Path(__file__).parent
1315

1416

pctasks/client/tests/test_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_local_file_template():
2323
yaml_dict = yaml.safe_load(yaml_str)
2424
templated_dict = LocalTemplater().template_dict(yaml_dict)
2525

26-
data = IngestCollectionsInput.parse_obj(templated_dict)
26+
data = IngestCollectionsInput.model_validate(templated_dict)
2727

2828
assert data.collections
2929
assert data.collections[0]["id"] == "test-collection"

0 commit comments

Comments
 (0)