diff --git a/.github/scripts/check_duplicates.py b/.github/scripts/check_duplicates.py deleted file mode 100644 index 9c919414..00000000 --- a/.github/scripts/check_duplicates.py +++ /dev/null @@ -1,51 +0,0 @@ -import sys - - -def find_duplicate_keys(file_path): - """ - Finds duplicate keys in a properties file and returns their occurrences. - - This function reads a properties file, identifies any keys that occur more than - once, and returns a dictionary with these keys and the line numbers of their occurrences. - - Parameters: - file_path (str): The path to the properties file to be checked. - - Returns: - dict: A dictionary where each key is a duplicated key in the file, and the value is a list - of line numbers where the key occurs. - """ - with open(file_path, "r", encoding="utf-8") as file: - lines = file.readlines() - - keys = {} - duplicates = {} - - for line_number, line in enumerate(lines, start=1): - line = line.strip() - if line and not line.startswith("#") and "=" in line: - key = line.split("=", 1)[0].strip() - if key in keys: - # If the key already exists, add the current line number - duplicates.setdefault(key, []).append(line_number) - # Also add the first instance of the key if not already done - if keys[key] not in duplicates[key]: - duplicates[key].insert(0, keys[key]) - else: - # Store the line number of the first instance of the key - keys[key] = line_number - - return duplicates - - -if __name__ == "__main__": - failed = False - for ar in sys.argv[1:]: - duplicates = find_duplicate_keys(ar) - if duplicates: - for key, lines in duplicates.items(): - lines_str = ", ".join(map(str, lines)) - print(f"{key} duplicated in {ar} on lines {lines_str}") - failed = True - if failed: - sys.exit(1) diff --git a/.github/scripts/check_tabulator.py b/.github/scripts/check_tabulator.py deleted file mode 100644 index dea57092..00000000 --- a/.github/scripts/check_tabulator.py +++ /dev/null @@ -1,85 +0,0 @@ -"""check_tabulator.py""" - -import argparse -import sys - - -def check_tabs(file_path): - """ - Checks for tabs in the specified file. - - Args: - file_path (str): The path to the file to be checked. - - Returns: - bool: True if tabs are found, False otherwise. - """ - with open(file_path, "r", encoding="utf-8") as file: - content = file.read() - - if "\t" in content: - print(f"Tab found in {file_path}") - return True - return False - - -def replace_tabs_with_spaces(file_path, replace_with=" "): - """ - Replaces tabs with a specified number of spaces in the file. - - Args: - file_path (str): The path to the file where tabs will be replaced. - replace_with (str): The character(s) to replace tabs with. Defaults to two spaces. - """ - with open(file_path, "r", encoding="utf-8") as file: - content = file.read() - - updated_content = content.replace("\t", replace_with) - - with open(file_path, "w", encoding="utf-8") as file: - file.write(updated_content) - - -def main(): - """ - Main function to replace tabs with spaces in the provided files. - The replacement character and files to check are taken from command line arguments. - """ - # Create ArgumentParser instance - parser = argparse.ArgumentParser( - description="Replace tabs in files with specified characters." - ) - - # Define optional argument `--replace_with` - parser.add_argument( - "--replace_with", - default=" ", - help="Character(s) to replace tabs with. Default is two spaces.", - ) - - # Define argument for file paths - parser.add_argument("files", metavar="FILE", nargs="+", help="Files to process.") - - # Parse arguments - args = parser.parse_args() - - # Extract replacement characters and files from the parsed arguments - replace_with = args.replace_with - files_checked = args.files - - error = False - - for file_path in files_checked: - if check_tabs(file_path): - replace_tabs_with_spaces(file_path, replace_with) - error = True - - if error: - print("Error: Originally found tabs in HTML files, now replaced.") - sys.exit(1) - - sys.exit(0) - - -if __name__ == "__main__": - main() diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index e0d94e6a..b71bba01 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -2,6 +2,8 @@ name: Pre-commit on: workflow_dispatch: + schedule: + - cron: "0 0 * * 1" permissions: contents: read diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5256f897..9edd51a9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,10 +6,10 @@ repos: args: - --fix - --line-length=127 - files: ^((.github/scripts|scripts)/.+)?[^/]+\.py$ + files: ^((\.github/scripts|scripts)/.+)?[^/]+\.py$ exclude: (split_photos.py) - id: ruff-format - files: ^((.github/scripts|scripts)/.+)?[^/]+\.py$ + files: ^((\.github/scripts|scripts)/.+)?[^/]+\.py$ exclude: (split_photos.py) - repo: https://github.com/codespell-project/codespell rev: v2.3.0 @@ -19,7 +19,7 @@ repos: - --ignore-words-list= - --skip="./.*,*.csv,*.json,*.ambr" - --quiet-level=2 - files: \.(properties|html|css|js|py|md)$ + files: \.(html|css|js|py|md)$ exclude: (.vscode|.devcontainer|src/main/resources|Dockerfile|.*/pdfjs.*|.*/thirdParty.*|bootstrap.*|.*\.min\..*|.*diff\.js) - repo: https://github.com/gitleaks/gitleaks rev: v8.22.0 @@ -35,23 +35,7 @@ repos: hooks: - id: end-of-file-fixer files: ^.*(\.js|\.java|\.py|\.yml)$ - exclude: ^(.*/pdfjs.*|.*/thirdParty.*|bootstrap.*|.*\.min\..*|.*diff\.js$) + exclude: ^(.*/pdfjs.*|.*/thirdParty.*|bootstrap.*|.*\.min\..*|.*diff\.js|\.github/workflows/.*$) - id: trailing-whitespace files: ^.*(\.js|\.java|\.py|\.yml)$ - exclude: ^(.*/pdfjs.*|.*/thirdParty.*|bootstrap.*|.*\.min\..*|.*diff\.js$) - - - repo: local - hooks: - - id: check-duplicate-properties-keys - name: Check Duplicate Properties Keys - entry: python .github/scripts/check_duplicates.py - language: python - files: ^(src)/.+\.properties$ - - id: check-html-tabs - name: Check HTML for tabs - description: Ensures HTML/CSS/JS files do not contain tab characters - # args: ["--replace_with= "] - entry: python .github/scripts/check_tabulator.py - language: python - exclude: ^(.*/pdfjs.*|.*/thirdParty.*|bootstrap.*|.*\.min\..*|.*diff\.js$) - files: ^.*(\.html|\.css|\.js)$ \ No newline at end of file + exclude: ^(.*/pdfjs.*|.*/thirdParty.*|bootstrap.*|.*\.min\..*|.*diff\.js|\.github/workflows/.*$) diff --git a/scripts/counter_translation.py b/scripts/counter_translation.py index ba4ab67b..789cb7c1 100644 --- a/scripts/counter_translation.py +++ b/scripts/counter_translation.py @@ -75,7 +75,7 @@ def write_readme(progress_list: list[tuple[str, int]]) -> None: f"![{value}%](https://geps.dev/progress/{value})", ) - with open("README.md", "w", encoding="utf-8") as file: + with open("README.md", "w", encoding="utf-8", newline="\n") as file: file.writelines(content) @@ -196,7 +196,7 @@ def compare_files( ) ) ignore_translation = convert_to_multiline(sort_ignore_translation) - with open(ignore_translation_file, "w", encoding="utf-8") as file: + with open(ignore_translation_file, "w", encoding="utf-8", newline="\n") as file: file.write(tomlkit.dumps(ignore_translation)) unique_data = list(set(result_list))