From 6cd81522629ad5cb252e94510a9193aed351dd80 Mon Sep 17 00:00:00 2001 From: mulhern Date: Mon, 2 Jun 2025 17:04:29 -0400 Subject: [PATCH 1/5] Remove batch_cancel.py script This script has been unused for years since GitHub has become more secure. Signed-off-by: mulhern --- misc_scripts/batch_cancel.py | 51 ------------------------------------ 1 file changed, 51 deletions(-) delete mode 100755 misc_scripts/batch_cancel.py diff --git a/misc_scripts/batch_cancel.py b/misc_scripts/batch_cancel.py deleted file mode 100755 index 147d2465..00000000 --- a/misc_scripts/batch_cancel.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/python3 -""" -Script for batch cancelling Github Actions CI jobs. -""" - -# isort: STDLIB -import itertools -import os -import sys -from getpass import getpass - -# isort: THIRDPARTY -from github import Github - - -def main(): - """ - Main function - """ - if len(sys.argv) < 4: - print(f"USAGE: {sys.argv[0]} ") - print( - "GITHUB_ORG_OR_USER: Github user or organization in which the repo is located" - ) - print("GITHUB_REPO: Name of the Github repo") - print("PR_USER: Name of the user who opened the PR") - raise RuntimeError("Three positional arguments are required") - user = sys.argv[1] - repo = sys.argv[2] - actions_user = sys.argv[3] - - api_key = os.environ.get("GITHUB_API_KEY") - if api_key is None: - api_key = getpass("Github API key: ") - - github = Github(api_key) - repo = github.get_repo(f"{user}/{repo}") - runs = itertools.chain( - repo.get_workflow_runs(actor=actions_user, status="queued"), - repo.get_workflow_runs(actor=actions_user, status="in_progress"), - ) - for run in runs: - run.cancel() - - -if __name__ == "__main__": - try: - main() - except Exception as err: # pylint: disable=broad-except - print(err) - sys.exit(1) From 04bf1787cb14b6974aef8e9538dd2246e0d46c30 Mon Sep 17 00:00:00 2001 From: mulhern Date: Mon, 2 Jun 2025 17:14:54 -0400 Subject: [PATCH 2/5] Allow reportOptionalMemberAcces pyright lint pyright can not figure out that stdout must not be None since it is piped. Signed-off-by: mulhern --- release_management/_utils.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/release_management/_utils.py b/release_management/_utils.py index cd3b9d3a..950c1290 100755 --- a/release_management/_utils.py +++ b/release_management/_utils.py @@ -60,7 +60,11 @@ def calc_release_suffix(): """ command = ["git", "rev-parse", "--short=8", "HEAD"] with subprocess.Popen(command, stdout=subprocess.PIPE) as proc: - commit_hash = proc.stdout.readline().strip().decode("utf-8") + commit_hash = ( + proc.stdout.readline() # pyright: ignore [ reportOptionalMemberAccess ] + .strip() + .decode("utf-8") + ) return f"{datetime.today():%Y%m%d%H%M}git{commit_hash}" @@ -95,15 +99,28 @@ def get_python_package_info(name): """ command = ["python3", "setup.py", "--name"] with subprocess.Popen(command, stdout=subprocess.PIPE) as proc: - assert proc.stdout.readline().strip().decode("utf-8") == name + assert ( + proc.stdout.readline() # pyright: ignore [ reportOptionalMemberAccess ] + .strip() + .decode("utf-8") + == name + ) command = ["python3", "setup.py", "--version"] with subprocess.Popen(command, stdout=subprocess.PIPE) as proc: - release_version = proc.stdout.readline().strip().decode("utf-8") + release_version = ( + proc.stdout.readline() # pyright: ignore [ reportOptionalMemberAccess ] + .strip() + .decode("utf-8") + ) command = ["python3", "setup.py", "--url"] with subprocess.Popen(command, stdout=subprocess.PIPE) as proc: - github_url = proc.stdout.readline().strip().decode("utf-8") + github_url = ( + proc.stdout.readline() # pyright: ignore [ reportOptionalMemberAccess ] + .strip() + .decode("utf-8") + ) github_repo = urlparse(github_url) assert github_repo.netloc == "github.com", "specified repo is not on GitHub" @@ -144,7 +161,9 @@ def verify_tag(tag): """ command = ["git", "tag", "--points-at"] with subprocess.Popen(command, stdout=subprocess.PIPE) as proc: - tag_str = proc.stdout.readline() + tag_str = ( + proc.stdout.readline() # pyright: ignore [ reportOptionalMemberAccess ] + ) return tag_str.decode("utf-8").rstrip() == tag @@ -171,7 +190,9 @@ def get_branch(): """ command = ["git", "branch", "--show-current"] with subprocess.Popen(command, stdout=subprocess.PIPE) as proc: - branch_str = proc.stdout.readline() + branch_str = ( + proc.stdout.readline() # pyright: ignore [ reportOptionalMemberAccess ] + ) return branch_str.decode("utf-8").rstrip() From c53aaab495bfb51222040dae19dde126ffc503a3 Mon Sep 17 00:00:00 2001 From: mulhern Date: Mon, 2 Jun 2025 17:29:29 -0400 Subject: [PATCH 3/5] Raise RuntimeError if thin_metadata_size call fails Signed-off-by: mulhern --- misc_scripts/thin_metadata_size_viz.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/misc_scripts/thin_metadata_size_viz.py b/misc_scripts/thin_metadata_size_viz.py index 475b338b..c4d0332e 100755 --- a/misc_scripts/thin_metadata_size_viz.py +++ b/misc_scripts/thin_metadata_size_viz.py @@ -51,7 +51,7 @@ def gen_parser(): return parser -def build_arrays(block_size, values): +def build_arrays(block_size, values): # pylint: disable=too-many-locals """ Build three matrices of values where the z_values are the result of running thin_metadata_size on the x and y values. @@ -73,8 +73,20 @@ def build_arrays(block_size, values): f"--max-thins={num_thins}", "-n", ] - with subprocess.Popen(command, stdout=subprocess.PIPE) as proc: - result = int(proc.stdout.readline().decode("utf-8").strip()) + with subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) as proc: + try: + result = int( + proc.stdout.readline() # pyright: ignore [ reportOptionalMemberAccess ] + .decode("utf-8") + .strip() + ) + except ValueError as err: + error_message = ( + proc.stderr.readline() # pyright: ignore [ reportOptionalMemberAccess ] + ) + raise RuntimeError(error_message.decode("utf-8")) from err x_row.append(pool_size) y_row.append(num_thins) z_row.append(result) From 5586cf0113125c878efc634d8ad9151046beaa1c Mon Sep 17 00:00:00 2001 From: mulhern Date: Mon, 2 Jun 2025 17:33:00 -0400 Subject: [PATCH 4/5] Allow reportAttributeAccessIssue pyright lint I do not know the cause of this lint, but given that the script may be judged completely obsolete soon, it is not worth finding out. Signed-off-by: mulhern --- misc_scripts/thin_metadata_size_viz.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc_scripts/thin_metadata_size_viz.py b/misc_scripts/thin_metadata_size_viz.py index c4d0332e..c406a585 100755 --- a/misc_scripts/thin_metadata_size_viz.py +++ b/misc_scripts/thin_metadata_size_viz.py @@ -112,7 +112,9 @@ def plot_figure(x_inputs, y_inputs, z_inputs): ylabel="Number of thin devices", zlabel="Metadata size", ) - axes.plot_wireframe(x_inputs, y_inputs, z_inputs) + axes.plot_wireframe( # pyright: ignore [ reportAttributeAccessIssue ] + x_inputs, y_inputs, z_inputs + ) return fig From ac8c3076ee3b0ac3c5b17ec3028cbbfdac0cda5a Mon Sep 17 00:00:00 2001 From: mulhern Date: Mon, 2 Jun 2025 17:45:32 -0400 Subject: [PATCH 5/5] Use pyright as well as pylint when linting Signed-off-by: mulhern --- .github/workflows/main.yml | 13 ++++++++----- Makefile | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cb269e04..acbff0f8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,19 +27,19 @@ jobs: python3-requests python3-semantic_version python3-specfile - task: lint + task: PATH=${PATH}:/github/home/.local/bin make -f Makefile lint - dependencies: > black python3-isort shfmt - task: fmt-travis + task: make -f Makefile fmt-travis - dependencies: > yamllint - task: yamllint + task: make -f Makefile yamllint - dependencies: > findutils ShellCheck - task: shellcheck + task: make -f Makefile shellcheck runs-on: ubuntu-latest container: fedora:41 # CURRENT DEVELOPMENT ENVIRONMENT steps: @@ -48,6 +48,9 @@ jobs: run: > dnf install -y make + pip ${{ matrix.dependencies }} + - name: Install pyright + run: pip install --user pyright - name: Run test - run: make -f Makefile ${{ matrix.task }} + run: ${{ matrix.task }} diff --git a/Makefile b/Makefile index 210b30f5..41a99ce8 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ lint: pylint ./dependency_management/* --disable=R0801 pylint ./misc_scripts/*.py --disable=R0801 pylint ./release_management/*.py --disable=R0801 + pyright .PHONY: fmt fmt: