diff --git a/scripts/generate_changelog.py b/scripts/generate_changelog.py index 516e88b..1c7e50b 100755 --- a/scripts/generate_changelog.py +++ b/scripts/generate_changelog.py @@ -8,13 +8,15 @@ though it often needs some manual editing too. """ +from __future__ import annotations + import argparse import multiprocessing import os import re import sys from dataclasses import dataclass -from typing import Any, List, Optional +from typing import Any, Optional import requests from git import Repo # pip install GitPython @@ -38,7 +40,7 @@ class PrInfo: gh_user_name: str pr_title: str - labels: List[str] + labels: list[str] @dataclass @@ -57,7 +59,7 @@ def get_github_token() -> str: token_file = os.path.join(home_dir, ".githubtoken") try: - with open(token_file) as f: + with open(token_file, encoding="utf8") as f: token = f.read().strip() return token except Exception: @@ -109,7 +111,7 @@ def remove_prefix(text: str, prefix: str) -> str: return text # or whatever -def print_section(crate: str, items: List[str]) -> None: +def print_section(crate: str, items: list[str]) -> None: if 0 < len(items): print(f"#### {crate}") for line in items: diff --git a/scripts/template_update.py b/scripts/template_update.py index d781c9e..d550d24 100755 --- a/scripts/template_update.py +++ b/scripts/template_update.py @@ -14,11 +14,12 @@ You can also use `--dry-run` to see what would happen without actually changing anything. """ +from __future__ import annotations + import argparse import os import shutil import tempfile -from typing import Set from git import Repo @@ -62,14 +63,14 @@ } -def parse_languages(lang_str: str) -> Set[str]: +def parse_languages(lang_str: str) -> set[str]: languages = lang_str.split(",") if lang_str else [] for lang in languages: assert lang in ["cpp", "python", "rust"], f"Unsupported language: {lang}" return set(languages) -def calc_deny_set(languages: Set[str]) -> Set[str]: +def calc_deny_set(languages: set[str]) -> set[str]: """The set of files to delete/ignore.""" files_to_delete = CPP_FILES | PYTHON_FILES | RUST_FILES if "cpp" in languages: @@ -81,13 +82,13 @@ def calc_deny_set(languages: Set[str]) -> Set[str]: return files_to_delete -def init(languages: Set[str], dry_run: bool) -> None: +def init(languages: set[str], dry_run: bool) -> None: print("Removing all language-specific files not needed for languages {languages}.") files_to_delete = calc_deny_set(languages) delete_files_and_folder(files_to_delete, dry_run) -def delete_files_and_folder(paths: Set[str], dry_run: bool) -> None: +def delete_files_and_folder(paths: set[str], dry_run: bool) -> None: repo_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) for path in paths: full_path = os.path.join(repo_path, path) @@ -102,7 +103,7 @@ def delete_files_and_folder(paths: Set[str], dry_run: bool) -> None: shutil.rmtree(full_path) -def update(languages: Set[str], dry_run: bool) -> None: +def update(languages: set[str], dry_run: bool) -> None: files_to_ignore = calc_deny_set(languages) repo_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))