Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# xrlint
/xrlint_config.*
/notebooks/xrlint_config.*

# Logs
*.log
Expand Down
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

## Version 0.1.0 (in development)

- Added CLI option `--print-config PATH`, see same option in ESLint
- XRLint CLI now outputs single results immediately to console,
instead only after all results have been collected.

- Refactored and renamed `CliEngine` into `XRLint`. Documented the class.
- `new_linter()` now uses a config name arg instead of a bool arg.
- Split example notebook into two

## Early development snapshots

Expand Down
4 changes: 4 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All described objects can be imported from the `xrlint.all` module.

## Class `XRLint`

::: xrlint.cli.engine.XRLint

## Function `new_linter()`

::: xrlint.linter.new_linter
Expand Down
23 changes: 14 additions & 9 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,33 @@ Usage: xrlint [OPTIONS] [FILES]...

Validate the given dataset FILES.

Reads configuration from `xrlint.config.*` if file exists and unless `--no-
default-config` is set or `--config PATH` is provided. Then validates each
dataset in FILES against the configuration. The validation result is dumped
to standard output if not otherwise stated by `--output-file PATH`. The
output format is `simple`. Other inbuilt formats are `json` and `html` which
can by setting the `--format NAME` option.
Reads configuration from `./xrlint_config.*` if such file exists and unless
`--no_config_lookup` is set or `--config` is provided. Then validates each
dataset in FILES against the configuration. The default dataset patters are
`**/*.zarr` and `**/.nc`. FILES may comprise also directories. If a
directory is not matched by any file pattern, it will be traversed
recursively. The validation result is dumped to standard output if not
otherwise stated by `--output-file`. The output format is `simple` by
default. Other inbuilt formats are `json` and `html` which you can specify
using the `--format` option.

Options:
--no-default-config Disable use of default configuration from
--no-config-lookup Disable use of default configuration from
xrlint_config.*
-c, --config PATH Use this configuration, overriding xrlint_config.*
-c, --config FILE Use this configuration, overriding xrlint_config.*
config options if present
--print-config FILE Print the configuration for the given file
--plugin MODULE Specify plugins. MODULE is the name of Python module
that defines an 'export_plugin()' function.
--rule SPEC Specify rules. SPEC must have format '<rule-name>:
<rule-config>' (note the space character).
-o, --output-file PATH Specify file to write report to
-o, --output-file FILE Specify file to write report to
-f, --format NAME Use a specific output format - default: simple
--color / --no-color Force enabling/disabling of color
--max-warnings COUNT Number of warnings to trigger nonzero exit code -
default: 5
--init Write initial configuration file and exit.
--version Show the version and exit.
--help Show this message and exit.

```
2 changes: 1 addition & 1 deletion docs/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ import xrlint.all as xrl

test_ds = xr.Dataset(attrs={"title": "Test Dataset"})

linter = xrl.new_linter(recommended=True)
linter = xrl.new_linter("recommended")
linter.verify_dataset(test_ds)
```
5 changes: 0 additions & 5 deletions docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@
- project logo
- if configuration for given FILE is empty,
report an error, see TODO in CLI main tests
- rename `xrlint.cli.CliEngine` into `xrlint.cli.XRLint`
(with similar API as the `ESLint` class) and export it
from `xrlint.all`. Value of `FILES` should be passed to
`verify_datasets()` methods.
- use `RuleMeta.docs_url` in formatters to create links
- implement xarray backend for xcube 'levels' format
so can validate them too
- add some more tests so we reach 99% coverage
- support rule op args/kwargs schema validation
- support CLI option `--print-config FILE`, see ESLint
- Support `RuleTest.expected`, it is currently unused

## Nice to have
Expand Down
64 changes: 64 additions & 0 deletions notebooks/mkdataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import numpy as np
import xarray as xr

nx = 2
ny = 3
nt = 4


def make_dataset() -> xr.Dataset:
"""Create a dataset that passes xrlint core rules."""

return xr.Dataset(
attrs=dict(title="SST-Climatology Subset"),
coords={
"x": xr.DataArray(
np.linspace(-180, 180, nx),
dims="x",
attrs={"units": "degrees"}
),
"y": xr.DataArray(
np.linspace(-90, 90, ny),
dims="y",
attrs={"units": "degrees"}
),
"time": xr.DataArray(
[2010 + y for y in range(nt)],
dims="time",
attrs={"units": "years"}
),
"spatial_ref": xr.DataArray(
0,
attrs={
"grid_mapping_name": "latitude_longitude",
"semi_major_axis": 6371000.0,
"inverse_flattening": 0,
},
),
},
data_vars={
"sst": xr.DataArray(
np.random.random((nt, ny, nx)),
dims=["time", "y", "x"],
attrs={"units": "kelvin", "grid_mapping": "spatial_ref"}
),
"sst_anomaly": xr.DataArray(
np.random.random((nt, ny, nx)),
dims=["time", "y", "x"],
attrs={"units": "kelvin", "grid_mapping": "spatial_ref"}
)
},
)


def make_dataset_with_issues() -> xr.Dataset:
"""Create a dataset that produces issues with xrlint core rules."""
invalid_ds = make_dataset()
invalid_ds.attrs = {}
invalid_ds.sst.attrs["units"] = 1
invalid_ds["sst_avg"] = xr.DataArray(
np.random.random((nx, ny)),
dims=["x", "y"],
attrs={"units": "kelvin"}
)
return invalid_ds
Loading
Loading