From 7b231012efec1829c4745366f6c307bf18a1fd98 Mon Sep 17 00:00:00 2001 From: jj Date: Sun, 27 Jul 2025 20:34:47 +0000 Subject: [PATCH] scripts: fix lint errors utils: lint helium_version: fix lint errors name_substitution: fix lint errors devutils: lint --- devutils/update_lists.py | 1 - devutils/update_platform_patches.py | 1 - utils/domain_substitution.py | 1 - utils/helium_version.py | 40 +++++++++++--- utils/name_substitution.py | 86 ++++++++++++++++++----------- utils/replace_resources.py | 18 +++++- 6 files changed, 102 insertions(+), 45 deletions(-) diff --git a/devutils/update_lists.py b/devutils/update_lists.py index 6f3d61df..f43a04b5 100755 --- a/devutils/update_lists.py +++ b/devutils/update_lists.py @@ -7,7 +7,6 @@ # Copyright (c) 2019 The ungoogled-chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE.ungoogled_chromium file. - """ Update binary pruning and domain substitution lists automatically. diff --git a/devutils/update_platform_patches.py b/devutils/update_platform_patches.py index afb67347..ce25613d 100755 --- a/devutils/update_platform_patches.py +++ b/devutils/update_platform_patches.py @@ -8,7 +8,6 @@ # Copyright (c) 2019 The ungoogled-chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE.ungoogled_chromium file. - """ Utility to ease the updating of platform patches against ungoogled-chromium's patches """ diff --git a/utils/domain_substitution.py b/utils/domain_substitution.py index 22d2c172..a27ece8c 100755 --- a/utils/domain_substitution.py +++ b/utils/domain_substitution.py @@ -8,7 +8,6 @@ # Copyright (c) 2019 The ungoogled-chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE.ungoogled_chromium file. - """ Substitute domain names in the source tree with blockable strings. """ diff --git a/utils/helium_version.py b/utils/helium_version.py index 14659523..d8f75a9d 100644 --- a/utils/helium_version.py +++ b/utils/helium_version.py @@ -1,21 +1,42 @@ +#!/usr/bin/env python3 + +# Copyright 2025 The Helium Authors +# You can use, redistribute, and/or modify this source code under +# the terms of the GPL-3.0 license that can be found in the LICENSE file. +""" +Script to generate Helium version numbers +and inject them into the Chromium build tree. +""" + import argparse from pathlib import Path CHROME_VERSION_BASE = 136 + def get_version_part(path): - with open(path, "r") as file: + """ + Gets the (first) digit representing a part of + the version from a particular file. + """ + with open(path, "r", encoding="utf-8") as file: return int(file.readline().split(".")[0].strip()) + def append_version(file, name, version): + """Appends a version part to the chromium VERSION file""" file.write(f"{name}={version}\n") + def check_existing_version(path): - with open(path, "r") as f: - if "HELIUM" in f.read(): - raise Exception("file already contains helium versioning") + """Verifies that the version has not yet been added to the build tree""" + with open(path, "r", encoding="utf-8") as file: + if "HELIUM" in file.read(): + raise ValueError("file already contains helium versioning") + def parse_args(): + """Argument parsing""" parser = argparse.ArgumentParser() parser.add_argument("--tree", type=Path, required=True) parser.add_argument("--platform-tree", type=Path, required=True) @@ -24,21 +45,25 @@ def parse_args(): args = parser.parse_args() return (args.tree, args.platform_tree, args.chromium_tree, args.print) + def get_version_parts(tree, platform_tree): + """Compiles all the version parts into the full version""" version_paths = { "HELIUM_MAJOR": tree / "version.txt", "HELIUM_MINOR": tree / "chromium_version.txt", "HELIUM_PATCH": tree / "revision.txt", "HELIUM_PLATFORM": platform_tree / "revision.txt", } - + version_parts = {} for name, path in version_paths.items(): delta = 0 if name != "HELIUM_MINOR" else -CHROME_VERSION_BASE version_parts[name] = get_version_part(path) + delta return version_parts + def main(): + """CLI entrypoint""" tree, platform_tree, chromium_tree, should_print = parse_args() version_parts = get_version_parts(tree, platform_tree) @@ -48,9 +73,10 @@ def main(): else: chrome_version_path = chromium_tree / "chrome/VERSION" check_existing_version(chrome_version_path) - with open(chrome_version_path, "a") as f: + with open(chrome_version_path, "a", encoding="utf-8") as file: for name, version in version_parts.items(): - append_version(f, name, version) + append_version(file, name, version) + if __name__ == "__main__": main() diff --git a/utils/name_substitution.py b/utils/name_substitution.py index 1bdd475f..ad2ec1b6 100644 --- a/utils/name_substitution.py +++ b/utils/name_substitution.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 + # Copyright 2025 The Helium Authors # You can use, redistribute, and/or modify this source code under # the terms of the GPL-3.0 license that can be found in the LICENSE file. +"""Script to replace instances of Chrome/Chromium with Helium""" from pathlib import Path import argparse @@ -12,8 +14,8 @@ import re REPLACEMENT_REGEXES_STR = [ # stuff we don't want to replace - (r'(\w+) Root Program', r'\1_unreplace Root Program'), - (r'(\w+) Web( S|s)tore', r'\1_unreplace Web Store'), + (r'(\w+) Root Program', r'\1_unreplace Root Program'), + (r'(\w+) Web( S|s)tore', r'\1_unreplace Web Store'), (r'(\w+) Remote Desktop', r'\1_unreplace Remote Desktop'), (r'("BEGIN_LINK_CHROMIUM")(.*?Chromium)(.*? ") + print( + "Usage: python3 replace_resources.py " \ + " " + ) sys.exit(1) resource_list = sys.argv[1] @@ -56,5 +69,6 @@ def main(): copy_resources(resource_list, resource_dir, chromium_dir) + if __name__ == "__main__": main()