From 6ba71577580a4a1a7fbf12756bb32d24a04d3dc2 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 15:54:43 +0200 Subject: [PATCH 01/10] GHA workflow now calls Python tooling within the virtual environment pytest did not use the legacy Python version, instead using a local newer version Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- .github/workflows/python-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 2bc891cb..df57af4e 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -73,10 +73,10 @@ jobs: python-version: ${{ matrix.python-version }} - name: Lint with flake8 run: | - flake8 . --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160 + python -m flake8 . --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160 - name: Test with pytest run: | - pytest + python -m pytest - name: Install run: | python setup.py sdist bdist_wheel From 984ff140f26094634a63c5d89daaf4faa8959851 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 15:58:56 +0200 Subject: [PATCH 02/10] Added Pyright and Pyflakes to legacy Python GHA workflow Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- .github/actions/set-up-legacy-python/action.yml | 2 +- .github/workflows/python-tests.yml | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/actions/set-up-legacy-python/action.yml b/.github/actions/set-up-legacy-python/action.yml index 791c7db8..f736eba1 100644 --- a/.github/actions/set-up-legacy-python/action.yml +++ b/.github/actions/set-up-legacy-python/action.yml @@ -22,6 +22,6 @@ runs: command: pip install -U pip - name: Install dependencies run: | - python -m pip install flake8 pytest setuptools wheel + python -m pip install flake8 pyright pyflakes pytest setuptools wheel if [ -f requirements.txt ]; then pip install -r requirements.txt; fi shell: bash diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index df57af4e..9f069ab0 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -74,6 +74,12 @@ jobs: - name: Lint with flake8 run: | python -m flake8 . --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160 + - name: Lint with pyright (type checking) + run: | + python -m pyright cfbs + - name: Lint with pyflakes + run: | + python -m pyflakes cfbs - name: Test with pytest run: | python -m pytest From 8759791f9b2120a070835ae95a0dc26592bc039b Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 17:20:46 +0200 Subject: [PATCH 03/10] Replaced `Union[X, None]` with `Optional[X]` Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/args.py | 26 +++++++++++++------------- cfbs/cfbs_types.py | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cfbs/args.py b/cfbs/args.py index a90e3520..8676760c 100644 --- a/cfbs/args.py +++ b/cfbs/args.py @@ -1,6 +1,6 @@ import argparse import os -from typing import List, Union +from typing import List, Optional from cfbs import commands from cfbs.utils import cache, CFBSExitError @@ -9,31 +9,31 @@ class ArgsTypesNamespace(argparse.Namespace): """Manual type hints to args attributes""" - command: Union[str, None] + command: Optional[str] args: List[str] loglevel: str manual: bool version: bool force: bool non_interactive: bool - index: Union[str, None] + index: Optional[str] check: bool - checksum: Union[str, None] + checksum: Optional[str] keep_order: bool - git: Union[bool, None] - git_user_name: Union[str, None] - git_user_email: Union[str, None] - git_commit_message: Union[str, None] + git: Optional[bool] + git_user_name: Optional[str] + git_user_email: Optional[str] + git_commit_message: Optional[str] ignore_versions_json: bool omit_download: bool check_against_git: bool - minimum_version: Union[str, None] - to_json: Union[str, None] - reference_version: Union[str, None] - masterfiles_dir: Union[str, None] + minimum_version: Optional[str] + to_json: Optional[str] + reference_version: Optional[str] + masterfiles_dir: Optional[str] ignored_path_components: List[str] offline: bool - masterfiles: Union[str, None] + masterfiles: Optional[str] def get_args(): diff --git a/cfbs/cfbs_types.py b/cfbs/cfbs_types.py index 0e9bf0ea..9d01fcd4 100644 --- a/cfbs/cfbs_types.py +++ b/cfbs/cfbs_types.py @@ -1,4 +1,4 @@ -from typing import List, NamedTuple, Union +from typing import List, NamedTuple, Optional CFBSCommandExitCode = int @@ -6,5 +6,5 @@ class CFBSCommandGitResult(NamedTuple): return_code: int do_commit: bool = True - commit_message: Union[str, None] = None + commit_message: Optional[str] = None commit_files: List[str] = [] From ab3000648d90f607737d0b6868352cdf9226a76b Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 17:28:49 +0200 Subject: [PATCH 04/10] Rewrote `CFBSCommandGitResult` for compatibility with Python 3.5 Ticket: ENT-13212 Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/cfbs_types.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/cfbs/cfbs_types.py b/cfbs/cfbs_types.py index 9d01fcd4..b5421556 100644 --- a/cfbs/cfbs_types.py +++ b/cfbs/cfbs_types.py @@ -3,8 +3,34 @@ CFBSCommandExitCode = int -class CFBSCommandGitResult(NamedTuple): - return_code: int - do_commit: bool = True - commit_message: Optional[str] = None - commit_files: List[str] = [] +# The usual, not `class`-based, method of defining a `typing.NamedTuple` type does not support default values, +# and it seems that the `class`-based method's constructor does not work with the Python 3.5 PEP 484[1] comment type hints. +# Thus, for compatibility with Python 3.5, a more verbose definition of `CFBSCommandGitResult` is used. +# This commit can be reverted, and type hints returned to the PEP 526 style type hints[2], once the supported Python version becomes 3.6+. +# References: +# [1]: https://peps.python.org/pep-0484/#type-comments +# [2]: https://peps.python.org/pep-0526/#class-and-instance-variable-annotations +_CFBSCommandGitResult = NamedTuple( + "_CFBSCommandGitResult", + [ + ("return_code", int), + ("do_commit", bool), + ("commit_message", Optional[str]), + ("commit_files", List[str]), + ], +) + + +class CFBSCommandGitResult(_CFBSCommandGitResult): + def __new__( + cls, + return_code: int, + do_commit: bool = True, + commit_message: Optional[str] = None, + commit_files: Optional[List[str]] = None, + ): + if commit_files is None: + commit_files = [] + return super(CFBSCommandGitResult, cls).__new__( + cls, return_code, do_commit, commit_message, commit_files + ) From fdf40dab7f52ac3c5ff58d498bc89975292d7bf0 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 18:02:59 +0200 Subject: [PATCH 05/10] Fixed potential Mutable Default Argument bug Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/analyze.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cfbs/analyze.py b/cfbs/analyze.py index 1784d3b9..5a57349e 100644 --- a/cfbs/analyze.py +++ b/cfbs/analyze.py @@ -73,12 +73,14 @@ def checksums_files( files_dir_path, checksums_dict=None, files_dict=None, - ignored_path_components=[], + ignored_path_components=None, ): if checksums_dict is None: checksums_dict = copy.deepcopy(DEFAULT_CHECKSUMS_DICT) if files_dict is None: files_dict = copy.deepcopy(DEFAULT_FILES_DICT) + if ignored_path_components is None: + ignored_path_components = [] for root, _, files in os.walk(files_dir_path): for name in files: From 9e17b59eba6b671fbaa1288f3708fea4cf4fd749 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 18:04:24 +0200 Subject: [PATCH 06/10] Corrected incorrect type hint Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/args.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfbs/args.py b/cfbs/args.py index 8676760c..9c86bfe4 100644 --- a/cfbs/args.py +++ b/cfbs/args.py @@ -31,7 +31,7 @@ class ArgsTypesNamespace(argparse.Namespace): to_json: Optional[str] reference_version: Optional[str] masterfiles_dir: Optional[str] - ignored_path_components: List[str] + ignored_path_components: Optional[List[str]] offline: bool masterfiles: Optional[str] From aece23f6c87225e2e1fd2c53bd3192274739b2e1 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 18:07:56 +0200 Subject: [PATCH 07/10] Rewrote CFBS args type hints for compatibility with Python 3.5 Ticket: ENT-13212 Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/args.py | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/cfbs/args.py b/cfbs/args.py index 9c86bfe4..21c1450b 100644 --- a/cfbs/args.py +++ b/cfbs/args.py @@ -9,31 +9,33 @@ class ArgsTypesNamespace(argparse.Namespace): """Manual type hints to args attributes""" - command: Optional[str] - args: List[str] - loglevel: str - manual: bool - version: bool - force: bool - non_interactive: bool - index: Optional[str] - check: bool - checksum: Optional[str] - keep_order: bool - git: Optional[bool] - git_user_name: Optional[str] - git_user_email: Optional[str] - git_commit_message: Optional[str] - ignore_versions_json: bool - omit_download: bool - check_against_git: bool - minimum_version: Optional[str] - to_json: Optional[str] - reference_version: Optional[str] - masterfiles_dir: Optional[str] - ignored_path_components: Optional[List[str]] - offline: bool - masterfiles: Optional[str] + # PEP 484 style type hints for compatibility with Python 3.5. + # This commit can be reverted, and type hints returned to the PEP 526 style type hints, once the supported Python version becomes 3.6+. + command = None # type: Optional[str] + args = [] # type: List[str] + loglevel = "warning" # type: str + manual = False # type: bool + version = False # type: bool + force = False # type: bool + non_interactive = False # type: bool + index = None # type: Optional[str] + check = False # type: bool + checksum = None # type: Optional[str] + keep_order = False # type: bool + git = None # type: Optional[bool] + git_user_name = None # type: Optional[str] + git_user_email = None # type: Optional[str] + git_commit_message = None # type: Optional[str] + ignore_versions_json = False # type: bool + omit_download = False # type: bool + check_against_git = False # type: bool + minimum_version = None # type: Optional[str] + to_json = None # type: Optional[str] + reference_version = None # type: Optional[str] + masterfiles_dir = None # type: Optional[str] + ignored_path_components = None # type: Optional[List[str]] + offline = False # type: bool + masterfiles = None # type: Optional[str] def get_args(): From 75bb72839173d3ececfb3760f18731cbde6e072d Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 18:13:01 +0200 Subject: [PATCH 08/10] Ignore incorrect flake8 unused import error Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/args.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfbs/args.py b/cfbs/args.py index 21c1450b..f9f53139 100644 --- a/cfbs/args.py +++ b/cfbs/args.py @@ -1,6 +1,6 @@ import argparse import os -from typing import List, Optional +from typing import List, Optional # noqa: F401 from cfbs import commands from cfbs.utils import cache, CFBSExitError From 2d59a7f441d6c72d3c980d90ed6adf0e63803eb2 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 18:29:29 +0200 Subject: [PATCH 09/10] Removed Pyflakes It appears to be redundant when already using flake8, and it seems to be impossible to ignore an incorrect error it generates. Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- .github/actions/set-up-legacy-python/action.yml | 2 +- .github/workflows/python-tests.yml | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/actions/set-up-legacy-python/action.yml b/.github/actions/set-up-legacy-python/action.yml index f736eba1..af693ff9 100644 --- a/.github/actions/set-up-legacy-python/action.yml +++ b/.github/actions/set-up-legacy-python/action.yml @@ -22,6 +22,6 @@ runs: command: pip install -U pip - name: Install dependencies run: | - python -m pip install flake8 pyright pyflakes pytest setuptools wheel + python -m pip install flake8 pyright pytest setuptools wheel if [ -f requirements.txt ]; then pip install -r requirements.txt; fi shell: bash diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 9f069ab0..3cfe0c02 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -30,7 +30,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install flake8 pyright pyflakes pytest setuptools wheel + python -m pip install flake8 pyright pytest setuptools wheel if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | @@ -38,9 +38,6 @@ jobs: - name: Lint with pyright (type checking) run: | pyright cfbs - - name: Lint with pyflakes - run: | - pyflakes cfbs - name: Test with pytest run: | pytest @@ -77,9 +74,6 @@ jobs: - name: Lint with pyright (type checking) run: | python -m pyright cfbs - - name: Lint with pyflakes - run: | - python -m pyflakes cfbs - name: Test with pytest run: | python -m pytest From 645e704a2e0e62080c9f8753a689239847816d1f Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 2 Sep 2025 18:54:38 +0200 Subject: [PATCH 10/10] Added type hints where Python 3.6's Pyright was getting confused Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/analyze.py | 2 +- cfbs/commands.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cfbs/analyze.py b/cfbs/analyze.py index 5a57349e..0341bb4e 100644 --- a/cfbs/analyze.py +++ b/cfbs/analyze.py @@ -232,7 +232,7 @@ def mpf_normalized_path(path, is_parentpath: bool, masterfiles_dir): `path` should be a path inside the masterfiles directory (or inside the parent directory, if `is_parentpath` is `True`). """ # downloaded MPF release information filepaths always have forward slashes - norm_path = path.replace(os.sep, "/") + norm_path = path.replace(os.sep, "/") # type: str if is_parentpath: if norm_path.startswith(masterfiles_dir + "/"): diff --git a/cfbs/commands.py b/cfbs/commands.py index cd8a80d2..d2b26eeb 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -205,7 +205,7 @@ def init_command( "description": description, "build": [], } - ) + ) # type: OrderedDict[str, str | List | bool] if index: config["index"] = index