From 88d54f8c0873597e13a3c52279aeb78d6bbcf5ea Mon Sep 17 00:00:00 2001 From: monkeyman192 Date: Thu, 10 Oct 2024 19:26:18 +1100 Subject: [PATCH] gh-11: Reformat changes in utils.py and final fixups to pipeline file --- .github/workflows/pipeline.yml | 13 ++++--------- pymhf/core/utils.py | 18 +++++++++++------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 026302e..0f4a3d7 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -43,12 +43,12 @@ jobs: release: name: Release pyMHF wheels and source build to PyPI # Only run this job if the commit was tagged. - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + if: startsWith(github.ref, 'refs/tags') needs: - build_test runs-on: ubuntu-latest environment: - name: testpypi + name: pypi url: https://pypi.org/p/pyMHF permissions: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing @@ -58,11 +58,10 @@ jobs: with: name: python-package-distributions path: dist/ - - name: See what files we have - run: ls ./dist/ - shell: bash - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + attestations: true test-release: name: Release pyMHF wheels and source build to test-PyPI @@ -80,12 +79,8 @@ jobs: with: name: python-package-distributions path: dist/ - - name: See what files we have - run: ls ./dist/ - shell: bash - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: repository-url: https://test.pypi.org/legacy/ attestations: true - verbose: true diff --git a/pymhf/core/utils.py b/pymhf/core/utils.py index 4f69a9a..8fa09b1 100644 --- a/pymhf/core/utils.py +++ b/pymhf/core/utils.py @@ -14,7 +14,7 @@ def get_main_window_handle() -> Optional[int]: - """ Return the handle of the main running application window if possible. + """Return the handle of the main running application window if possible. This will correspond to the HWND for the window belonging to the PID of the main running process. """ windows = {x.getHandle(): x for x in pwc.getAllWindows()} @@ -24,21 +24,25 @@ def get_main_window_handle() -> Optional[int]: logger.error(f"Cannot find window handle for PID {_internal.PID}") return None elif len(wins) > 1: - logger.error(f"Found multiple windows for PID {_internal.PID}: {main_pid_hwnds}.\n" - "Picking the first arbitrarily but this may not be correct.") + logger.error( + f"Found multiple windows for PID {_internal.PID}: {main_pid_hwnds}.\n" + "Picking the first arbitrarily but this may not be correct." + ) return wins[0] else: return wins[0] def get_hwnds_for_pid(pid: int) -> list[int]: - """ Return all HWND's for the provided PID. """ + """Return all HWND's for the provided PID.""" + def callback(hwnd: int, hwnds: list[int]): _, found_pid = win32process.GetWindowThreadProcessId(hwnd) if found_pid == pid: hwnds.append(hwnd) return True + hwnds = [] win32gui.EnumWindows(callback, hwnds) return hwnds @@ -50,7 +54,7 @@ def get_window_by_handle(handle: int) -> Optional[pwc.Window]: def set_main_window_active(callback: Optional[Callable[[], None]] = None): - """ Set the main window as active. + """Set the main window as active. If a callback is provided, it will be called after activating the window. This callback must not take any arguments and any return value will be ignored. """ @@ -58,9 +62,9 @@ def set_main_window_active(callback: Optional[Callable[[], None]] = None): if not _internal.MAIN_HWND: _internal.MAIN_HWND = get_main_window_handle() if not _internal.MAIN_HWND: - logger.error(f"Cannot set main window active as we can't find it...") + logger.error("Cannot set main window active as we can't find it...") if not is_main_window_foreground(): - if (main_window := get_window_by_handle(_internal.MAIN_HWND)): + if main_window := get_window_by_handle(_internal.MAIN_HWND): main_window.activate() if callback is not None: callback()