Skip to content

Commit 22a1a85

Browse files
authored
Merge pull request #2715 from ESMValGroup/enable-more-ruff-rules
Enable more ruff rules
2 parents d3eb1d1 + e2f8cab commit 22a1a85

401 files changed

Lines changed: 6235 additions & 3711 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/gensidebar.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
def _write_if_changed(fname, contents):
1111
"""Write/update file only if changed."""
1212
try:
13-
with open(fname, "r", encoding="utf-8") as stream:
13+
with open(fname, encoding="utf-8") as stream:
1414
old_contents = stream.read()
15-
except IOError:
15+
except OSError:
1616
old_contents = ""
1717

1818
if old_contents != contents:
@@ -42,15 +42,15 @@ def _write(project, desc, link, mapping=conf["intersphinx_mapping"]):
4242
if project != conf_api:
4343
if do_gen:
4444
args = desc, mapping[project][0], link
45-
lines.append(" %s <%s%s.html>" % args)
45+
lines.append(" {} <{}{}.html>".format(*args))
4646
else:
4747
args = desc, link
48-
lines.append(" %s <%s>" % args)
48+
lines.append(" {} <{}>".format(*args))
4949

5050
def _header(project, text):
5151
if project == conf_api or do_gen:
5252
lines.extend([".. toctree::", " :maxdepth: 2"])
53-
lines.extend([" :caption: %s" % text, ""])
53+
lines.extend([f" :caption: {text}", ""])
5454

5555
#
5656
# Specify the sidebar contents here

esmvalcore/_citation.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ def _save_citation_bibtex(product_name, tags, json_urls):
104104
citation_entries.extend(sorted(entries))
105105

106106
with open(
107-
f"{product_name}_citation.bibtex", "w", encoding="utf-8"
107+
f"{product_name}_citation.bibtex",
108+
"w",
109+
encoding="utf-8",
108110
) as file:
109111
file.write("\n".join(citation_entries))
110112

@@ -115,7 +117,7 @@ def _save_citation_info_txt(product_name, info_urls, other_info):
115117
# Save CMIP6 url_info
116118
if info_urls:
117119
lines.append(
118-
"Follow the links below to find more information about CMIP6 data:"
120+
"Follow the links below to find more information about CMIP6 data:",
119121
)
120122
lines.extend(f"- {url}" for url in sorted(info_urls))
121123

@@ -126,15 +128,17 @@ def _save_citation_info_txt(product_name, info_urls, other_info):
126128
lines.append("")
127129
lines.append(
128130
"Additional data citation information was found, for "
129-
"which no entry is available in the bibtex file:"
131+
"which no entry is available in the bibtex file:",
130132
)
131133
lines.extend(
132134
"- " + str(t).replace("\n", " ") for t in sorted(other_info)
133135
)
134136

135137
if lines:
136138
with open(
137-
f"{product_name}_data_citation_info.txt", "w", encoding="utf-8"
139+
f"{product_name}_data_citation_info.txt",
140+
"w",
141+
encoding="utf-8",
138142
) as file:
139143
file.write("\n".join(lines) + "\n")
140144

@@ -160,10 +164,10 @@ def _get_response(url):
160164
json_data = response.json()
161165
else:
162166
logger.warning("Error in the CMIP6 citation link: %s", url)
163-
except IOError:
167+
except OSError:
164168
logger.info(
165169
"No network connection, "
166-
"unable to retrieve CMIP6 citation information"
170+
"unable to retrieve CMIP6 citation information",
167171
)
168172
return json_data
169173

@@ -189,7 +193,7 @@ def _json_to_bibtex(data):
189193
doi = data["identifier"].get("id", "doi not found")
190194
url = f"https://doi.org/{doi}"
191195

192-
bibtex_entry = textwrap.dedent(f"""
196+
return textwrap.dedent(f"""
193197
@misc{{{url},
194198
\turl = {{{url}}},
195199
\ttitle = {{{title}}},
@@ -199,7 +203,6 @@ def _json_to_bibtex(data):
199203
\tdoi = {{{doi}}},
200204
}}
201205
""").lstrip()
202-
return bibtex_entry
203206

204207

205208
@lru_cache(maxsize=1024)
@@ -222,11 +225,7 @@ def _collect_bibtex_citation(tag):
222225
def _collect_cmip_citation(json_url):
223226
"""Collect information from CMIP6 Data Citation Service."""
224227
json_data = _get_response(json_url)
225-
if json_data:
226-
bibtex_entry = _json_to_bibtex(json_data)
227-
else:
228-
bibtex_entry = ""
229-
return bibtex_entry
228+
return _json_to_bibtex(json_data) if json_data else ""
230229

231230

232231
def _make_url_prefix(attribute):
@@ -242,17 +241,14 @@ def _make_url_prefix(attribute):
242241
for key, value in attribute:
243242
if key.localpart in localpart:
244243
localpart[key.localpart] = value
245-
url_prefix = ".".join(localpart.values())
246-
return url_prefix
244+
return ".".join(localpart.values())
247245

248246

249247
def _make_json_url(url_prefix):
250248
"""Make json url based on CMIP6 Data Citation Service."""
251-
json_url = f"{CMIP6_URL_STEM}/cerarest/exportcmip6?input={url_prefix}"
252-
return json_url
249+
return f"{CMIP6_URL_STEM}/cerarest/exportcmip6?input={url_prefix}"
253250

254251

255252
def _make_info_url(url_prefix):
256253
"""Make info url based on CMIP6 Data Citation Service."""
257-
info_url = f"{CMIP6_URL_STEM}/cmip6?input={url_prefix}"
258-
return info_url
254+
return f"{CMIP6_URL_STEM}/cmip6?input={url_prefix}"

0 commit comments

Comments
 (0)