From c86efb32e68b8da97a5a3448d0fd9faa52bcd34f Mon Sep 17 00:00:00 2001 From: Norman Fomferra Date: Thu, 13 Feb 2025 08:55:16 +0100 Subject: [PATCH 1/2] Preparing release of v0.5 --- CHANGES.md | 2 +- docs/rule-ref.md | 50 +++++++++++++--------- mkruleref.py | 2 +- xrlint/plugins/core/rules/grid_mappings.py | 4 ++ xrlint/version.py | 2 +- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e571bcf..b93ba02 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # XRLint Change History -## Version 0.5.0 (in development) +## Version 0.5.0 (from 2025-02-13) ### Adjustments and Enhancements diff --git a/docs/rule-ref.md b/docs/rule-ref.md index d009080..f020fff 100644 --- a/docs/rule-ref.md +++ b/docs/rule-ref.md @@ -20,7 +20,7 @@ A dataset should provide information about where the data came from and what has - `no_vars`: do not check variables at all. Defaults to `False`. - `ignored_vars`: list of ignored variables (regex patterns). Defaults to `['crs', 'spatial_ref']`. -[:material-information-variant:](https://cfconventions.org/cf-conventions/cf-conventions.html#description-of-file-contents) +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#description-of-file-contents) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: @@ -28,7 +28,7 @@ Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: Datasets should identify the applicable conventions using the `Conventions` attribute. The rule has an optional configuration parameter `match` which is a regex pattern that the value of the `Conventions` attribute must match, if any. If not provided, the rule just verifies that the attribute exists and whether it is a character string. -[:material-information-variant:](https://cfconventions.org/cf-conventions/cf-conventions.html#identification-of-conventions) +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#identification-of-conventions) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: @@ -41,20 +41,21 @@ Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning ### :material-bug: `grid-mappings` Grid mappings, if any, shall have valid grid mapping coordinate variables. +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#grid-mappings-and-projections) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-bug: `lat-coordinate` Latitude coordinate should have standard units and standard names. -[:material-information-variant:](https://cfconventions.org/cf-conventions/cf-conventions.html#latitude-coordinate) +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#latitude-coordinate) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-bug: `lon-coordinate` Longitude coordinate should have standard units and standard names. -[:material-information-variant:](https://cfconventions.org/cf-conventions/cf-conventions.html#longitude-coordinate) +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#longitude-coordinate) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: @@ -67,35 +68,42 @@ Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: ### :material-lightbulb: `no-empty-chunks` Empty chunks should not be encoded and written. The rule currently applies to Zarr format only. -[:material-information-variant:](https://docs.xarray.dev/en/stable/generated/xarray.Dataset.to_zarr.html#xarray-dataset-to-zarr) +[More...](https://docs.xarray.dev/en/stable/generated/xarray.Dataset.to_zarr.html#xarray-dataset-to-zarr) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-circle-off-outline: ### :material-bug: `time-coordinate` Time coordinates should have valid and unambiguous time units encoding. -[:material-information-variant:](https://cfconventions.org/cf-conventions/cf-conventions.html#time-coordinate) +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#time-coordinate) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-lightbulb: `var-desc` Check that each data variable provides an identification and description of the content. The rule can be configured by parameter `attrs` which is a list of names of attributes that provides descriptive information. It defaults to `['standard_name', 'long_name']`. -[:material-information-variant:](https://cfconventions.org/cf-conventions/cf-conventions.html#standard-name) +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#standard-name) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: ### :material-lightbulb: `var-flags` Validate attributes 'flag_values', 'flag_masks' and 'flag_meanings' that make variables that contain flag values self describing. -[:material-information-variant:](https://cfconventions.org/cf-conventions/cf-conventions.html#flags) +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#flags) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: +### :material-lightbulb: `var-missing-data` + +Checks the recommended use of missing data, i.e., coordinate variables should not define missing data, but packed data should. Notifies about the use of valid ranges to indicate missing data, which is currently not supported by xarray. +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#units) + +Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: + ### :material-lightbulb: `var-units` Every variable should provide a description of its units. -[:material-information-variant:](https://cfconventions.org/cf-conventions/cf-conventions.html#units) +[More...](https://cfconventions.org/cf-conventions/cf-conventions.html#units) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: @@ -104,70 +112,70 @@ Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: ### :material-bug: `any-spatial-data-var` A datacube should have spatial data variables. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/cubespec.html#data-model-and-format) +[More...](https://xcube.readthedocs.io/en/latest/cubespec.html#data-model-and-format) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-bug: `cube-dims-order` Order of dimensions in spatio-temporal datacube variables should be [time, ..., y, x]. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/cubespec.html#data-model-and-format) +[More...](https://xcube.readthedocs.io/en/latest/cubespec.html#data-model-and-format) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-lightbulb: `data-var-colors` Spatial data variables should encode xcube color mappings in their metadata. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/cubespec.html#encoding-of-colors) +[More...](https://xcube.readthedocs.io/en/latest/cubespec.html#encoding-of-colors) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: ### :material-bug: `dataset-title` Datasets should be given a non-empty title. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/cubespec.html#metadata) +[More...](https://xcube.readthedocs.io/en/latest/cubespec.html#metadata) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-lightbulb: `grid-mapping-naming` Grid mapping variables should be called 'spatial_ref' or 'crs' for compatibility with rioxarray and other packages. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/cubespec.html#spatial-reference) +[More...](https://xcube.readthedocs.io/en/latest/cubespec.html#spatial-reference) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: ### :material-bug: `increasing-time` Time coordinate labels should be monotonically increasing. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/cubespec.html#temporal-reference) +[More...](https://xcube.readthedocs.io/en/latest/cubespec.html#temporal-reference) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-bug: `lat-lon-naming` Latitude and longitude coordinates and dimensions should be called 'lat' and 'lon'. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/cubespec.html#spatial-reference) +[More...](https://xcube.readthedocs.io/en/latest/cubespec.html#spatial-reference) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-lightbulb: `ml-dataset-meta` Multi-level datasets should provide a '.zlevels' meta-info file, and if so, it should be consistent. Without the meta-info file the multi-level dataset cannot be reliably extended by new time slices as the aggregation method used for each variable must be specified. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/mldatasets.html#the-xcube-levels-format) +[More...](https://xcube.readthedocs.io/en/latest/mldatasets.html#the-xcube-levels-format) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-bug: `ml-dataset-time` The `time` dimension of multi-level datasets should use a chunk size of 1. This allows for faster image tile generation for visualisation. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/mldatasets.html#definition) +[More...](https://xcube.readthedocs.io/en/latest/mldatasets.html#definition) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: ### :material-bug: `ml-dataset-xy` Multi-level dataset levels should provide spatial resolutions decreasing by powers of two. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/mldatasets.html#definition) +[More...](https://xcube.readthedocs.io/en/latest/mldatasets.html#definition) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: @@ -180,14 +188,14 @@ Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert: ### :material-bug: `single-grid-mapping` A single grid mapping shall be used for all spatial data variables of a datacube. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/cubespec.html#spatial-reference) +[More...](https://xcube.readthedocs.io/en/latest/cubespec.html#spatial-reference) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: ### :material-bug: `time-naming` Time coordinate and dimension should be called 'time'. -[:material-information-variant:](https://xcube.readthedocs.io/en/latest/cubespec.html#temporal-reference) +[More...](https://xcube.readthedocs.io/en/latest/cubespec.html#temporal-reference) Contained in: `all`-:material-lightning-bolt: `recommended`-:material-lightning-bolt: diff --git a/mkruleref.py b/mkruleref.py index 4b5a36c..46ee77b 100644 --- a/mkruleref.py +++ b/mkruleref.py @@ -52,7 +52,7 @@ def write_plugin_rules(stream, plugin: Plugin): ) stream.write(rule_meta.description or "_No description._") if rule_meta.docs_url: - stream.write("\n" + f"[:{read_more_icon}:]({rule_meta.docs_url})") + stream.write(f"\n[More...]({rule_meta.docs_url})") stream.write("\n\n") # List the predefined configurations that contain the rule stream.write("Contained in: ") diff --git a/xrlint/plugins/core/rules/grid_mappings.py b/xrlint/plugins/core/rules/grid_mappings.py index dfdc355..bd8aa97 100644 --- a/xrlint/plugins/core/rules/grid_mappings.py +++ b/xrlint/plugins/core/rules/grid_mappings.py @@ -14,6 +14,10 @@ description=( "Grid mappings, if any, shall have valid grid mapping coordinate variables." ), + docs_url=( + "https://cfconventions.org/cf-conventions/cf-conventions.html" + "#grid-mappings-and-projections" + ), ) class GridMappings(RuleOp): def validate_dataset(self, ctx: RuleContext, node: DatasetNode): diff --git a/xrlint/version.py b/xrlint/version.py index 8fecd05..1b59e11 100644 --- a/xrlint/version.py +++ b/xrlint/version.py @@ -2,4 +2,4 @@ # This software is distributed under the terms and conditions of the # MIT license (https://mit-license.org/). -version = "0.5.0.dev0" +version = "0.5.0" From bf1c6b8d5257197d9c4663613ba5fe48d7dd96bb Mon Sep 17 00:00:00 2001 From: Norman Fomferra Date: Thu, 13 Feb 2025 09:05:48 +0100 Subject: [PATCH 2/2] Formatting --- environment.yml | 1 + pyproject.toml | 1 + tests/test_linter.py | 2 +- xrlint/_linter/apply.py | 2 +- xrlint/formatters/html.py | 5 +---- xrlint/formatters/simple.py | 5 +---- xrlint/result.py | 4 ++-- xrlint/rule.py | 2 +- 8 files changed, 9 insertions(+), 13 deletions(-) diff --git a/environment.yml b/environment.yml index 8a3767d..b39d4b4 100644 --- a/environment.yml +++ b/environment.yml @@ -10,6 +10,7 @@ dependencies: - tabulate - xarray # Dev Dependencies + - isort - mkdocs - mkdocs-autorefs - mkdocs-material diff --git a/pyproject.toml b/pyproject.toml index c9d25c6..daca338 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,6 +68,7 @@ dev = [ # Development tools "build", "hatch", + "isort", "pytest", "pytest-cov", "ruff", diff --git a/tests/test_linter.py b/tests/test_linter.py index 4042d8a..c8d650c 100644 --- a/tests/test_linter.py +++ b/tests/test_linter.py @@ -10,7 +10,7 @@ from xrlint.config import Config, ConfigObject from xrlint.constants import CORE_PLUGIN_NAME, DATASET_ROOT_NAME from xrlint.linter import Linter, new_linter -from xrlint.node import AttrNode, AttrsNode, DatasetNode, VariableNode, DataTreeNode +from xrlint.node import AttrNode, AttrsNode, DatasetNode, DataTreeNode, VariableNode from xrlint.plugin import new_plugin from xrlint.processor import ProcessorOp from xrlint.result import Message, Result diff --git a/xrlint/_linter/apply.py b/xrlint/_linter/apply.py index 8ffda67..8544717 100644 --- a/xrlint/_linter/apply.py +++ b/xrlint/_linter/apply.py @@ -2,7 +2,7 @@ # This software is distributed under the terms and conditions of the # MIT license (https://mit-license.org/). -from xrlint.node import AttrNode, AttrsNode, DataTreeNode, DatasetNode, VariableNode +from xrlint.node import AttrNode, AttrsNode, DatasetNode, DataTreeNode, VariableNode from xrlint.rule import RuleConfig, RuleExit, RuleOp from ..constants import DATASET_ROOT_NAME, DATATREE_ROOT_NAME diff --git a/xrlint/formatters/html.py b/xrlint/formatters/html.py index bec1788..aaec003 100644 --- a/xrlint/formatters/html.py +++ b/xrlint/formatters/html.py @@ -5,10 +5,7 @@ import html from collections.abc import Iterable -from xrlint.constants import ( - SEVERITY_CODE_TO_COLOR, - SEVERITY_CODE_TO_NAME, -) +from xrlint.constants import SEVERITY_CODE_TO_COLOR, SEVERITY_CODE_TO_NAME from xrlint.formatter import FormatterContext, FormatterOp from xrlint.formatters import registry from xrlint.result import Message, Result, get_rules_meta_for_results diff --git a/xrlint/formatters/simple.py b/xrlint/formatters/simple.py index 5661d44..5516e1e 100644 --- a/xrlint/formatters/simple.py +++ b/xrlint/formatters/simple.py @@ -6,10 +6,7 @@ from tabulate import tabulate -from xrlint.constants import ( - SEVERITY_CODE_TO_COLOR, - SEVERITY_CODE_TO_NAME, -) +from xrlint.constants import SEVERITY_CODE_TO_COLOR, SEVERITY_CODE_TO_NAME from xrlint.formatter import FormatterContext, FormatterOp from xrlint.formatters import registry from xrlint.result import Message, Result diff --git a/xrlint/result.py b/xrlint/result.py index 2138398..027ce72 100644 --- a/xrlint/result.py +++ b/xrlint/result.py @@ -113,8 +113,8 @@ def warning_count(self) -> int: @cached_property def error_count(self) -> int: """The number of errors. This includes fixable errors - and fatal errors. - """ + and fatal errors. + """ return sum(1 if m.severity == SEVERITY_ERROR else 0 for m in self.messages) @cached_property diff --git a/xrlint/rule.py b/xrlint/rule.py index 5317c5e..6b53cc3 100644 --- a/xrlint/rule.py +++ b/xrlint/rule.py @@ -10,7 +10,7 @@ import xarray as xr from xrlint.constants import SEVERITY_ENUM, SEVERITY_ENUM_TEXT -from xrlint.node import AttrNode, AttrsNode, DataTreeNode, DatasetNode, VariableNode +from xrlint.node import AttrNode, AttrsNode, DatasetNode, DataTreeNode, VariableNode from xrlint.operation import Operation, OperationMeta from xrlint.result import Suggestion from xrlint.util.constructible import ValueConstructible