Skip to content

Commit

Permalink
Apply pylint changes to dev/release/*.py
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed Feb 7, 2024
1 parent a341af7 commit 7a13306
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 117 deletions.
33 changes: 23 additions & 10 deletions dev/releases/make_archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,27 @@
import grp
import gzip
import json
import os
import pwd
import re
import shutil
import subprocess
import sys
import tarfile

from utils import *
from utils import (
download_with_sha256,
error,
get_makefile_var,
notice,
patchfile,
run_with_log,
safe_git_fetch_tags,
verify_command_available,
verify_git_clean,
verify_git_repo,
working_directory,
)

# Insist on Python >= 3.6 for f-strings and other goodies
if sys.version_info < (3, 6):
Expand Down Expand Up @@ -56,11 +69,11 @@
error("make sure GAP has been compiled via './configure && make'")
notice(f"Detected GAP version {gapversion}")

if re.fullmatch(r"[1-9]+\.[0-9]+\.[0-9]+", gapversion) != None:
notice(f"--- THIS LOOKS LIKE A RELEASE ---")
if re.fullmatch(r"[1-9]+\.[0-9]+\.[0-9]+", gapversion) is not None:
notice("--- THIS LOOKS LIKE A RELEASE ---")
pkg_tag = f"v{gapversion}"
else:
notice(f"--- THIS LOOKS LIKE A NIGHTLY BUILD ---")
notice("--- THIS LOOKS LIKE A NIGHTLY BUILD ---")
pkg_tag = "latest"


Expand Down Expand Up @@ -195,14 +208,14 @@
subprocess.run(["./configure"], check=True)
subprocess.run(["make"], check=True)

notice(f"Constructing help-links JSON file")
notice("Constructing help-links JSON file")
json_output = subprocess.run(
[
"./gap",
"-r",
"--quiet",
"--quitonbreak",
f"dev/releases/HelpLinks-to-JSON.g",
"dev/releases/HelpLinks-to-JSON.g",
],
check=True,
capture_output=True,
Expand Down Expand Up @@ -257,12 +270,12 @@ def make_and_record_archive(
else:
error(f"unknown compression type {compression} (not gztar or zip)")

filename = f"{name}{ext}"
notice(f"Creating {filename}")
fname = f"{name}{ext}"
notice(f"Creating {fname}")
owner = pwd.getpwuid(0).pw_name
group = grp.getgrgid(0).gr_name
shutil.make_archive(name, compression, root_dir, base_dir, owner=owner, group=group)
manifest_list.append(filename)
manifest_list.append(fname)


# Create the remaining archives
Expand All @@ -280,7 +293,7 @@ def make_and_record_archive(
# If you create additional archives, make sure to add them to manifest_list!
manifest_filename = "MANIFEST"
notice(f"Creating the manifest, with name {manifest_filename}")
with open(manifest_filename, "w") as manifest:
with open(manifest_filename, "w", encoding="utf-8") as manifest:
for filename in manifest_list:
manifest.write(f"{filename}\n")

Expand Down
4 changes: 2 additions & 2 deletions dev/releases/make_github_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

with utils.working_directory(PATH_TO_RELEASE):
manifest_filename = "MANIFEST"
with open(manifest_filename, "r") as manifest_file:
with open(manifest_filename, "r", encoding="utf-8") as manifest_file:
manifest = manifest_file.read().splitlines()

notice(f"Contents of {manifest_filename}:")
Expand All @@ -67,7 +67,7 @@

# Now check that TAG_NAME and the created archives belong together
main_archive_name = "gap-" + VERSION + ".tar.gz"
if not main_archive_name in manifest:
if main_archive_name not in manifest:
error(f"Expected to find {main_archive_name} in MANIFEST, but did not!")

# Upload all assets to release
Expand Down
138 changes: 69 additions & 69 deletions dev/releases/release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,86 +247,86 @@ def changes_overview(
# Could also introduce some consistency checks here for wrong combinations of labels
filename = "releasenotes_" + new_version + ".md"
notice("Writing release notes into file " + filename)
relnotes_file = open(filename, "w")
prs_with_use_title = [pr for pr in prs if has_label(pr, "release notes: use title")]

# Write out all PRs with 'use title'
relnotes_file.write(
f"""
with open(filename, "w", encoding="utf-8") as relnotes_file:
prs_with_use_title = [
pr for pr in prs if has_label(pr, "release notes: use title")
]
# Write out all PRs with 'use title'
relnotes_file.write(
f"""
## GAP {new_version} (TODO insert date here, )
The following gives an overview of the changes compared to the previous
release. This list is not complete, many more internal or minor changes
were made, but we tried to only list those changes which we think might
affect some users directly.
"""
)

for priorityobject in prioritylist:
matches = [pr for pr in prs_with_use_title if has_label(pr, priorityobject[0])]
print("PRs with label '" + priorityobject[0] + "': ", len(matches))
if len(matches) == 0:
continue
relnotes_file.write("### " + priorityobject[1] + "\n\n")
for pr in matches:
relnotes_file.write(pr_to_md(pr))
prs_with_use_title.remove(pr)
relnotes_file.write("\n")
The following gives an overview of the changes compared to the previous
release. This list is not complete, many more internal or minor changes
were made, but we tried to only list those changes which we think might
affect some users directly.
# The remaining PRs have no "kind" or "topic" label from the priority list
# (may have other "kind" or "topic" label outside the priority list).
# Check their list in the release notes, and adjust labels if appropriate.
if len(prs_with_use_title) > 0:
relnotes_file.write("### Other changes\n\n")
for pr in prs_with_use_title:
relnotes_file.write(pr_to_md(pr))
relnotes_file.write("\n")

package_updates(relnotes_file, new_version)
"""
)

relnotes_file.close()
for priorityobject in prioritylist:
matches = [
pr for pr in prs_with_use_title if has_label(pr, priorityobject[0])
]
print("PRs with label '" + priorityobject[0] + "': ", len(matches))
if len(matches) == 0:
continue
relnotes_file.write("### " + priorityobject[1] + "\n\n")
for pr in matches:
relnotes_file.write(pr_to_md(pr))
prs_with_use_title.remove(pr)
relnotes_file.write("\n")

# The remaining PRs have no "kind" or "topic" label from the priority list
# (may have other "kind" or "topic" label outside the priority list).
# Check their list in the release notes, and adjust labels if appropriate.
if len(prs_with_use_title) > 0:
relnotes_file.write("### Other changes\n\n")
for pr in prs_with_use_title:
relnotes_file.write(pr_to_md(pr))
relnotes_file.write("\n")

package_updates(relnotes_file, new_version)

notice("Release notes were written into file " + filename)
with open(
"unsorted_PRs_" + new_version + ".md", "w", encoding="utf-8"
) as unsorted_file:
# Report PRs that have to be updated before inclusion into release notes.
unsorted_file.write("### " + "release notes: to be added" + "\n\n")
unsorted_file.write(
"If there are any PRs listed below, check their title and labels.\n"
)
unsorted_file.write(
'When done, change their label to "release notes: use title".\n\n'
)

unsorted_file = open("unsorted_PRs_" + new_version + ".md", "w")

# Report PRs that have to be updated before inclusion into release notes.
unsorted_file.write("### " + "release notes: to be added" + "\n\n")
unsorted_file.write(
"If there are any PRs listed below, check their title and labels.\n"
)
unsorted_file.write(
'When done, change their label to "release notes: use title".\n\n'
)

for pr in prs:
if has_label(pr, "release notes: to be added"):
unsorted_file.write(pr_to_md(pr))
for pr in prs:
if has_label(pr, "release notes: to be added"):
unsorted_file.write(pr_to_md(pr))

prs = [pr for pr in prs if not has_label(pr, "release notes: to be added")]
prs = [pr for pr in prs if not has_label(pr, "release notes: to be added")]

unsorted_file.write("\n")
unsorted_file.write("\n")

# Report PRs that have neither "to be added" nor "added" or "use title" label
unsorted_file.write("### Uncategorized PR" + "\n\n")
unsorted_file.write(
"If there are any PRs listed below, either apply the same steps\n"
)
unsorted_file.write(
'as above, or change their label to "release notes: not needed".\n\n'
)
# Report PRs that have neither "to be added" nor "added" or "use title" label
unsorted_file.write("### Uncategorized PR" + "\n\n")
unsorted_file.write(
"If there are any PRs listed below, either apply the same steps\n"
)
unsorted_file.write(
'as above, or change their label to "release notes: not needed".\n\n'
)

for pr in prs:
# we need to use both old "release notes: added" label and
# the newly introduced in "release notes: use title" label
# since both label may appear in GAP 4.12.0 changes overview
if not (
has_label(pr, "release notes: added")
or has_label(pr, "release notes: use title")
):
unsorted_file.write(pr_to_md(pr))
unsorted_file.close()
for pr in prs:
# we need to use both old "release notes: added" label and
# the newly introduced in "release notes: use title" label
# since both label may appear in GAP 4.12.0 changes overview
if not (
has_label(pr, "release notes: added")
or has_label(pr, "release notes: use title")
):
unsorted_file.write(pr_to_md(pr))


def main(new_version: str) -> None:
Expand Down
24 changes: 13 additions & 11 deletions dev/releases/update_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ def download_asset_by_name(asset_name: str, writedir: str) -> None:
utils.download_with_sha256(url, asset_name)


def extract_tarball(tarball: str) -> None:
notice(f"Extracting {tarball} . . .")
with tarfile.open(tarball) as tar:
def extract_tarball(tball: str) -> None:
notice(f"Extracting {tball} . . .")
with tarfile.open(tball) as tar:
try:
tar.extractall()
except:
error(f"Failed to extract {tarball}!")
error(f"Failed to extract {tball}!")


def get_date_from_configure_ac(gaproot: str) -> str:
with open(f"{gaproot}/configure.ac", "r") as configure_ac:
with open(f"{gaproot}/configure.ac", "r", encoding="utf-8") as configure_ac:
filedata = configure_ac.read()
try: # Expect date in YYYY-MM-DD format
release_date = re.search(
"\[gap_releaseday\], \[(\d{4}-\d{2}-\d{2})\]", filedata
r"\[gap_releaseday\], \[(\d{4}-\d{2}-\d{2})\]", filedata
).group(1)
release_date = datetime.datetime.strptime(release_date, "%Y-%m-%d")
return release_date.strftime("%d %B %Y")
Expand All @@ -109,7 +109,7 @@ def download_and_extract_json_gz_asset(asset_name: str, dest: str) -> None:
download_asset_by_name(asset_name, tmpdir)
with utils.working_directory(tmpdir):
with gzip.open(asset_name, "rt", encoding="utf-8") as file_in:
with open(dest, "w") as file_out:
with open(dest, "w", encoding="utf-8") as file_out:
shutil.copyfileobj(file_in, file_out)


Expand Down Expand Up @@ -155,12 +155,12 @@ def download_and_extract_json_gz_asset(asset_name: str, dest: str) -> None:
known_release = os.path.isfile(f"_Releases/{version}.html")
newest_release = releases.index(release) == 0
if known_release:
notice(f"I have seen this release before")
notice("I have seen this release before")
elif newest_release:
notice(f"This is a new release to me, and it has the biggest version number")
notice("This is a new release to me, and it has the biggest version number")
else:
notice(
f"This is a new release to me, but I know about releases with bigger version numbers"
"This is a new release to me, but I know about releases with bigger version numbers"
)

# For all releases, record the assets (in case they were deleted/updated/added)
Expand Down Expand Up @@ -237,5 +237,7 @@ def download_and_extract_json_gz_asset(asset_name: str, dest: str) -> None:
with open(f"{pwd}/_data/package-infos/{version_safe}.json", "rb") as infile:
data = json.loads(infile.read())
for pkg in data:
with open(f"{pwd}/_Packages/{pkg}.html", "w+") as pkg_file:
with open(
f"{pwd}/_Packages/{pkg}.html", "w+", encoding="utf-8"
) as pkg_file:
pkg_file.write(f"---\ntitle: {data[pkg]['PackageName']}\n---\n")
Loading

0 comments on commit 7a13306

Please sign in to comment.