Skip to content

Commit e8eb7f6

Browse files
committed
Merge branch 'develop' into cross-calibrate-impact-functions
2 parents 72ccfc9 + bc37227 commit e8eb7f6

File tree

214 files changed

+29014
-16652
lines changed

Some content is hidden

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

214 files changed

+29014
-16652
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)

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
build-and-test:
1313
name: 'Core / Unit Test Pipeline'
1414
runs-on: ubuntu-latest
15+
timeout-minutes: 20
1516
permissions:
1617
# For publishing results
1718
checks: write

.github/workflows/pull-request.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: GitHub CI
2+
3+
# Execute this for every pull request (opened, reopened, and synchronized)
4+
on: [pull_request]
5+
6+
jobs:
7+
pre-commit-checks:
8+
name: 'Core / Pre-Commit Checks'
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
-
13+
name: Checkout Repo
14+
uses: actions/checkout@v4
15+
with:
16+
ref: ${{ github.event.pull_request.head.sha }}
17+
-
18+
name: Checkout target commit
19+
run: git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin ${{ github.event.pull_request.base.ref }}
20+
-
21+
name: Set up Python 3.11
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: '3.11'
25+
-
26+
# Store the current date to use it as cache key
27+
name: Get current date
28+
id: date
29+
run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}"
30+
-
31+
name: Cache dependencies
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
~/.cache/pip
36+
~/.cache/pre-commit
37+
key: ${{ github.event.pull_request.head.ref }}-${{ steps.date.outputs.date }}
38+
restore-keys: |
39+
${{ github.event.pull_request.head.ref }}
40+
${{ github.event.pull_request.base.ref }}
41+
develop
42+
main
43+
-
44+
name: Install pre-commit and hooks
45+
run: |
46+
pip install pre-commit
47+
pre-commit install --install-hooks
48+
-
49+
name: Run pre-commit checks
50+
run: pre-commit run --show-diff-on-failure --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,10 @@ data/ISIMIP_crop/
176176

177177
# climada data results folder:
178178
results/
179+
180+
# Hidden files we want to track
181+
!.gitignore
182+
!.pre-commit-config.yaml
183+
!.pylintrc
184+
!.readthedocs.yml
185+
!.github

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://pre-commit.com for more information
2+
default_language_version:
3+
python: python3
4+
5+
# See https://pre-commit.com/hooks.html for more hooks
6+
repos:
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v3.2.0
9+
hooks:
10+
- id: end-of-file-fixer
11+
- id: trailing-whitespace
12+
13+
- repo: https://github.com/pycqa/isort
14+
rev: '5.13.2'
15+
hooks:
16+
- id: isort
17+
args: ["--profile", "black", "--filter-files"]
18+
19+
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
20+
- repo: https://github.com/psf/black-pre-commit-mirror
21+
rev: '24.4.2'
22+
hooks:
23+
- id: black-jupyter

0 commit comments

Comments
 (0)