diff --git a/hsmodels/__init__.py b/hsmodels/__init__.py index e69de29..0fc8e5e 100644 --- a/hsmodels/__init__.py +++ b/hsmodels/__init__.py @@ -0,0 +1,16 @@ +from pydantic_core import Url + + +def __add__(self, other): + return str(self) + other + + +def __radd__(self, other): + return other + str(self) + + +# monkey patch string concatentation until pydantic implements Url as an extension of str again +# https://github.com/pydantic/pydantic-core/pull/1126 + +Url.__add__ = __add__ +Url.__radd__ = __radd__ diff --git a/hsmodels/schemas/__init__.py b/hsmodels/schemas/__init__.py index 81619b5..97ebf59 100644 --- a/hsmodels/schemas/__init__.py +++ b/hsmodels/schemas/__init__.py @@ -2,9 +2,9 @@ from enum import Enum from pydantic import BaseModel -from pydantic_core import Url from rdflib import Graph, Literal, URIRef +from hsmodels import Url from hsmodels.namespaces import DC, HSTERMS, ORE, RDF, RDFS1 from hsmodels.schemas.aggregations import ( FileSetMetadata, diff --git a/hsmodels/schemas/rdf/validators.py b/hsmodels/schemas/rdf/validators.py index 63e5a79..0c9446f 100644 --- a/hsmodels/schemas/rdf/validators.py +++ b/hsmodels/schemas/rdf/validators.py @@ -1,5 +1,4 @@ -from pydantic_core import Url - +from hsmodels import Url from hsmodels.schemas.enums import CoverageType, DateType from hsmodels.schemas.languages_iso import languages diff --git a/hsmodels/schemas/root_validators.py b/hsmodels/schemas/root_validators.py index cd5e728..66a84aa 100644 --- a/hsmodels/schemas/root_validators.py +++ b/hsmodels/schemas/root_validators.py @@ -1,6 +1,6 @@ -from pydantic_core import Url from rdflib import URIRef +from hsmodels import Url from hsmodels.schemas.enums import CoverageType, DateType, ModelProgramFileType, RelationType, UserIdentifierType from hsmodels.utils import to_coverage_dict diff --git a/tests/test_metadata.py b/tests/test_metadata.py index a35b47a..c024290 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -171,3 +171,9 @@ def test_resource_metadata(res_md): res_md.publisher.name == "Consortium of Universities for the Advancement of Hydrologic Science, Inc. (CUAHSI)" ) assert str(res_md.publisher.url) == "https://www.cuahsi.org/" + + +def test_resource_metadata_url_str_concat(res_md): + assert ( + "concat test " + res_md.url == "concat test http://www.hydroshare.org/resource/84805fd615a04d63b4eada65644a1e20" + )