Skip to content

Commit

Permalink
py-fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Apr 17, 2024
1 parent edbc705 commit a51a834
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
10 changes: 6 additions & 4 deletions scripts/generate_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,7 +40,7 @@
class PrInfo:
gh_user_name: str
pr_title: str
labels: List[str]
labels: list[str]


@dataclass
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions scripts/template_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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__)))

Expand Down

0 comments on commit a51a834

Please sign in to comment.