Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop black #963

Merged
merged 5 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior/error:
1.
1.

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

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

**Additional context**
Expand Down
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Changes proposed in this PR:
-
-
-
-

This PR fixes #

Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/make_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
def get_version() -> str:
"""Return the current version number, based on the _version.py file."""
[version_file] = glob.glob("climada*/_version.py")
with open(version_file, 'r', encoding="UTF-8") as vfp:
with open(version_file, "r", encoding="UTF-8") as vfp:
content = vfp.read()
regex = r'^__version__\s*=\s*[\'\"](.*)[\'\"]\s*$'
regex = r"^__version__\s*=\s*[\'\"](.*)[\'\"]\s*$"
mtch = re.match(regex, content)
return mtch.group(1)

Expand Down
55 changes: 31 additions & 24 deletions .github/scripts/prepare_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

- update version numbers in _version.py and setup.py
- purge the "Unreleased" section of CHANGELOG.md and rename it to the new version number
- copy the README.md file to doc/misc/README.md,
- copy the README.md file to doc/misc/README.md,
but without the badges as they interfere with the sphinx doc builder

All changes are immediately commited to the repository.
Expand Down Expand Up @@ -38,28 +38,28 @@ def bump_version_number(version_number: str, level: str) -> str:
"""Return a copy of `version_number` with one level number incremented."""
major, minor, patch = version_number.split(".")
if level == "major":
major = str(int(major)+1)
major = str(int(major) + 1)
minor = "0"
patch = "0"
elif level == "minor":
minor = str(int(minor)+1)
minor = str(int(minor) + 1)
patch = "0"
elif level == "patch":
patch = str(int(patch)+1)
patch = str(int(patch) + 1)
else:
raise ValueError(f"level should be 'major', 'minor' or 'patch', not {level}")
return ".".join([major, minor, patch])


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


def update_changelog(nvn):
Expand All @@ -70,16 +70,16 @@ def update_changelog(nvn):
release = []
section_name = None
section = []
with open("CHANGELOG.md", 'r', encoding="UTF-8") as changelog:
with open("CHANGELOG.md", "r", encoding="UTF-8") as changelog:
for line in changelog.readlines():
if line.startswith('#'):
if line.startswith('### '):
if line.startswith("#"):
if line.startswith("### "):
if section:
release.append((section_name, section))
section_name = line[4:].strip()
section = []
#print("tag:", section_name)
elif line.startswith('## '):
# print("tag:", section_name)
elif line.startswith("## "):
if section:
release.append((section_name, section))
if release:
Expand All @@ -88,15 +88,15 @@ def update_changelog(nvn):
release = []
section_name = None
section = []
#print("release:", release_name)
# print("release:", release_name)
else:
section.append(line)
if section:
release.append((section_name, section))
if release:
releases.append((release_name, release))

with open("CHANGELOG.md", 'w', encoding="UTF-8") as changelog:
with open("CHANGELOG.md", "w", encoding="UTF-8") as changelog:
changelog.write("# Changelog\n\n")
for release_name, release in releases:
if release_name:
Expand All @@ -107,7 +107,11 @@ def update_changelog(nvn):
if any(ln.strip() for ln in section):
if section_name:
changelog.write(f"### {section_name}\n")
lines = [ln.strip() for ln in section if "code freeze date: " not in ln.lower()]
lines = [
ln.strip()
for ln in section
if "code freeze date: " not in ln.lower()
]
if not section_name and release_name.lower() == nvn:
print("setting date")
for i, line in enumerate(lines):
Expand All @@ -116,26 +120,26 @@ def update_changelog(nvn):
lines[i] = f"Release date: {today}"
changelog.write(re.sub("\n+$", "\n", "\n".join(lines)))
changelog.write("\n")
return GitFile('CHANGELOG.md')
return GitFile("CHANGELOG.md")


def update_version(nvn):
"""Update the _version.py file"""
[file_with_version] = glob.glob("climada*/_version.py")
regex = r'(^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)'
regex = r"(^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)"
return update_file(file_with_version, regex, nvn)


def update_setup(new_version_number):
"""Update the setup.py file"""
file_with_version = "setup.py"
regex = r'(^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)'
regex = r"(^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)"
return update_file(file_with_version, regex, new_version_number)


def update_file(file_with_version, regex, new_version_number):
"""Replace the version number(s) in a file, based on a rgular expression."""
with open(file_with_version, 'r', encoding="UTF-8") as curf:
with open(file_with_version, "r", encoding="UTF-8") as curf:
lines = curf.readlines()
successfully_updated = False
for i, line in enumerate(lines):
Expand All @@ -145,14 +149,15 @@ def update_file(file_with_version, regex, new_version_number):
successfully_updated = True
if not successfully_updated:
raise RuntimeError(f"cannot determine version of {file_with_version}")
with open(file_with_version, 'w', encoding="UTF-8") as newf:
with open(file_with_version, "w", encoding="UTF-8") as newf:
for line in lines:
newf.write(line)
return GitFile(file_with_version)


class GitFile():
class GitFile:
"""Helper class for `git add`."""

def __init__(self, path):
self.path = path

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


class Git():
class Git:
"""Helper class for `git commit`."""

def __init__(self):
_gitname = subprocess.run(
["git", "config", "--global", "user.name", "'climada'"],
Expand Down Expand Up @@ -228,6 +234,7 @@ def prepare_new_release(level):

if __name__ == "__main__":
from sys import argv

try:
LEVEL = argv[1]
except IndexError:
Expand Down
22 changes: 12 additions & 10 deletions .github/scripts/setup_devbranch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ def get_last_version() -> str:

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

if "## Unreleased" in lines:
return

with open("CHANGELOG.md", 'w', encoding="UTF-8") as changelog:
changelog.write("""# Changelog
with open("CHANGELOG.md", "w", encoding="UTF-8") as changelog:
changelog.write(
"""# Changelog

## Unreleased

Expand All @@ -62,27 +63,28 @@ def update_changelog():

### Removed

""")
"""
)
changelog.writelines(lines[2:])


def update_version(nvn):
"""Update the _version.py file"""
[file_with_version] = glob.glob("climada*/_version.py")
regex = r'(^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)'
regex = r"(^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)"
return update_file(file_with_version, regex, nvn)


def update_setup(new_version_number):
"""Update the setup.py file"""
file_with_version = "setup.py"
regex = r'(^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)'
regex = r"(^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)"
return update_file(file_with_version, regex, new_version_number)


def update_file(file_with_version, regex, new_version_number):
"""Replace the version number(s) in a file, based on a rgular expression."""
with open(file_with_version, 'r', encoding="UTF-8") as curf:
with open(file_with_version, "r", encoding="UTF-8") as curf:
lines = curf.readlines()
successfully_updated = False
for i, line in enumerate(lines):
Expand All @@ -92,18 +94,18 @@ def update_file(file_with_version, regex, new_version_number):
successfully_updated = True
if not successfully_updated:
raise RuntimeError(f"cannot determine version of {file_with_version}")
with open(file_with_version, 'w', encoding="UTF-8") as newf:
with open(file_with_version, "w", encoding="UTF-8") as newf:
for line in lines:
newf.write(line)


def setup_devbranch():
"""Adjust files after a release was published, i.e.,
apply the canonical deviations from main in develop.

Just changes files, all `git` commands are in the setup_devbranch.sh file.
"""
main_version = get_last_version().strip('v')
main_version = get_last_version().strip("v")
semver = main_version.split(".")
semver[-1] = f"{int(semver[-1]) + 1}-dev"
dev_version = ".".join(semver)
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ graft climada/*/test/data
graft climada/test/data
graft data
global-exclude .*
global-exclude *.py[co]
global-exclude *.py[co]
2 changes: 1 addition & 1 deletion climada.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"supported_exposures_types": ["litpop", "crop_production", "base"]
},
"log_level": "INFO"
}
}
2 changes: 1 addition & 1 deletion climada/data/demo/demo_emdat_impact_data_2020.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1073,4 +1073,4 @@ Dis No,Year,Seq,Disaster Group,Disaster Subgroup,Disaster Type,Disaster Subtype,
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,
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,,,,,,,,,
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,,,,,,,,,
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,,,,,,,,
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,,,,,,,,
2 changes: 1 addition & 1 deletion climada/data/system/GDP_TWN_IMF_WEO_data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ TWN,Taiwan Province of China,"Gross domestic product, current prices",U.S. dolla
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
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
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"International Monetary Fund, World Economic Outlook Database, October 2019",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"International Monetary Fund, World Economic Outlook Database, October 2019",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2 changes: 1 addition & 1 deletion climada/data/system/WEALTH2GDP_factors_CRI_2016.csv
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ Venezuela,VEN,0.29407,0.35328
Vietnam,VNM,1.23241,1.66724
Yemen,YEM,1.18584,1.76063
Zambia,ZMB,0.10663,0.32193
Zimbabwe,ZWE,0.20161,1.65566
Zimbabwe,ZWE,0.20161,1.65566
Loading