Skip to content

Commit 4ab2474

Browse files
Develop black (#963)
* format * import Impact from climada.engine.impact in order to avoid circular imports * avoid circular imports * pre-commit run --all-files
1 parent 1048fc0 commit 4ab2474

File tree

65 files changed

+2548
-1616
lines changed

Some content is hidden

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

65 files changed

+2548
-1616
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A clear and concise description of what the bug is.
1212

1313
**To Reproduce**
1414
Steps to reproduce the behavior/error:
15-
1.
15+
1.
1616

1717
Code example:
1818
```python
@@ -29,7 +29,7 @@ If applicable, add screenshots to help explain your problem.
2929

3030
**System Information (please complete the following information):**
3131
- Operating system and version: [e.g. Ubuntu 22.04, macOS 14.3.1, Windows 10]
32-
- Python version: [e.g. 3.10]
32+
- Python version: [e.g. 3.10]
3333
(to obtain this information execute > import sys >print(sys.version))
3434

3535
**Additional context**

.github/pull_request_template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Changes proposed in this PR:
2-
-
3-
-
2+
-
3+
-
44

55
This PR fixes #
66

.github/scripts/make_release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
def get_version() -> str:
1414
"""Return the current version number, based on the _version.py file."""
1515
[version_file] = glob.glob("climada*/_version.py")
16-
with open(version_file, 'r', encoding="UTF-8") as vfp:
16+
with open(version_file, "r", encoding="UTF-8") as vfp:
1717
content = vfp.read()
18-
regex = r'^__version__\s*=\s*[\'\"](.*)[\'\"]\s*$'
18+
regex = r"^__version__\s*=\s*[\'\"](.*)[\'\"]\s*$"
1919
mtch = re.match(regex, content)
2020
return mtch.group(1)
2121

.github/scripts/prepare_release.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
- update version numbers in _version.py and setup.py
77
- purge the "Unreleased" section of CHANGELOG.md and rename it to the new version number
8-
- copy the README.md file to doc/misc/README.md,
8+
- copy the README.md file to doc/misc/README.md,
99
but without the badges as they interfere with the sphinx doc builder
1010
1111
All changes are immediately commited to the repository.
@@ -38,28 +38,28 @@ def bump_version_number(version_number: str, level: str) -> str:
3838
"""Return a copy of `version_number` with one level number incremented."""
3939
major, minor, patch = version_number.split(".")
4040
if level == "major":
41-
major = str(int(major)+1)
41+
major = str(int(major) + 1)
4242
minor = "0"
4343
patch = "0"
4444
elif level == "minor":
45-
minor = str(int(minor)+1)
45+
minor = str(int(minor) + 1)
4646
patch = "0"
4747
elif level == "patch":
48-
patch = str(int(patch)+1)
48+
patch = str(int(patch) + 1)
4949
else:
5050
raise ValueError(f"level should be 'major', 'minor' or 'patch', not {level}")
5151
return ".".join([major, minor, patch])
5252

5353

5454
def update_readme(_nvn):
55-
"""align doc/misc/README.md with ./README.md but remove the non-markdown header lines from """
56-
with open("README.md", 'r', encoding="UTF-8") as rmin:
57-
lines = [line for line in rmin.readlines() if not line.startswith('[![')]
55+
"""align doc/misc/README.md with ./README.md but remove the non-markdown header lines from"""
56+
with open("README.md", "r", encoding="UTF-8") as rmin:
57+
lines = [line for line in rmin.readlines() if not line.startswith("[![")]
5858
while not lines[0].strip():
5959
lines = lines[1:]
60-
with open("doc/misc/README.md", 'w', encoding="UTF-8") as rmout:
60+
with open("doc/misc/README.md", "w", encoding="UTF-8") as rmout:
6161
rmout.writelines(lines)
62-
return GitFile('doc/misc/README.md')
62+
return GitFile("doc/misc/README.md")
6363

6464

6565
def update_changelog(nvn):
@@ -70,16 +70,16 @@ def update_changelog(nvn):
7070
release = []
7171
section_name = None
7272
section = []
73-
with open("CHANGELOG.md", 'r', encoding="UTF-8") as changelog:
73+
with open("CHANGELOG.md", "r", encoding="UTF-8") as changelog:
7474
for line in changelog.readlines():
75-
if line.startswith('#'):
76-
if line.startswith('### '):
75+
if line.startswith("#"):
76+
if line.startswith("### "):
7777
if section:
7878
release.append((section_name, section))
7979
section_name = line[4:].strip()
8080
section = []
81-
#print("tag:", section_name)
82-
elif line.startswith('## '):
81+
# print("tag:", section_name)
82+
elif line.startswith("## "):
8383
if section:
8484
release.append((section_name, section))
8585
if release:
@@ -88,15 +88,15 @@ def update_changelog(nvn):
8888
release = []
8989
section_name = None
9090
section = []
91-
#print("release:", release_name)
91+
# print("release:", release_name)
9292
else:
9393
section.append(line)
9494
if section:
9595
release.append((section_name, section))
9696
if release:
9797
releases.append((release_name, release))
9898

99-
with open("CHANGELOG.md", 'w', encoding="UTF-8") as changelog:
99+
with open("CHANGELOG.md", "w", encoding="UTF-8") as changelog:
100100
changelog.write("# Changelog\n\n")
101101
for release_name, release in releases:
102102
if release_name:
@@ -107,7 +107,11 @@ def update_changelog(nvn):
107107
if any(ln.strip() for ln in section):
108108
if section_name:
109109
changelog.write(f"### {section_name}\n")
110-
lines = [ln.strip() for ln in section if "code freeze date: " not in ln.lower()]
110+
lines = [
111+
ln.strip()
112+
for ln in section
113+
if "code freeze date: " not in ln.lower()
114+
]
111115
if not section_name and release_name.lower() == nvn:
112116
print("setting date")
113117
for i, line in enumerate(lines):
@@ -116,26 +120,26 @@ def update_changelog(nvn):
116120
lines[i] = f"Release date: {today}"
117121
changelog.write(re.sub("\n+$", "\n", "\n".join(lines)))
118122
changelog.write("\n")
119-
return GitFile('CHANGELOG.md')
123+
return GitFile("CHANGELOG.md")
120124

121125

122126
def update_version(nvn):
123127
"""Update the _version.py file"""
124128
[file_with_version] = glob.glob("climada*/_version.py")
125-
regex = r'(^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)'
129+
regex = r"(^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)"
126130
return update_file(file_with_version, regex, nvn)
127131

128132

129133
def update_setup(new_version_number):
130134
"""Update the setup.py file"""
131135
file_with_version = "setup.py"
132-
regex = r'(^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)'
136+
regex = r"(^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)"
133137
return update_file(file_with_version, regex, new_version_number)
134138

135139

136140
def update_file(file_with_version, regex, new_version_number):
137141
"""Replace the version number(s) in a file, based on a rgular expression."""
138-
with open(file_with_version, 'r', encoding="UTF-8") as curf:
142+
with open(file_with_version, "r", encoding="UTF-8") as curf:
139143
lines = curf.readlines()
140144
successfully_updated = False
141145
for i, line in enumerate(lines):
@@ -145,14 +149,15 @@ def update_file(file_with_version, regex, new_version_number):
145149
successfully_updated = True
146150
if not successfully_updated:
147151
raise RuntimeError(f"cannot determine version of {file_with_version}")
148-
with open(file_with_version, 'w', encoding="UTF-8") as newf:
152+
with open(file_with_version, "w", encoding="UTF-8") as newf:
149153
for line in lines:
150154
newf.write(line)
151155
return GitFile(file_with_version)
152156

153157

154-
class GitFile():
158+
class GitFile:
155159
"""Helper class for `git add`."""
160+
156161
def __init__(self, path):
157162
self.path = path
158163

@@ -166,8 +171,9 @@ def gitadd(self):
166171
).stdout.decode("utf8")
167172

168173

169-
class Git():
174+
class Git:
170175
"""Helper class for `git commit`."""
176+
171177
def __init__(self):
172178
_gitname = subprocess.run(
173179
["git", "config", "--global", "user.name", "'climada'"],
@@ -228,6 +234,7 @@ def prepare_new_release(level):
228234

229235
if __name__ == "__main__":
230236
from sys import argv
237+
231238
try:
232239
LEVEL = argv[1]
233240
except IndexError:

.github/scripts/setup_devbranch.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ def get_last_version() -> str:
3333

3434
def update_changelog():
3535
"""Insert a vanilla "Unreleased" section on top."""
36-
with open("CHANGELOG.md", 'r', encoding="UTF-8") as changelog:
36+
with open("CHANGELOG.md", "r", encoding="UTF-8") as changelog:
3737
lines = changelog.readlines()
3838

3939
if "## Unreleased" in lines:
4040
return
4141

42-
with open("CHANGELOG.md", 'w', encoding="UTF-8") as changelog:
43-
changelog.write("""# Changelog
42+
with open("CHANGELOG.md", "w", encoding="UTF-8") as changelog:
43+
changelog.write(
44+
"""# Changelog
4445
4546
## Unreleased
4647
@@ -62,27 +63,28 @@ def update_changelog():
6263
6364
### Removed
6465
65-
""")
66+
"""
67+
)
6668
changelog.writelines(lines[2:])
6769

6870

6971
def update_version(nvn):
7072
"""Update the _version.py file"""
7173
[file_with_version] = glob.glob("climada*/_version.py")
72-
regex = r'(^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)'
74+
regex = r"(^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)"
7375
return update_file(file_with_version, regex, nvn)
7476

7577

7678
def update_setup(new_version_number):
7779
"""Update the setup.py file"""
7880
file_with_version = "setup.py"
79-
regex = r'(^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)'
81+
regex = r"(^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)"
8082
return update_file(file_with_version, regex, new_version_number)
8183

8284

8385
def update_file(file_with_version, regex, new_version_number):
8486
"""Replace the version number(s) in a file, based on a rgular expression."""
85-
with open(file_with_version, 'r', encoding="UTF-8") as curf:
87+
with open(file_with_version, "r", encoding="UTF-8") as curf:
8688
lines = curf.readlines()
8789
successfully_updated = False
8890
for i, line in enumerate(lines):
@@ -92,18 +94,18 @@ def update_file(file_with_version, regex, new_version_number):
9294
successfully_updated = True
9395
if not successfully_updated:
9496
raise RuntimeError(f"cannot determine version of {file_with_version}")
95-
with open(file_with_version, 'w', encoding="UTF-8") as newf:
97+
with open(file_with_version, "w", encoding="UTF-8") as newf:
9698
for line in lines:
9799
newf.write(line)
98100

99101

100102
def setup_devbranch():
101103
"""Adjust files after a release was published, i.e.,
102104
apply the canonical deviations from main in develop.
103-
105+
104106
Just changes files, all `git` commands are in the setup_devbranch.sh file.
105107
"""
106-
main_version = get_last_version().strip('v')
108+
main_version = get_last_version().strip("v")
107109
semver = main_version.split(".")
108110
semver[-1] = f"{int(semver[-1]) + 1}-dev"
109111
dev_version = ".".join(semver)

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ graft climada/*/test/data
44
graft climada/test/data
55
graft data
66
global-exclude .*
7-
global-exclude *.py[co]
7+
global-exclude *.py[co]

climada.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
"supported_exposures_types": ["litpop", "crop_production", "base"]
2828
},
2929
"log_level": "INFO"
30-
}
30+
}

climada/data/demo/demo_emdat_impact_data_2020.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,4 +1073,4 @@ Dis No,Year,Seq,Disaster Group,Disaster Subgroup,Disaster Type,Disaster Subtype,
10731073
2020-0132-TON,2020,0132,Natural,Meteorological,Storm,Tropical cyclone,,Cyclone 'Harold',--,Tonga,TON,Polynesia,Oceania,"Tongatapu, 'Eua",,,,,,,,,Kph,,,,,2020,4,6,2020,4,9,,,1289,,1289,,,111000,
10741074
2020-0015-TUV,2020,0015,Natural,Meteorological,Storm,Tropical cyclone,,Cyclone 'Tino',Affected,Tuvalu,TUV,Polynesia,Oceania,,,,,,,Yes,,,Kph,,,,,2020,1,18,2020,1,18,,,,,,,,,
10751075
2020-0219-USA,2020,0219,Natural,Meteorological,Storm,Tropical cyclone,,Tropical storm 'Cristobal',Affected,United States of America (the),USA,Northern America,Americas,"errebonne, Plaquemines, Lafourche Parishes (Louisiana)",,,,,,Yes,,80,Kph,,,,,2020,6,7,2020,6,7,,,,,,,,,
1076-
2020-0132-VUT,2020,0132,Natural,Meteorological,Storm,Tropical cyclone,,Cyclone 'Harold',--,Vanuatu,VUT,Melanesia,Oceania,Pentecost and Espiritu Santo,,,,,,,,,Kph,,,,,2020,4,6,2020,4,9,4,,,,,,,,
1076+
2020-0132-VUT,2020,0132,Natural,Meteorological,Storm,Tropical cyclone,,Cyclone 'Harold',--,Vanuatu,VUT,Melanesia,Oceania,Pentecost and Espiritu Santo,,,,,,,,,Kph,,,,,2020,4,6,2020,4,9,4,,,,,,,,

climada/data/system/GDP_TWN_IMF_WEO_data.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ TWN,Taiwan Province of China,"Gross domestic product, current prices",U.S. dolla
33
TWN,Taiwan Province of China,"Gross domestic product, deflator",Index,,"See notes for: Gross domestic product, constant prices (National currency) Gross domestic product, current prices (National currency).",69.946,77.417,79.33,81.444,82.495,82.523,86.575,86.605,86.657,88.892,93.472,96.725,99.824,103.299,105.065,107.554,110.062,112.506,116.182,113.911,112.88,112.189,111.733,110.174,109.894,108.209,107.095,106.638,103.869,104.003,102.405,100,100.543,102.019,103.749,107.128,108.085,106.84,105.834,106.337,106.484,107.149,108.054,109.026,109.951,2018
44
TWN,Taiwan Province of China,"Gross domestic product per capita, current prices",U.S. dollars,Units,"See notes for: Gross domestic product, current prices (National currency) Population (Persons).","2,367.600","2,692.406","2,675.823","2,882.402","3,203.468","3,295.112","4,010.111","5,325.216","6,337.499","7,577.046","8,178.152","9,092.297","10,725.702","11,266.123","12,108.752","13,076.007","13,597.248","13,968.097","12,787.258","13,768.274","14,876.879","13,408.383","13,715.525","14,094.370","15,360.724","16,503.313","16,984.540","17,780.925","18,102.946","16,959.775","19,261.667","20,911.643","21,269.614","21,887.992","22,638.917","22,373.564","22,572.702","24,389.677","25,007.747","24,827.898","25,525.806","26,861.070","28,324.425","29,870.221","31,483.799",2018
55
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
6-
"International Monetary Fund, World Economic Outlook Database, October 2019",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
6+
"International Monetary Fund, World Economic Outlook Database, October 2019",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

climada/data/system/WEALTH2GDP_factors_CRI_2016.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,4 @@ Venezuela,VEN,0.29407,0.35328
169169
Vietnam,VNM,1.23241,1.66724
170170
Yemen,YEM,1.18584,1.76063
171171
Zambia,ZMB,0.10663,0.32193
172-
Zimbabwe,ZWE,0.20161,1.65566
172+
Zimbabwe,ZWE,0.20161,1.65566

0 commit comments

Comments
 (0)