From aa040cc405097064c4b21a44c97babb7cb0eaf23 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Mon, 16 Dec 2024 09:33:43 +0100 Subject: [PATCH] Updated pydantic models such that they work for pydantic > 2.10.0 --- .../dataresource_pydantic2.py | 56 +++++++++---------- requirements_full.txt | 4 +- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/examples/datamodel_as_rdf/dataresource_pydantic2.py b/examples/datamodel_as_rdf/dataresource_pydantic2.py index 0d70a0d95..2300f344b 100644 --- a/examples/datamodel_as_rdf/dataresource_pydantic2.py +++ b/examples/datamodel_as_rdf/dataresource_pydantic2.py @@ -16,6 +16,8 @@ print("This example requires pydantic v2") raise SystemExit(44) +HostlessAnyUrl = Annotated[AnyUrl, UrlConstraints(host_required=False)] + class ResourceConfig(BaseModel): """Resource Strategy Data Configuration. @@ -25,21 +27,17 @@ class ResourceConfig(BaseModel): `accessUrl`/`accessService` MUST be specified. """ - downloadUrl: Annotated[ - Optional[AnyUrl], - UrlConstraints(host_required=False), - Field( - None, - description=( - """Definition: The URL of the downloadable file in a given - format. E.g. CSV " "file or RDF file. + downloadUrl: Optional[HostlessAnyUrl] = Field( + None, + description=( + """Definition: The URL of the downloadable file in a given + format. E.g. CSV " "file or RDF file. - Usage: `downloadURL` *SHOULD* be used for the URL at which - this distribution is available directly, typically through a - HTTPS GET request or SFTP.""" - ), + Usage: `downloadURL` *SHOULD* be used for the URL at which + this distribution is available directly, typically through a + HTTPS GET request or SFTP.""" ), - ] + ) mediaType: Annotated[ Optional[str], Field( @@ -55,25 +53,21 @@ class ResourceConfig(BaseModel): ), ), ] - accessUrl: Annotated[ - Optional[AnyUrl], - UrlConstraints(host_required=False), - Field( - None, - description=( - """A URL of the resource that gives access to a distribution of - the dataset. E.g. landing page, feed, SPARQL endpoint. - - Usage: `accessURL` *SHOULD* be used for the URL of a - service or location that can provide access to this - distribution, typically through a Web form, query or API - call. - - `downloadURL` is preferred for direct links to downloadable - resources.""" - ), + accessUrl: Optional[HostlessAnyUrl] = Field( + None, + description=( + """A URL of the resource that gives access to a distribution of + the dataset. E.g. landing page, feed, SPARQL endpoint. + + Usage: `accessURL` *SHOULD* be used for the URL of a + service or location that can provide access to this + distribution, typically through a Web form, query or API + call. + + `downloadURL` is preferred for direct links to downloadable + resources.""" ), - ] + ) accessService: Annotated[ Optional[str], Field( diff --git a/requirements_full.txt b/requirements_full.txt index a65808a7b..127aa4808 100644 --- a/requirements_full.txt +++ b/requirements_full.txt @@ -21,8 +21,8 @@ pymongo>=4.4.0,<5 #psycopg2>=2,<3 # Utilities -# Bug in pydantic 2.10.1, see https://github.com/pydantic/pydantic/issues/9898 -pydantic>=1.10.0,!=2.10.0,!=2.10.1,<2.10.2 +# Bug in pydantic 2.10.0, see https://github.com/pydantic/pydantic/issues/9898 +pydantic>=1.10.0,!=2.10.0,<2.10.4 typing_extensions>=4.1,<5; python_version<'3.9' fortran-language-server>=1.12.0,<1.13