|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "## XRLint CLI\n", |
| 8 | + "\n", |
| 9 | + "---" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": 4, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [ |
| 17 | + { |
| 18 | + "name": "stdout", |
| 19 | + "output_type": "stream", |
| 20 | + "text": [ |
| 21 | + "Usage: xrlint [OPTIONS] [FILES]...\n", |
| 22 | + "\n", |
| 23 | + " Validate the given dataset FILES.\n", |
| 24 | + "\n", |
| 25 | + " Reads configuration from `./xrlint_config.*` if such file exists and unless\n", |
| 26 | + " `--no_config_lookup` is set or `--config` is provided. Then validates each\n", |
| 27 | + " dataset in FILES against the configuration. The default dataset patters are\n", |
| 28 | + " `**/*.zarr` and `**/.nc`. FILES may comprise also directories. If a\n", |
| 29 | + " directory is not matched by any file pattern, it will be traversed\n", |
| 30 | + " recursively. The validation result is dumped to standard output if not\n", |
| 31 | + " otherwise stated by `--output-file`. The output format is `simple` by\n", |
| 32 | + " default. Other inbuilt formats are `json` and `html` which you can specify\n", |
| 33 | + " using the `--format` option.\n", |
| 34 | + "\n", |
| 35 | + "Options:\n", |
| 36 | + " --no-config-lookup Disable use of default configuration from\n", |
| 37 | + " xrlint_config.*\n", |
| 38 | + " -c, --config FILE Use this configuration, overriding xrlint_config.*\n", |
| 39 | + " config options if present\n", |
| 40 | + " --print-config FILE Print the configuration for the given file\n", |
| 41 | + " --plugin MODULE Specify plugins. MODULE is the name of Python module\n", |
| 42 | + " that defines an 'export_plugin()' function.\n", |
| 43 | + " --rule SPEC Specify rules. SPEC must have format '<rule-name>:\n", |
| 44 | + " <rule-config>' (note the space character).\n", |
| 45 | + " -o, --output-file FILE Specify file to write report to\n", |
| 46 | + " -f, --format NAME Use a specific output format - default: simple\n", |
| 47 | + " --color / --no-color Force enabling/disabling of color\n", |
| 48 | + " --max-warnings COUNT Number of warnings to trigger nonzero exit code -\n", |
| 49 | + " default: 5\n", |
| 50 | + " --init Write initial configuration file and exit.\n", |
| 51 | + " --version Show the version and exit.\n", |
| 52 | + " --help Show this message and exit.\n" |
| 53 | + ] |
| 54 | + } |
| 55 | + ], |
| 56 | + "source": [ |
| 57 | + "!xrlint --help" |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "code", |
| 62 | + "execution_count": 5, |
| 63 | + "metadata": {}, |
| 64 | + "outputs": [ |
| 65 | + { |
| 66 | + "data": { |
| 67 | + "text/plain": [ |
| 68 | + "'C:\\\\Users\\\\norma\\\\Projects\\\\xrlint\\\\notebooks'" |
| 69 | + ] |
| 70 | + }, |
| 71 | + "execution_count": 5, |
| 72 | + "metadata": {}, |
| 73 | + "output_type": "execute_result" |
| 74 | + } |
| 75 | + ], |
| 76 | + "source": [ |
| 77 | + "import os\n", |
| 78 | + "os.getcwd()" |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + "cell_type": "code", |
| 83 | + "execution_count": 6, |
| 84 | + "metadata": {}, |
| 85 | + "outputs": [ |
| 86 | + { |
| 87 | + "name": "stderr", |
| 88 | + "output_type": "stream", |
| 89 | + "text": [ |
| 90 | + "Error: file xrlint_config.yaml already exists.\n" |
| 91 | + ] |
| 92 | + } |
| 93 | + ], |
| 94 | + "source": [ |
| 95 | + "!xrlint --init" |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + "cell_type": "code", |
| 100 | + "execution_count": 7, |
| 101 | + "metadata": {}, |
| 102 | + "outputs": [ |
| 103 | + { |
| 104 | + "data": { |
| 105 | + "text/plain": [ |
| 106 | + "<xarray.backends.zarr.ZarrStore at 0x2b09f4c3010>" |
| 107 | + ] |
| 108 | + }, |
| 109 | + "execution_count": 7, |
| 110 | + "metadata": {}, |
| 111 | + "output_type": "execute_result" |
| 112 | + } |
| 113 | + ], |
| 114 | + "source": [ |
| 115 | + "from mkdataset import make_dataset, make_dataset_with_issues\n", |
| 116 | + "\n", |
| 117 | + "make_dataset().to_zarr(\"valid.zarr\", mode=\"w\")\n", |
| 118 | + "make_dataset_with_issues().to_zarr(\"invalid.zarr\", mode=\"w\")" |
| 119 | + ] |
| 120 | + }, |
| 121 | + { |
| 122 | + "cell_type": "code", |
| 123 | + "execution_count": 8, |
| 124 | + "metadata": {}, |
| 125 | + "outputs": [ |
| 126 | + { |
| 127 | + "name": "stdout", |
| 128 | + "output_type": "stream", |
| 129 | + "text": [ |
| 130 | + "\n", |
| 131 | + "valid.zarr - ok\n", |
| 132 | + "\n", |
| 133 | + "invalid.zarr:\n", |
| 134 | + "dataset warn Missing 'title' attribute in dataset. dataset-title-attr\n", |
| 135 | + "dataset.attrs warn Missing metadata, attributes are empty. no-empty-attrs\n", |
| 136 | + "dataset.data_vars['sst'] warn Invalid 'units' attribute in variable 'sst'. var-units-attr\n", |
| 137 | + "\n", |
| 138 | + "3 warnings\n", |
| 139 | + "\n" |
| 140 | + ] |
| 141 | + } |
| 142 | + ], |
| 143 | + "source": [ |
| 144 | + "!xrlint --no-color valid.zarr invalid.zarr" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": 39, |
| 150 | + "metadata": {}, |
| 151 | + "outputs": [ |
| 152 | + { |
| 153 | + "name": "stdout", |
| 154 | + "output_type": "stream", |
| 155 | + "text": [ |
| 156 | + "<div role=\"results\">\n", |
| 157 | + "<h3>Results</h3>\n", |
| 158 | + "<div role=\"result\">\n", |
| 159 | + "<p role=\"file\">valid.zarr - ok</p>\n", |
| 160 | + "</div>\n", |
| 161 | + "<hr/>\n", |
| 162 | + "<div role=\"result\">\n", |
| 163 | + "<p role=\"file\">invalid.zarr:</p>\n", |
| 164 | + "<table>\n", |
| 165 | + "<tbody>\n", |
| 166 | + "<tr><td>dataset </td><td>warn</td><td>Missing 'title' attribute in dataset. </td><td>dataset-title-attr</td></tr>\n", |
| 167 | + "<tr><td>dataset.attrs </td><td>warn</td><td>Missing metadata, attributes are empty. </td><td>no-empty-attrs </td></tr>\n", |
| 168 | + "<tr><td>dataset.data_vars['sst']</td><td>warn</td><td>Invalid 'units' attribute in variable 'sst'.</td><td>var-units-attr </td></tr>\n", |
| 169 | + "</tbody>\n", |
| 170 | + "</table><p role=\"summary\">3 warnings</p>\n", |
| 171 | + "</div>\n", |
| 172 | + "</div>\n", |
| 173 | + "\n" |
| 174 | + ] |
| 175 | + } |
| 176 | + ], |
| 177 | + "source": [ |
| 178 | + "!xrlint valid.zarr invalid.zarr -f html" |
| 179 | + ] |
| 180 | + }, |
| 181 | + { |
| 182 | + "cell_type": "code", |
| 183 | + "execution_count": 9, |
| 184 | + "metadata": {}, |
| 185 | + "outputs": [ |
| 186 | + { |
| 187 | + "name": "stdout", |
| 188 | + "output_type": "stream", |
| 189 | + "text": [ |
| 190 | + "{\n", |
| 191 | + " \"name\": \"<computed>\",\n", |
| 192 | + " \"plugins\": {\n", |
| 193 | + " \"__core__\": \"xrlint.plugins.core\"\n", |
| 194 | + " },\n", |
| 195 | + " \"rules\": {\n", |
| 196 | + " \"coords-for-dims\": 2,\n", |
| 197 | + " \"dataset-title-attr\": 1,\n", |
| 198 | + " \"grid-mappings\": 2,\n", |
| 199 | + " \"no-empty-attrs\": 1,\n", |
| 200 | + " \"var-units-attr\": 1\n", |
| 201 | + " }\n", |
| 202 | + "}\n" |
| 203 | + ] |
| 204 | + } |
| 205 | + ], |
| 206 | + "source": [ |
| 207 | + "!xrlint --print-config valid.zarr" |
| 208 | + ] |
| 209 | + }, |
| 210 | + { |
| 211 | + "cell_type": "code", |
| 212 | + "execution_count": null, |
| 213 | + "metadata": {}, |
| 214 | + "outputs": [], |
| 215 | + "source": [] |
| 216 | + } |
| 217 | + ], |
| 218 | + "metadata": { |
| 219 | + "kernelspec": { |
| 220 | + "display_name": "Python 3 (ipykernel)", |
| 221 | + "language": "python", |
| 222 | + "name": "python3" |
| 223 | + }, |
| 224 | + "language_info": { |
| 225 | + "codemirror_mode": { |
| 226 | + "name": "ipython", |
| 227 | + "version": 3 |
| 228 | + }, |
| 229 | + "file_extension": ".py", |
| 230 | + "mimetype": "text/x-python", |
| 231 | + "name": "python", |
| 232 | + "nbconvert_exporter": "python", |
| 233 | + "pygments_lexer": "ipython3", |
| 234 | + "version": "3.11.11" |
| 235 | + } |
| 236 | + }, |
| 237 | + "nbformat": 4, |
| 238 | + "nbformat_minor": 4 |
| 239 | +} |
0 commit comments