Skip to content

fix(manager): add common macOS paths to system module search#125

Merged
ErikBjare merged 2 commits intoActivityWatch:masterfrom
TimeToBuildBob:fix/macos-system-path
Mar 12, 2026
Merged

fix(manager): add common macOS paths to system module search#125
ErikBjare merged 2 commits intoActivityWatch:masterfrom
TimeToBuildBob:fix/macos-system-path

Conversation

@TimeToBuildBob
Copy link
Copy Markdown
Contributor

Problem

When aw-qt is launched from Finder on macOS (e.g. double-clicking the .app), the PATH is minimal (/usr/bin:/bin:/usr/sbin:/sbin) and doesn't include directories where ActivityWatch modules are typically installed. This means _discover_modules_system() finds 0 system modules, causing aw-qt to report errors like:

Module aw-server not found
Module aw-watcher-afk not found
Module aw-watcher-window not found

Launching from Terminal works fine because the shell's full PATH is inherited.

Closes #96

Solution

Add common macOS binary paths explicitly to the system module search, so modules are found regardless of how aw-qt is launched:

  • /opt/homebrew/bin — Homebrew on Apple Silicon
  • /usr/local/bin — Homebrew on Intel / pip global installs
  • ~/.local/bin — pip --user installs

Guards:

  • Paths already in PATH are not duplicated
  • Only existing directories are searched (os.path.isdir check)
  • Change is macOS-only (no effect on Linux/Windows)

Tests

Added 3 unit tests in tests/test_manager.py:

  1. test_macos_adds_extra_paths_when_not_in_path — verifies Homebrew and pip paths are searched with a minimal Finder-like PATH
  2. test_macos_does_not_duplicate_existing_path_entries — verifies paths already in PATH aren't searched twice
  3. test_non_macos_does_not_add_extra_paths — verifies Linux behavior is unchanged

When aw-qt is launched from Finder on macOS the PATH is minimal
(/usr/bin:/bin:/usr/sbin:/sbin) and doesn't include directories where AW
modules are typically installed. This caused _discover_modules_system() to
find 0 system modules when not launched from a terminal.

Add common macOS binary paths explicitly to the search so that system
modules can be found regardless of how aw-qt was launched:
- /opt/homebrew/bin  (Homebrew on Apple Silicon)
- /usr/local/bin     (Homebrew on Intel / pip global installs)
- ~/.local/bin       (pip --user installs)

Duplicates are skipped (paths already in PATH are not added again), and
only existing directories are searched.

Fixes ActivityWatch#96

Co-authored-by: Bob <bob@superuserlabs.org>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR fixes a macOS-specific module discovery failure where aw-qt launched from Finder inherits a minimal PATH (/usr/bin:/bin:/usr/sbin:/sbin), causing all system modules to appear missing. The fix appends three common macOS install locations (/opt/homebrew/bin, /usr/local/bin, ~/.local/bin) to the search path only on Darwin, only when each directory is not already present, and only when it actually exists on disk.

Key points:

  • Production code in aw_qt/manager.py is clean and correct — deduplication and existence guards work as intended.
  • One test assertion in test_macos_adds_extra_paths_when_not_in_path is a false positive: the check any("local/bin" in p for p in searched_paths) will always match /usr/local/bin (another explicitly-added path) before ever exercising ~/.local/bin, so the guard for the pip user-install path is not actually verified.
  • The test_macos_does_not_duplicate_existing_path_entries test does not cover ~/.local/bin deduplication (the fixture full_path omits it), but that is a minor coverage gap, not a correctness problem.

Confidence Score: 4/5

  • Safe to merge — production logic is correct; one test assertion is a false positive but does not affect runtime behavior.
  • The production change is minimal, well-guarded (dedup + isdir), and macOS-only. The only defect is in the test suite: the ~/.local/bin assertion in test_macos_adds_extra_paths_when_not_in_path always passes due to a substring collision with /usr/local/bin, so it never truly validates that ~/.local/bin is searched. Fixing the assertion before merging is recommended but the actual fix is sound.
  • tests/test_manager.py — the false-positive assertion for ~/.local/bin should be corrected.

Important Files Changed

Filename Overview
aw_qt/manager.py Adds macOS-specific path augmentation to _discover_modules_system(). Logic is sound: paths are only added when not already in PATH and the directory exists, and the change is Darwin-only. No issues found in production code.
tests/test_manager.py Three new test cases added for macOS path discovery. The ~/.local/bin assertion in test_macos_adds_extra_paths_when_not_in_path is a false positive — "local/bin" matches /usr/local/bin before it ever matches the expanded ~/.local/bin, so the check for the pip user-install path never actually exercises.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["_discover_modules_system()"] --> B["search_paths = os.get_exec_path()"]
    B --> C{"_parent_dir in search_paths?"}
    C -- Yes --> D["Remove _parent_dir"]
    C -- No --> E{"platform == Darwin?"}
    D --> E
    E -- No --> I
    E -- Yes --> F["macos_extra_paths = [/opt/homebrew/bin, /usr/local/bin, ~/.local/bin]"]
    F --> G{"extra_path already in search_paths?"}
    G -- Yes --> G2["Skip (no duplicate)"]
    G -- No --> H{"os.path.isdir(extra_path)?"}
    H -- No --> H2["Skip (doesn't exist)"]
    H -- Yes --> H3["Append to search_paths"]
    G2 --> I["paths = [p for p in search_paths if os.path.isdir(p)]"]
    H2 --> I
    H3 --> I
    I --> J["For each path: os.listdir → find aw-* executables"]
    J --> K["Return discovered modules"]
Loading

Last reviewed commit: 93f3a20

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@ErikBjare ErikBjare merged commit b7cedd9 into ActivityWatch:master Mar 12, 2026
3 checks passed
marcstober pushed a commit to marcstober/aw-qt that referenced this pull request Mar 18, 2026
…yWatch#125)

* fix(manager): add common macOS paths to system module search

When aw-qt is launched from Finder on macOS the PATH is minimal
(/usr/bin:/bin:/usr/sbin:/sbin) and doesn't include directories where AW
modules are typically installed. This caused _discover_modules_system() to
find 0 system modules when not launched from a terminal.

Add common macOS binary paths explicitly to the search so that system
modules can be found regardless of how aw-qt was launched:
- /opt/homebrew/bin  (Homebrew on Apple Silicon)
- /usr/local/bin     (Homebrew on Intel / pip global installs)
- ~/.local/bin       (pip --user installs)

Duplicates are skipped (paths already in PATH are not added again), and
only existing directories are searched.

Fixes ActivityWatch#96

Co-authored-by: Bob <bob@superuserlabs.org>

* Update tests/test_manager.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: Erik Bjäreholt <erik.bjareholt@gmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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.

Unable to find system modules on macOS

2 participants