Skip to content

fix: use sys.executable instead of hardcoded python#5

Open
Krivoblotsky wants to merge 1 commit into
mainfrom
fix/sys-executable
Open

fix: use sys.executable instead of hardcoded python#5
Krivoblotsky wants to merge 1 commit into
mainfrom
fix/sys-executable

Conversation

@Krivoblotsky
Copy link
Copy Markdown

Summary

  • run.py called subprocess with "python" hardcoded in three places (launch_app, get_tree, get_tree_screenshot)
  • This breaks in virtualenvs where only the venv Python is activated, and on systems where python isn't in PATH (only python3)
  • Replaced all three with sys.executable, which always refers to the interpreter that is actually running the process

Test plan

  • get_tree("com.apple.TextEdit") works from inside a virtualenv
  • get_tree_screenshot("com.apple.TextEdit") works from inside a virtualenv
  • No regression when called from a plain system Python install

🤖 Generated with Claude Code

Hardcoded "python" breaks in virtualenvs and on systems where only
"python3" is in PATH. sys.executable always refers to the interpreter
running the current process.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates macapptree/run.py to invoke the current Python interpreter (via sys.executable) instead of hardcoding "python", improving compatibility with virtualenvs and systems where python is not on PATH.

Changes:

  • Import sys and replace "python" with sys.executable in subprocess invocations.
  • Update subprocess command construction in launch_app, get_tree, and get_tree_screenshot.
Comments suppressed due to low confidence (1)

macapptree/run.py:36

  • subprocess.check_call() does not capture stderr/stdout, so e.stderr in this handler will always be None. If you want to print the failing command’s stderr, switch to subprocess.run(..., capture_output=True, text=True, check=True) (or pass stderr=subprocess.PIPE) and log e.stderr/e.stdout; otherwise log e / return code instead.
    command = [sys.executable, "-m", "macapptree.main", "-a", app_bundle, "--oa", tmp_file.name]
    if max_depth:
        command.extend(["--max-depth", str(max_depth)])
    try:
        subprocess.check_call(command)
        return json.load(tmp_file)
    except subprocess.CalledProcessError as e:
        print(f"Failed to extract app accessibility for {app_bundle}. Error: {e.stderr}")
        raise e

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

Comment thread macapptree/run.py
Comment on lines +18 to 21
subprocess.check_call([sys.executable, "-m", "macapptree.launch_app", "-a", app_bundle])
except subprocess.CalledProcessError as e:
print(f"Failed to launch app: {app_bundle}. Error: {e.stderr}")
raise e
Comment thread macapptree/run.py
Comment on lines 27 to +28
tmp_file = tempfile.NamedTemporaryFile(delete=False)
command = ["python", "-m", "macapptree.main", "-a", app_bundle, "--oa", tmp_file.name]
command = [sys.executable, "-m", "macapptree.main", "-a", app_bundle, "--oa", tmp_file.name]
Comment thread macapptree/run.py
Comment on lines 45 to 49
screenshot_tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
command = ["python", "-m", "macapptree.main",
"-a", app_bundle,
command = [sys.executable, "-m", "macapptree.main",
"-a", app_bundle,
"--oa", a11y_tmp_file.name,
"--os", screenshot_tmp_file.name]
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