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
7 changes: 2 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ jobs:
python -m pip install --upgrade pip
pip install .[dev,doc]

- name: Lint with flake8
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
ruff check

- name: Run unit tests
shell: bash -l {0}
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install .[dev,doc]
- name: Lint with flake8
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
ruff check
- name: Test with pytest
run: |
pytest --cov=xrlint --cov-branch --cov-report=xml
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

- Improved overall test coverage.

- Switched to [ruff](https://docs.astral.sh/ruff/)
as default linter and formatter.


## Version 0.2.0 (14.01.2025)

Expand Down
21 changes: 12 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ checklist are addressed in your PR.

**PR checklist**

* Format code using [black](https://black.readthedocs.io/) with default settings.
Check also section [code style](#code-style) below.
* Format and check code using [ruff](https://docs.astral.sh/ruff/) with
default settings: `ruff format` and `ruff check`. See also section
[code style](#code-style) below.
* Your change shall not break existing unit tests.
`pytest` must run without errors.
* Add unit tests for any new code not yet covered by tests.
Expand All @@ -33,16 +34,18 @@ checklist are addressed in your PR.

## Code style

The XRLint code complies to [PEP-8](https://pep8.org/) except for a line
length of 88 characters as recommended by [black](https://black.readthedocs.io/).
Since black is un-opinionated regarding the order of imports,
we use the following three import blocks separated by an empty
line:
The code style of XRLint equals the default settings
of [black](https://black.readthedocs.io/). Since black is
un-opinionated regarding the order of imports, we group and
sort imports statements according to the default settings of
[isort](https://pycqa.github.io/isort/) which boils down to

0. Future imports
1. Python standard library imports, e.g., `os`, `typing`, etc
2. 3rd-party imports, e.g., `xarray`, `zarr`, etc
3. XRLint module imports:
Prefer absolute import paths: `from xrlint.a.b.c import d`.
3. 1st-party XRLint module imports using absolute paths,
e.g., `from xrlint.a.b.c import d`.
4. 1st-party XRLint module imports from local modules:
Relative imports such as `from .c import d` are ok
while `..c import d` are not ok.

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[![CI](https://github.com/bcdev/xrlint/actions/workflows/tests.yml/badge.svg)](https://github.com/bcdev/xrlint/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/bcdev/xrlint/graph/badge.svg?token=GVKuJao97t)](https://codecov.io/gh/bcdev/xrlint)
[![PyPI Version](https://img.shields.io/pypi/v/xrlint)](https://pypi.org/project/xrlint/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![GitHub License](https://img.shields.io/github/license/bcdev/xrlint)](https://github.com/bcdev/xrlint)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v0.json)](https://github.com/charliermarsh/ruff)[![GitHub License](https://img.shields.io/github/license/bcdev/xrlint)](https://github.com/bcdev/xrlint)

# XRLint - A linter for xarray datasets

Expand Down
8 changes: 4 additions & 4 deletions docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ pytest --cov=xrlint --cov-report html

### Code Style

XRLint source code is formatted using the [black](https://black.readthedocs.io/) tool and
quality-controlled using [flake8](https://flake8.pycqa.org/).
XRLint source code is formatted and quality-controlled using
using [ruff](https://docs.astral.sh/ruff/):

```bash
black .
flake8 --max-line-length=88 .
ruff format
ruff check
```

### Documentation
Expand Down
3 changes: 1 addition & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ dependencies:
- tabulate
- xarray
# Dev Dependencies
- black
- flake8
- mkdocs
- mkdocs-autorefs
- mkdocs-material
Expand All @@ -20,6 +18,7 @@ dependencies:
- pytest
- pytest-cov
- requests-mock
- ruff
# Testing Datasets
- pandas
- netcdf4
Expand Down
4 changes: 1 addition & 3 deletions examples/plugin_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from xrlint.config import Config
from xrlint.node import DatasetNode
from xrlint.plugin import new_plugin
from xrlint.rule import RuleContext
from xrlint.rule import RuleOp

from xrlint.rule import RuleContext, RuleOp

plugin = new_plugin(
name="hello-plugin",
Expand Down
7 changes: 2 additions & 5 deletions examples/rule_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import xarray as xr

from xrlint.node import DatasetNode
from xrlint.rule import RuleContext
from xrlint.rule import RuleOp
from xrlint.rule import define_rule
from xrlint.testing import RuleTest
from xrlint.testing import RuleTester
from xrlint.rule import RuleContext, RuleOp, define_rule
from xrlint.testing import RuleTest, RuleTester


@define_rule("good-title")
Expand Down
4 changes: 1 addition & 3 deletions examples/virtual_plugin_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"""

from xrlint.node import DatasetNode
from xrlint.rule import RuleContext
from xrlint.rule import RuleOp
from xrlint.rule import define_rule
from xrlint.rule import RuleContext, RuleOp, define_rule


@define_rule("good-title", description="Dataset title should be 'Hello World!'.")
Expand Down
51 changes: 28 additions & 23 deletions notebooks/xrlint-cli.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {},
"outputs": [
{
Expand All @@ -22,15 +22,19 @@
"\n",
" Validate the given dataset FILES.\n",
"\n",
" Reads configuration from `./xrlint_config.*` if such file exists and unless\n",
" `--no_config_lookup` is set or `--config` is provided. Then validates each\n",
" dataset in FILES against the configuration. The default dataset patters are\n",
" `**/*.zarr` and `**/.nc`. FILES may comprise also directories. If a\n",
" directory is not matched by any file pattern, it will be traversed\n",
" recursively. The validation result is dumped to standard output if not\n",
" otherwise stated by `--output-file`. The output format is `simple` by\n",
" default. Other inbuilt formats are `json` and `html` which you can specify\n",
" using the `--format` option.\n",
" Reads configuration from './xrlint_config.*' if such file exists and unless\n",
" '--no_config_lookup' is set or '--config' is provided. It then validates\n",
" each dataset in FILES against the configuration. The default dataset patters\n",
" are '**/*.zarr' and '**/.nc'. FILES may comprise also directories or URLs.\n",
" The supported URL protocols are the ones supported by xarray. Using remote\n",
" protocols may require installing additional packages such as S3Fs\n",
" (https://s3fs.readthedocs.io/) for the 's3' protocol.\n",
"\n",
" If a directory is provided that not matched by any file pattern, it will be\n",
" traversed recursively. The validation result is dumped to standard output if\n",
" not otherwise stated by '--output-file'. The output format is 'simple' by\n",
" default. Other inbuilt formats are 'json' and 'html' which you can specify\n",
" using the '--format' option.\n",
"\n",
"Options:\n",
" --no-config-lookup Disable use of default configuration from\n",
Expand Down Expand Up @@ -59,7 +63,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -68,26 +72,27 @@
"'C:\\\\Users\\\\norma\\\\Projects\\\\xrlint\\\\notebooks'"
]
},
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os\n",
"\n",
"os.getcwd()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"name": "stdout",
"output_type": "stream",
"text": [
"Error: file xrlint_config.yaml already exists.\n"
"Configuration template written to xrlint_config.yaml\n"
]
}
],
Expand All @@ -97,16 +102,16 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<xarray.backends.zarr.ZarrStore at 0x2b09f4c3010>"
"<xarray.backends.zarr.ZarrStore at 0x14b37ccb400>"
]
},
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -120,7 +125,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -146,7 +151,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -180,7 +185,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -190,7 +195,7 @@
"{\n",
" \"name\": \"<computed>\",\n",
" \"plugins\": {\n",
" \"__core__\": \"xrlint.plugins.core\"\n",
" \"__core__\": \"xrlint.plugins.core:export_plugin\"\n",
" },\n",
" \"rules\": {\n",
" \"coords-for-dims\": 2,\n",
Expand Down Expand Up @@ -231,7 +236,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
"version": "3.13.1"
}
},
"nbformat": 4,
Expand Down
Loading
Loading