Skip to content

Replace hardcoded sys.platform checks with shared constants - #72

Merged
JezaChen merged 2 commits into
masterfrom
dev-0.5.1/refactor/replace-hardcoded-platform
Apr 14, 2026
Merged

Replace hardcoded sys.platform checks with shared constants#72
JezaChen merged 2 commits into
masterfrom
dev-0.5.1/refactor/replace-hardcoded-platform

Conversation

@JezaChen

Copy link
Copy Markdown
Owner

Summary

  • Replace scattered sys.platform comparisons across 7 modules with IS_WINDOWS / IS_MACOS constants from pqi_contants.py, establishing a single source of truth for platform detection.
  • Remove legacy code: delete obsolete _pqi_saved_modules.py compatibility layer and unused packaging/launcher scripts (pack_exe.py, pack_exe_pyinstaller.py, run_server.py).

Changed files

  • pqi_monkey.py — use IS_WINDOWS in remove_quotes_from_args / quote_args
  • keyboard_hook_handler.py — use IS_WINDOWS in factory __new__
  • platform_specific/__init__.py — use IS_WINDOWS / IS_MACOS in _get_setup()
  • ide_jumpers.py — use IS_WINDOWS in _find_default_ide_path_helper
  • styles.py — use IS_WINDOWS / IS_MACOS in _get_default_font
  • attach_window.py — use IS_WINDOWS in PidLineEdit
  • pqi_server_gui.py — use IS_MACOS in main()

Note

pqi_attach/ still contains its own local IS_WINDOWS/IS_MAC definitions — these can be unified in a follow-up PR.

Test plan

  • Verify server GUI launches correctly on Windows
  • Verify platform-specific code paths (font selection, keyboard hook, IDE detection) still work
  • Spot-check that attach window grab button appears only on Windows

🤖 Generated with Claude Code

… constants

Use IS_WINDOWS/IS_MACOS from pqi_contants instead of inline sys.platform comparisons across server GUI and client modules for consistency and single source of truth.
Copilot AI review requested due to automatic review settings April 14, 2026 15:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR centralizes platform detection by replacing direct sys.platform comparisons with shared IS_WINDOWS / IS_MACOS constants, aiming to make platform-specific behavior consistent and easier to maintain.

Changes:

  • Replace scattered sys.platform platform checks with IS_WINDOWS / IS_MACOS.
  • Update platform-specific GUI behavior (macOS Fusion palette, Windows-only grab action, default font selection).
  • Route platform-specific setup selection through shared constants.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
PyQtInspect/pqi_server_gui.py Switch macOS styling condition in main() to IS_MACOS.
PyQtInspect/pqi_gui/windows/attach_window.py Gate Windows-only “grab” functionality via IS_WINDOWS constant.
PyQtInspect/pqi_gui/styles.py Use shared constants to select platform default font.
PyQtInspect/pqi_gui/settings/ide_jumpers.py Replace Windows platform check in IDE path lookup logic with IS_WINDOWS.
PyQtInspect/pqi_gui/platform_specific/init.py Select correct Setup implementation using IS_WINDOWS / IS_MACOS.
PyQtInspect/pqi_gui/keyboard_hook_handler.py Use IS_WINDOWS to select the keyboard hook implementation.
PyQtInspect/_pqi_bundle/pqi_monkey.py Use IS_WINDOWS in argument quoting/unquoting helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +202 to 205
if IS_WINDOWS:
defaultPath = _find_for_windows()
if defaultPath:
pqi_log.info(f'Found IDE path for {command_name} from commands on Windows: {defaultPath}')

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Windows-specific branch appears inside _find_for_linux(), which makes the function name misleading and harder to reason about. Consider either (a) moving the Windows branch into a platform-dispatch wrapper (e.g., _find_default_ide_path()), or (b) renaming/refactoring _find_for_linux() to reflect that it may run on multiple platforms.

Copilot uses AI. Check for mistakes.
Comment thread PyQtInspect/pqi_gui/styles.py Outdated
Comment on lines 5 to 11
from PyQtInspect._pqi_bundle.pqi_contants import IS_WINDOWS, IS_MACOS
if IS_WINDOWS: # Windows
return 'Microsoft Yahei'
elif sys.platform == 'darwin': # macOS
elif IS_MACOS: # macOS
return 'Helvetica'
else: # Linux
return 'DejaVu Sans'

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing IS_WINDOWS/IS_MACOS inside _get_default_font() adds repeated import overhead if this function is called frequently (e.g., during style recalculation). Prefer a module-level import for these constants (or caching the result) unless there is a concrete need to avoid import-time dependencies.

Copilot uses AI. Check for mistakes.
Comment on lines 19 to 23
from PyQtInspect._pqi_bundle.pqi_contants import IS_WINDOWS
if IS_WINDOWS:
class_ = WindowsKeyboardHookHandler
else:
class_ = DummyKeyboardHookHandler

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing the IS_WINDOWS import inside __new__ obscures dependencies and makes the factory logic harder to scan. If there’s no import-cycle concern, prefer importing IS_WINDOWS at module scope to keep platform selection logic focused on behavior rather than imports.

Copilot uses AI. Check for mistakes.
Address PR review: move IS_WINDOWS/IS_MACOS imports from function scope to module top-level in styles.py, keyboard_hook_handler.py, and platform_specific/__init__.py.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 14, 2026

Copy link
Copy Markdown

Deploying pyqtinspect-open with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3d1fa21
Status: ✅  Deploy successful!
Preview URL: https://cbd53781.pyqtinspect-open.pages.dev
Branch Preview URL: https://dev-0-5-1-refactor-replace-h.pyqtinspect-open.pages.dev

View logs

@JezaChen

Copy link
Copy Markdown
Owner Author

@copilot review again

@JezaChen
JezaChen merged commit 6c63651 into master Apr 14, 2026
3 checks passed
Copilot stopped work on behalf of JezaChen due to an error April 14, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants