Skip to content

Commit ae99250

Browse files
authored
Use pooch instead of bundling standard name table (#436)
* Use pooch instead of bundling standard name table * fix * Skip pooch in mypy * Make pooch more optionall * Minor fixes
1 parent 2d579f2 commit ae99250

File tree

7 files changed

+15
-34290
lines changed

7 files changed

+15
-34290
lines changed

cf_xarray/accessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ def add_canonical_attributes(
20232023
Print added attributes to screen.
20242024
source : optional
20252025
Path of `cf-standard-name-table.xml` or file object containing XML data.
2026-
If ``None``, use the default version associated with ``cf-xarray``.
2026+
If ``None``, use the latest CF standard name table (requires ``pooch``).
20272027
20282028
Returns
20292029
-------

cf_xarray/data/cf-standard-name-table.xml

Lines changed: 0 additions & 34276 deletions
This file was deleted.

cf_xarray/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@ def LooseVersion(vstring):
6767
has_scipy, requires_scipy = _importorskip("scipy")
6868
has_shapely, requires_shapely = _importorskip("shapely")
6969
has_pint, requires_pint = _importorskip("pint")
70+
has_pooch, requires_pooch = _importorskip("pooch")
7071
_, requires_rich = _importorskip("rich")
7172
has_regex, requires_regex = _importorskip("regex")

cf_xarray/tests/test_accessor.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import pickle
33
import warnings
44
from textwrap import dedent
5-
from urllib.request import urlopen
65

76
import matplotlib as mpl
87
import numpy as np
@@ -41,6 +40,7 @@
4140
raise_if_dask_computes,
4241
requires_cftime,
4342
requires_pint,
43+
requires_pooch,
4444
requires_regex,
4545
requires_rich,
4646
requires_scipy,
@@ -1698,14 +1698,9 @@ def test_regex_match():
16981698
assert_identical(ds.cf["temp"], ds["Tempblah"])
16991699

17001700

1701+
@requires_pooch
17011702
def test_cf_standard_name_table_version() -> None:
1702-
url = (
1703-
"https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/"
1704-
"master/Data/cf-standard-names/current/src/cf-standard-name-table.xml"
1705-
)
1706-
expected_info, _, _ = parse_cf_standard_name_table(urlopen(url))
1707-
actual_info, _, _ = parse_cf_standard_name_table()
1708-
assert expected_info == actual_info
1703+
parse_cf_standard_name_table()
17091704

17101705

17111706
def test_add_canonical_attributes_0_dim() -> None:

cf_xarray/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from collections import defaultdict
32
from typing import Any, Dict, Iterable
43
from xml.etree import ElementTree
@@ -83,8 +82,12 @@ def parse_cf_standard_name_table(source=None):
8382
""""""
8483

8584
if not source:
86-
source = os.path.join(
87-
os.path.dirname(__file__), "data", "cf-standard-name-table.xml"
85+
import pooch
86+
87+
source = pooch.retrieve(
88+
"https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/"
89+
"master/Data/cf-standard-names/current/src/cf-standard-name-table.xml",
90+
known_hash=None,
8891
)
8992
root = ElementTree.parse(source).getroot()
9093

ci/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies:
1515
- pooch
1616
- regex
1717
- rich
18+
- pooch
1819
- scipy
1920
- shapely
2021
- xarray

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies = [
2222
dynamic = ["version"]
2323

2424
[project.optional-dependencies]
25-
all = ["matplotlib", "pint", "shapely", "regex", "rich"]
25+
all = ["matplotlib", "pint", "shapely", "regex", "rich", "pooch"]
2626

2727
[project.urls]
2828
homepage = "https://cf-xarray.readthedocs.io"
@@ -41,7 +41,7 @@ requires = [
4141
build-backend = "setuptools.build_meta"
4242

4343
[tool.setuptools]
44-
packages = ["cf_xarray", "cf_xarray.data", "cf_xarray.scripts"]
44+
packages = ["cf_xarray", "cf_xarray.scripts"]
4545

4646
[tool.setuptools.exclude-package-data]
4747
cf_xarray = ["tests/*"]
@@ -129,6 +129,7 @@ warn_unused_ignores = true
129129
module=[
130130
"cftime",
131131
"pandas",
132+
"pooch",
132133
"matplotlib",
133134
"pytest",
134135
"shapely.geometry",

0 commit comments

Comments
 (0)