Skip to content

Commit f03bd51

Browse files
Release 2.0 (#170)
* Update changelog * Fix dependencies * Update notices on readme * Add py3.12 to changelog * Make newest cads-api-client version work * Bump version to 2.0.0 * Drop py38 add py312 for the testing workflow * Remove reference to old cdsapi package * Turns out the the cads-api-client still needs the cdsapi * Patch new LegacyApiClient class instead of old client * Fix API again, add 3.13 support.
1 parent 94bfafb commit f03bd51

File tree

10 files changed

+108
-50
lines changed

10 files changed

+108
-50
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.0.0b2
2+
current_version = 2.0.0
33

44
[comment]
55
comment = The contents of this file cannot be merged with that of pyproject.toml until https://github.com/c4urself/bump2version/issues/42 is resolved

.github/workflows/test_and_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
python-version: ["3.8", "3.9", "3.10", "3.11"]
15+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1616
name: Run tests for ${{ matrix.python-version }}
1717
steps:
1818
- uses: actions/checkout@v3

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ license: Apache-2.0
9797
message: "If you use this software, please cite it using these metadata."
9898
repository-code: "https://github.com/ewatercycle/era5cli"
9999
title: era5cli
100-
version: "2.0.0b2"
100+
version: "2.0.0"

README.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
<img align="right" width="150" alt="Logo" src="docs/assets/era5cli_logo_colors_border.png">
2-
3-
> [!IMPORTANT]
4-
> The old Climate Data Store (CDS) will be shut down on 3 September 2024.
5-
> All era5cli versions up to v1.4.2 will no longer work.
6-
>
7-
> For more information see: https://forum.ecmwf.int/t/the-new-climate-data-store-beta-cds-beta-is-now-live/3315
8-
>
9-
>
10-
> To continue using era5cli, you will need to re-register at ECMWF and get a new API key,
11-
> and transition to the era5cli v2 beta. This can be installed with:
12-
> `pip install era5cli==2.0.0b2`
13-
14-
> [!WARNING]
15-
> netCDF files from the new Climate Data Store Beta are not formatted the same as the
16-
> old CDS. Some variables might be missing.
17-
> See the open issue [here](https://github.com/eWaterCycle/era5cli/issues/165), as well as the [ECMWF discussion forum](https://forum.ecmwf.int/).
18-
19-
201
[![github license badge](https://img.shields.io/github/license/eWaterCycle/era5cli)](https://github.com/eWaterCycle/era5cli)
212
[![rsd badge](https://img.shields.io/badge/RSD-era5cli-blue)](https://research-software-directory.org/software/era5cli)
223
[![fair-software.eu](https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8B-yellow)](https://fair-software.eu)
@@ -27,6 +8,22 @@
278
[![Test Coverage](https://codecov.io/gh/eWaterCycle/era5cli/branch/main/graph/badge.svg?token=qeZXgGASBK)](https://codecov.io/gh/eWaterCycle/era5cli)
289
[![PyPI](https://badge.fury.io/py/era5cli.svg)](https://badge.fury.io/py/era5cli)
2910

11+
<img align="right" width="150" alt="Logo" src="docs/assets/era5cli_logo_colors_border.png">
12+
13+
> [!IMPORTANT]
14+
> The old Climate Data Store (CDS) has been shut down. All era5cli versions up to v1.4.2 will no longer work.
15+
>
16+
> For more information see:
17+
> https://forum.ecmwf.int/t/goodbye-legacy-climate-data-store-hello-new-climate-data-store-cds/6380/14
18+
>
19+
> To continue using era5cli, you will need to re-register at ECMWF and get a new API key,
20+
> and transition to era5cli version 2. This can be installed with:
21+
> `pip install era5cli==2.0.0`
22+
23+
> [!WARNING]
24+
> netCDF files from the new Climate Data Store Beta are not formatted the same as the
25+
> old CDS. Some variables might be missing.
26+
> See the open issue [here](https://github.com/eWaterCycle/era5cli/issues/165), as well as the [ECMWF discussion forum](https://forum.ecmwf.int/).
3027
3128
A command line interface to download ERA5 data from the [Copernicus Climate Data Store](<https://climate.copernicus.eu/>).
3229

docs/CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
# 2.0.0 - 2025-02-12
11+
12+
Changes since v1.4.2:
13+
14+
**Added:**
15+
16+
- support for Python 3.12, 3.13.
17+
18+
**Changed:**
19+
20+
- The `splitmonths` argument now defaults to `True` for hourly requests. To not split requests by year, add `--splitmonths False`.
21+
- The 'cads-api-client' used in the 2.0 beta versions is already deprecated, the backend now uses the 'cdsapi' again, which uses ["datapi"](https://github.com/ecmwf-projects/datapi).
22+
23+
**Fixed:**
24+
25+
- Added support for the new climate data store.
26+
27+
**Removed:**
28+
29+
- the deprecated `orography` variable. Use `geopotential` instead.
30+
- the deprecated `--prelimbe` argument. This one has not been required anymore, as the back-extension is part of the normal dataset now.
31+
- support for Python 3.8.
32+
33+
**Dev changes:**
34+
35+
- The pre-commit hook has been removed. Pre-commit does not play well with hatch: it would need to be installed system-wide. No hatch-specific hooks are available.
36+
37+
38+
1039
## 2.0.0b2 - 2024-09-20
1140

1241
**Fixed:**

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A command line interface to download ERA5 data from the [Copernicus Climate Data
1010

1111
To continue using era5cli, you will need to re-register at ECMWF and get a new API key,
1212
and transition to the era5cli v2 beta. This can be installed with:
13-
`pip install era5cli==2.0.0b2`
13+
`pip install era5cli>=2.0.0`
1414

1515
???+ warning
1616
netCDF files from the new Climate Data Store Beta are not formatted the same as the

era5cli/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
"Bart Schilperoort",
2727
)
2828
__email__ = "[email protected]"
29-
__version__ = "2.0.0b2"
29+
__version__ = "2.0.0"

era5cli/key_management.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import sys
33
from pathlib import Path
44
from typing import Tuple
5-
import cads_api_client
5+
import cdsapi
66
from requests.exceptions import ConnectionError # pylint: disable=redefined-builtin
77

88

99
ERA5CLI_CONFIG_PATH = Path.home() / ".config" / "era5cli" / "cds_key.txt"
1010
CDSAPI_CONFIG_PATH = Path.home() / ".cdsapirc"
11-
DEFAULT_CDS_URL = "https://cds-beta.climate.copernicus.eu/api"
11+
DEFAULT_CDS_URL = "https://cds.climate.copernicus.eu/api"
1212

13-
AUTH_ERR_MSG = "401 Client Error"
13+
AUTH_ERR_MSG = "401"
14+
NO_DATA_ERR_MSG = "There is no data matching your request"
1415

1516

1617
class InvalidRequestError(Exception):
@@ -34,9 +35,23 @@ def attempt_cds_login(url: str, key: str) -> True:
3435
InvalidRequestError: If the test request failed, likely due to changes in the
3536
CDS API's variable naming.
3637
"""
37-
client = cads_api_client.ApiClient(key, url)
38+
client = cdsapi.Client(key=key, url=url, verify=True)
3839
try:
39-
client.check_authentication()
40+
# Check the URL
41+
client.status() # pragma: no cover
42+
43+
# Checks if the authentication works, without downloading data
44+
client.retrieve( # pragma: no cover
45+
"reanalysis-era5-single-levels",
46+
{
47+
"variable": "2t",
48+
"product_type": "reanalysis",
49+
"date": "2012-12-01",
50+
"time": "14:00",
51+
"format": "netcdf",
52+
},
53+
)
54+
return True
4055
except ConnectionError as err:
4156
raise ConnectionError(
4257
f"{os.linesep}Failed to connect to CDS. Please check your internet "
@@ -54,6 +69,11 @@ def attempt_cds_login(url: str, key: str) -> True:
5469
f"{ERA5CLI_CONFIG_PATH.resolve()}{os.linesep}"
5570
"Or redefine your configuration with 'era5cli config'"
5671
) from err
72+
if NO_DATA_ERR_MSG in str(err):
73+
raise InvalidRequestError(
74+
f"{os.linesep}Something changed in the CDS API. Please raise an issue "
75+
"on https://www.github.com/eWaterCycle/era5cli"
76+
) from err
5777
raise err # pragma: no cover
5878

5979

@@ -123,7 +143,7 @@ def load_era5cli_config() -> Tuple[str, str]:
123143
"Old config detected. In the new CDS API only a key is required.\n"
124144
"Please look at the new CDS website, and reconfigure your login in "
125145
"era5cli\n"
126-
" https://cds-beta.climate.copernicus.eu/"
146+
" https://cds.climate.copernicus.eu/"
127147
)
128148
raise InvalidLoginError(msg)
129149

@@ -148,7 +168,7 @@ def load_cdsapi_config() -> Tuple[str, str]:
148168
msg = (
149169
"Your CDS API configuration file contains a UID entry/incorrect URL.\n"
150170
"Please look at the new CDS website, and reconfigure your key:\n"
151-
" https://cds-beta.climate.copernicus.eu/"
171+
" https://cds.climate.copernicus.eu/"
152172
)
153173
raise InvalidLoginError(msg)
154174
return url, key

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ name = "era5cli"
1313
description = "A command line interface to download ERA5 data from the Copernicus Climate Data Store. https://climate.copernicus.eu/.."
1414
readme = "README.md"
1515
license = { text = "Apache Software License" }
16-
requires-python = ">=3.8, <3.12"
16+
requires-python = ">=3.9"
1717
authors = [
1818
{name = "Ronald van Haren"},
1919
{name = "Jaro Camphuijsen"},
@@ -51,14 +51,14 @@ classifiers = [
5151
"Operating System :: POSIX",
5252
"Programming Language :: Python",
5353
"Programming Language :: Python :: 3 :: Only",
54-
"Programming Language :: Python :: 3.8",
5554
"Programming Language :: Python :: 3.9",
5655
"Programming Language :: Python :: 3.10",
5756
"Programming Language :: Python :: 3.11",
57+
"Programming Language :: Python :: 3.12",
58+
"Programming Language :: Python :: 3.13",
5859
]
5960
dependencies = [
60-
"cdsapi>=0.7.1",
61-
"cads-api-client==1.3.0", # Pin because API is unstable: github.com/ecmwf-projects/cads-api-client/issues/81
61+
"cdsapi>=0.7.4",
6262
"pathos",
6363
"PTable",
6464
"netCDF4"
@@ -111,7 +111,7 @@ serve = ["mkdocs serve",]
111111

112112
[tool.black]
113113
line-length = 88
114-
target-version = ['py38', 'py39', 'py310', 'py311']
114+
target-version = ['py39', 'py310', 'py311', 'py312', 'py313']
115115
include = '\.pyi?$'
116116

117117
[tool.isort]

tests/test_config.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,29 +122,41 @@ class TestAttemptCdsLogin:
122122
expected.
123123
"""
124124

125-
@pytest.mark.xfail(reason="broken by new cads-client api")
126125
def test_status_fail(self):
127-
with patch(
128-
"cads_api_client.ApiClient.check_authentication",
129-
side_effect=rex.ConnectionError,
130-
):
126+
with patch("cdsapi.Client.status", side_effect=rex.ConnectionError):
131127
with pytest.raises(rex.ConnectionError, match="Failed to connect to CDS"):
132-
key_management.attempt_cds_login(
133-
url="https://www.github.com/", key="def"
134-
)
128+
key_management.attempt_cds_login(url="test", key="abc:def")
135129

136130
def test_connection_fail(self):
137-
mp = patch(
138-
"cads_api_client.ApiClient.check_authentication",
139-
side_effect=Exception("401 Client Error"),
131+
mp1 = patch("cdsapi.Client.status")
132+
mp2 = patch(
133+
"cdsapi.Client.retrieve",
134+
side_effect=Exception("401"),
140135
)
141-
with mp:
136+
with mp1, mp2:
142137
with pytest.raises(
143138
key_management.InvalidLoginError,
144139
match="Authorization with the CDS served failed",
140+
):
141+
key_management.attempt_cds_login(
142+
url="https://www.github.com/", key="abc:def"
143+
)
144+
145+
def test_retrieve_fail(self):
146+
mp1 = patch("cdsapi.Client.status")
147+
mp2 = patch(
148+
"cdsapi.Client.retrieve",
149+
side_effect=Exception("There is no data matching your request"),
150+
)
151+
with mp1, mp2:
152+
with pytest.raises(
153+
key_management.InvalidRequestError,
154+
match="Something changed in the CDS API",
145155
):
146156
key_management.attempt_cds_login(url="test", key="abc:def")
147157

148158
def test_all_pass(self):
149-
with patch("cads_api_client.ApiClient.check_authentication"):
150-
key_management.attempt_cds_login(url="test", key="abc:def")
159+
mp1 = patch("cdsapi.Client.status")
160+
mp2 = patch("cdsapi.Client.retrieve")
161+
with mp1, mp2:
162+
assert key_management.attempt_cds_login(url="test", key="abc:def") is True

0 commit comments

Comments
 (0)