diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9e96e46..cb45cfd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,15 +8,15 @@ repos: - id: end-of-file-fixer - id: check-ast - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.9.10 + rev: v0.12.0 hooks: # Run the linter. - - id: ruff + - id: ruff-check args: [ --fix ] # Run the formatter. - id: ruff-format - repo: https://github.com/astral-sh/uv-pre-commit - rev: 0.6.5 + rev: 0.7.14 hooks: # Run the pip compile - id: pip-compile diff --git a/documentation/index.md b/documentation/index.md index 2c27072..5e3d4d6 100755 --- a/documentation/index.md +++ b/documentation/index.md @@ -27,6 +27,7 @@ upload your datasets to HDX. - [Tags](#tags) - [Maintainer](#maintainer) - [Organization](#organization) + - [Custom Visualization](#customviz) - [Resource Generation](#resource-generation) - [QuickCharts Generation](#quickcharts-generation) - [Resource Specific Operations](#resource-specific-operations) @@ -790,7 +791,22 @@ If you want to set the organization, you do it like this: ORGANIZATION is either a string id, dictionary or an Organization object. -### Resource generation +### Custom Visualization + +If you want to add a custom visualization to a dataset, you can do this: + + dataset.set_custom_viz(URL) + +URL is a string containing the url of your visualization. + +You can get any existing visualization like this: + + url = dataset.get_custom_viz() + +The return value is a string if a visualization has been set on the dataset, +otherwise it is None. + +### Resource Generation There are a range of helpful functions to generate resources. In the following examples, RESOURCE DATA takes the form {"name": NAME, "description": diff --git a/hatch.toml b/hatch.toml index 029f1f8..a7a7610 100644 --- a/hatch.toml +++ b/hatch.toml @@ -34,4 +34,4 @@ run = """ [envs.hatch-static-analysis] config-path = "none" -dependencies = ["ruff==0.9.10"] +dependencies = ["ruff==0.12.0"] diff --git a/pyproject.toml b/pyproject.toml index ea9e405..acbc3ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ dependencies = [ "defopt>=7.0.0", "email_validator", "hdx-python-country>=3.9.6", - "hdx-python-utilities>=3.8.8", + "hdx-python-utilities>=3.9.0", "libhxl>=5.2.2", "makefun", "quantulum3", diff --git a/requirements.txt b/requirements.txt index a2799fa..f869c23 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ # uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt annotated-types==0.7.0 # via pydantic -astdoc==1.3.0 +astdoc==1.3.1 # via mkapi attrs==25.3.0 # via @@ -16,7 +16,7 @@ backrefs==5.9 # via mkdocs-material cachetools==5.5.2 # via google-auth -certifi==2025.7.14 +certifi==2025.8.3 # via requests cfgv==3.4.0 # via pre-commit @@ -32,7 +32,7 @@ click==8.2.1 # typer colorama==0.4.6 # via mkdocs-material -coverage==7.9.2 +coverage==7.10.2 # via pytest-cov defopt==7.0.0 # via hdx-python-api (pyproject.toml) @@ -44,7 +44,7 @@ docopt==0.6.2 # via # ckanapi # num2words -docutils==0.21.2 +docutils==0.22 # via defopt email-validator==2.2.0 # via hdx-python-api (pyproject.toml) @@ -66,7 +66,7 @@ gspread==6.2.1 # via hdx-python-api (pyproject.toml) hdx-python-country==3.9.6 # via hdx-python-api (pyproject.toml) -hdx-python-utilities==3.8.8 +hdx-python-utilities==3.9.0 # via # hdx-python-api (pyproject.toml) # hdx-python-country @@ -129,7 +129,7 @@ mergedeep==1.3.4 # via # mkdocs # mkdocs-get-deps -mkapi==4.4.4 +mkapi==4.4.5 # via hdx-python-api (pyproject.toml) mkdocs==1.6.1 # via @@ -137,7 +137,7 @@ mkdocs==1.6.1 # mkdocs-material mkdocs-get-deps==0.2.0 # via mkdocs -mkdocs-material==9.6.15 +mkdocs-material==9.6.16 # via mkapi mkdocs-material-extensions==1.3.1 # via mkdocs-material @@ -192,7 +192,7 @@ pygments==2.19.2 # mkdocs-material # pytest # rich -pymdown-extensions==10.16 +pymdown-extensions==10.16.1 # via mkdocs-material pyphonetics==0.5.3 # via hdx-python-utilities @@ -251,7 +251,7 @@ requests-oauthlib==2.0.0 # via google-auth-oauthlib rfc3986==2.0.0 # via frictionless -rich==14.0.0 +rich==14.1.0 # via typer rpds-py==0.26.0 # via @@ -313,7 +313,7 @@ urllib3==2.5.0 # requests validators==0.35.0 # via frictionless -virtualenv==20.32.0 +virtualenv==20.33.1 # via pre-commit watchdog==6.0.0 # via mkdocs diff --git a/src/hdx/data/dataset.py b/src/hdx/data/dataset.py index 892d9e4..cac3523 100755 --- a/src/hdx/data/dataset.py +++ b/src/hdx/data/dataset.py @@ -2141,6 +2141,28 @@ def remove_filetype(self, filetype: str) -> bool: ) return self._remove_string_from_commastring("file_types", filetype) + def set_custom_viz(self, url: str) -> None: + """Set custom visualization url for dataset + + Args: + url (str): Custom visualization url + + Returns: + None + """ + self.data["customviz"] = [{"url": url}] + + def get_custom_viz(self) -> Optional[str]: + """Get custom visualization url for dataset + + Returns: + Optional[str]: Custom visualization url or None: + """ + viz = self.data.get("customviz") + if not isinstance(viz, list): + return None + return viz[0].get("url") + def preview_off(self) -> None: """Set dataset preview off diff --git a/tests/hdx/data/test_dataset_noncore.py b/tests/hdx/data/test_dataset_noncore.py index 4f08306..3d481ee 100755 --- a/tests/hdx/data/test_dataset_noncore.py +++ b/tests/hdx/data/test_dataset_noncore.py @@ -1010,3 +1010,10 @@ def test_load_save_to_json(self, vocabulary_read): save_text("null", path) dataset = Dataset.load_from_json(path) assert dataset is None + + def test_custom_viz(self): + dataset = Dataset({"name": "lala", "title": "title", "notes": "description"}) + url = "http://lala" + dataset.set_custom_viz(url) + assert dataset.get_custom_viz() == url + assert dataset["customviz"] == [{"url": "http://lala"}]