From a6b170f7ae9fd2715345cceffe79b07fd733965e Mon Sep 17 00:00:00 2001 From: artdotlis Date: Wed, 10 Dec 2025 09:50:38 +0000 Subject: [PATCH 1/2] refactor(link): add URL validation for link status and result --- configs/dev/requirements.dev.txt | 6 +++--- configs/dev/requirements.docs.txt | 6 +++--- pyproject.toml | 2 +- requirements.txt | 8 ++++---- src/saim/culture_link/private/container.py | 17 +++++++++++++++++ src/saim/culture_link/validate_cafi.py | 3 +-- src/saim/shared/data_con/culture.py | 4 +--- uv.lock | 12 ++++++------ 8 files changed, 36 insertions(+), 22 deletions(-) diff --git a/configs/dev/requirements.dev.txt b/configs/dev/requirements.dev.txt index 068031c..172508b 100644 --- a/configs/dev/requirements.dev.txt +++ b/configs/dev/requirements.dev.txt @@ -323,9 +323,9 @@ typing-extensions==4.15.0 \ --hash=sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466 \ --hash=sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548 # via mypy -urllib3==2.6.0 \ - --hash=sha256:c90f7a39f716c572c4e3e58509581ebd83f9b59cced005b7db7ad2d22b0db99f \ - --hash=sha256:cb9bcef5a4b345d5da5d145dc3e30834f58e8018828cbc724d30b4cb7d4d49f1 +urllib3==2.6.1 \ + --hash=sha256:5379eb6e1aba4088bae84f8242960017ec8d8e3decf30480b3a1abdaa9671a3f \ + --hash=sha256:e67d06fe947c36a7ca39f4994b08d73922d40e6cca949907be05efa6fd75110b # via types-requests vulture==2.14 \ --hash=sha256:cb8277902a1138deeab796ec5bef7076a6e0248ca3607a3f3dee0b6d9e9b8415 \ diff --git a/configs/dev/requirements.docs.txt b/configs/dev/requirements.docs.txt index 2b5e003..328f456 100644 --- a/configs/dev/requirements.docs.txt +++ b/configs/dev/requirements.docs.txt @@ -258,9 +258,9 @@ six==1.17.0 \ --hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274 \ --hash=sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81 # via python-dateutil -urllib3==2.6.0 \ - --hash=sha256:c90f7a39f716c572c4e3e58509581ebd83f9b59cced005b7db7ad2d22b0db99f \ - --hash=sha256:cb9bcef5a4b345d5da5d145dc3e30834f58e8018828cbc724d30b4cb7d4d49f1 +urllib3==2.6.1 \ + --hash=sha256:5379eb6e1aba4088bae84f8242960017ec8d8e3decf30480b3a1abdaa9671a3f \ + --hash=sha256:e67d06fe947c36a7ca39f4994b08d73922d40e6cca949907be05efa6fd75110b # via requests watchdog==6.0.0 \ --hash=sha256:07df1fdd701c5d4c8e55ef6cf55b8f0120fe1aef7ef39a1c6fc6bc2e606d517a \ diff --git a/pyproject.toml b/pyproject.toml index 3fbbea6..5591beb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ dependencies = [ "python-keycloak ==5.8.1", "requests ==2.32.5", "requests-cache ==1.2.1", - "cafi @ git+https://github.com/LeibnizDSMZ/cafi.git@v0.9.13", + "cafi @ git+https://github.com/LeibnizDSMZ/cafi.git@v0.9.14", ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index 3130b7f..9af1034 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,7 +23,7 @@ attrs==25.4.0 \ # via # cattrs # requests-cache -cafi @ git+https://github.com/LeibnizDSMZ/cafi.git@72a82fe8adce0b3ac4e9ced363550541692cf500 +cafi @ git+https://github.com/LeibnizDSMZ/cafi.git@e90398f246bba7539af28bfaaeca0dcbd54c206c # via saim cattrs==25.3.0 \ --hash=sha256:1ac88d9e5eda10436c4517e390a4142d88638fe682c436c93db7ce4a277b884a \ @@ -335,9 +335,9 @@ url-normalize==2.2.1 \ --hash=sha256:3deb687587dc91f7b25c9ae5162ffc0f057ae85d22b1e15cf5698311247f567b \ --hash=sha256:74a540a3b6eba1d95bdc610c24f2c0141639f3ba903501e61a52a8730247ff37 # via requests-cache -urllib3==2.6.0 \ - --hash=sha256:c90f7a39f716c572c4e3e58509581ebd83f9b59cced005b7db7ad2d22b0db99f \ - --hash=sha256:cb9bcef5a4b345d5da5d145dc3e30834f58e8018828cbc724d30b4cb7d4d49f1 +urllib3==2.6.1 \ + --hash=sha256:5379eb6e1aba4088bae84f8242960017ec8d8e3decf30480b3a1abdaa9671a3f \ + --hash=sha256:e67d06fe947c36a7ca39f4994b08d73922d40e6cca949907be05efa6fd75110b # via # requests # requests-cache diff --git a/src/saim/culture_link/private/container.py b/src/saim/culture_link/private/container.py index 077851a..c1521fd 100644 --- a/src/saim/culture_link/private/container.py +++ b/src/saim/culture_link/private/container.py @@ -2,6 +2,7 @@ from typing import Iterator, final from cafi.container.links import CatalogueLink +from pydantic import HttpUrl, ValidationError from saim.culture_link.private.constants import ( CAT_DET_EXP_DAYS, CAT_EXP_DAYS, @@ -89,6 +90,15 @@ class LinkStatus: link_type: str status: VerificationStatus + def __post_init__(self) -> None: + try: + if self.link != "": + object.__setattr__(self, "link", str(HttpUrl(self.link))) + except ValidationError: + object.__setattr__(self, "link", "") + if self.link == "": + object.__setattr__(self, "status", VerificationStatus.no_url) + @final @dataclass(frozen=True, slots=True) @@ -97,6 +107,13 @@ class LinkResult: brc_id: int found_ccno: CCNoDes + def __post_init__(self) -> None: + try: + if self.link != "": + object.__setattr__(self, "link", str(HttpUrl(self.link))) + except ValidationError: + object.__setattr__(self, "link", "") + @final @dataclass(frozen=True, slots=True) diff --git a/src/saim/culture_link/validate_cafi.py b/src/saim/culture_link/validate_cafi.py index e13684a..7a7a9f8 100644 --- a/src/saim/culture_link/validate_cafi.py +++ b/src/saim/culture_link/validate_cafi.py @@ -5,7 +5,6 @@ from cafi.library.loader import load_catalogue_db, load_regex_db from cafi.container.acr_db import AcrDbEntry from cafi.container.links import LinkLevel -from cafi.container.fun.format import url_to_str from saim.culture_link.create_links import CcnoLinkGenerator, SearchRequest from saim.designation.manager import AcronymManager @@ -21,7 +20,7 @@ def _create_search_request_homepage( exclude=(LinkLevel.cat,), ) for task_id, (acr_id, acr_entry) in enumerate(cc_db.items()) - if url_to_str(acr_entry.homepage) != "" + if str(acr_entry.homepage) != "" ] diff --git a/src/saim/shared/data_con/culture.py b/src/saim/shared/data_con/culture.py index 364164e..ddac4fb 100644 --- a/src/saim/shared/data_con/culture.py +++ b/src/saim/shared/data_con/culture.py @@ -33,7 +33,6 @@ from saim.shared.data_ops.clean import detect_empty_dict_keys from saim.shared.parse.date import check_date_str, date_to_str from saim.taxon_name.manager import TaxonManager -from cafi.container.fun.format import url_to_str _REQ_KEYS: Final[tuple[str, ...]] = ( "acronym", @@ -131,8 +130,7 @@ class CultureCCNo(BaseModel): source: CiDSrc # optional fields - default url: ( - Annotated[HttpUrl, PlainSerializer(lambda val: url_to_str(val), return_type=str)] - | None + Annotated[HttpUrl, PlainSerializer(lambda val: str(val), return_type=str)] | None ) = None cul_id: Annotated[int, Field(ge=1)] | None = Field(default=None, alias="cultureId") history: Annotated[str, AfterValidator(clean_text_rm_tags), Field(min_length=2)] = "" diff --git a/uv.lock b/uv.lock index f0a8f03..0e08c5c 100644 --- a/uv.lock +++ b/uv.lock @@ -120,8 +120,8 @@ wheels = [ [[package]] name = "cafi" -version = "0.9.13" -source = { git = "https://github.com/LeibnizDSMZ/cafi.git?rev=v0.9.13#72a82fe8adce0b3ac4e9ced363550541692cf500" } +version = "0.9.14" +source = { git = "https://github.com/LeibnizDSMZ/cafi.git?rev=v0.9.14#e90398f246bba7539af28bfaaeca0dcbd54c206c" } dependencies = [ { name = "pydantic" }, { name = "requests" }, @@ -1348,7 +1348,7 @@ test = [ [package.metadata] requires-dist = [ - { name = "cafi", git = "https://github.com/LeibnizDSMZ/cafi.git?rev=v0.9.13" }, + { name = "cafi", git = "https://github.com/LeibnizDSMZ/cafi.git?rev=v0.9.14" }, { name = "playwright", specifier = "==1.56.0" }, { name = "pydantic", specifier = "==2.12.5" }, { name = "python-dateutil", specifier = "==2.9.0.post0" }, @@ -1498,11 +1498,11 @@ wheels = [ [[package]] name = "urllib3" -version = "2.6.0" +version = "2.6.1" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/1c/43/554c2569b62f49350597348fc3ac70f786e3c32e7f19d266e19817812dd3/urllib3-2.6.0.tar.gz", hash = "sha256:cb9bcef5a4b345d5da5d145dc3e30834f58e8018828cbc724d30b4cb7d4d49f1", size = 432585, upload-time = "2025-12-05T15:08:47.885Z" } +sdist = { url = "https://files.pythonhosted.org/packages/5e/1d/0f3a93cca1ac5e8287842ed4eebbd0f7a991315089b1a0b01c7788aa7b63/urllib3-2.6.1.tar.gz", hash = "sha256:5379eb6e1aba4088bae84f8242960017ec8d8e3decf30480b3a1abdaa9671a3f", size = 432678, upload-time = "2025-12-08T15:25:26.773Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/56/1a/9ffe814d317c5224166b23e7c47f606d6e473712a2fad0f704ea9b99f246/urllib3-2.6.0-py3-none-any.whl", hash = "sha256:c90f7a39f716c572c4e3e58509581ebd83f9b59cced005b7db7ad2d22b0db99f", size = 131083, upload-time = "2025-12-05T15:08:45.983Z" }, + { url = "https://files.pythonhosted.org/packages/bc/56/190ceb8cb10511b730b564fb1e0293fa468363dbad26145c34928a60cb0c/urllib3-2.6.1-py3-none-any.whl", hash = "sha256:e67d06fe947c36a7ca39f4994b08d73922d40e6cca949907be05efa6fd75110b", size = 131138, upload-time = "2025-12-08T15:25:25.51Z" }, ] [[package]] From 088e0e681db95020f8eb6f9e06d66170ffffd2c8 Mon Sep 17 00:00:00 2001 From: artdotlis Date: Wed, 10 Dec 2025 09:51:25 +0000 Subject: [PATCH 2/2] bump: release 0.9.27 --- CHANGELOG.md | 6 ++++++ README.md | 2 +- pyproject.toml | 2 +- src/saim/shared/misc/constants.py | 2 +- uv.lock | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e4b1e3..a63f665 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.9.27 (2025-12-10) + +### Refactor + +- **link**: add URL validation for link status and result + ## v0.9.26 (2025-12-09) ### Refactor diff --git a/README.md b/README.md index 4055c67..fbcfffb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Strain Authentication and Identification Methods - saim -[![release: 0.9.26](https://img.shields.io/badge/rel-0.9.26-blue.svg?style=flat-square)](https://github.com/LeibnizDSMZ/saim.git) +[![release: 0.9.27](https://img.shields.io/badge/rel-0.9.27-blue.svg?style=flat-square)](https://github.com/LeibnizDSMZ/saim.git) [![MIT LICENSE](https://img.shields.io/badge/License-MIT-brightgreen.svg?style=flat-square)](https://choosealicense.com/licenses/mit/) [![Documentation Status](https://img.shields.io/badge/docs-GitHub-blue.svg?style=flat-square)](https://LeibnizDSMZ.github.io/saim/) diff --git a/pyproject.toml b/pyproject.toml index 5591beb..0bde9c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "saim" -version = "0.9.26" +version = "0.9.27" description = """A library for identifying strains.""" readme = "README.md" authors = [ diff --git a/src/saim/shared/misc/constants.py b/src/saim/shared/misc/constants.py index 3c91565..a815db2 100644 --- a/src/saim/shared/misc/constants.py +++ b/src/saim/shared/misc/constants.py @@ -2,4 +2,4 @@ ENCODING: Final[str] = "utf-8" -VERSION: Final[str] = "v0.9.26" +VERSION: Final[str] = "v0.9.27" diff --git a/uv.lock b/uv.lock index 0e08c5c..edf6851 100644 --- a/uv.lock +++ b/uv.lock @@ -1308,7 +1308,7 @@ wheels = [ [[package]] name = "saim" -version = "0.9.26" +version = "0.9.27" source = { editable = "." } dependencies = [ { name = "cafi" },