fix: use sys.executable instead of hardcoded python#5
Open
Krivoblotsky wants to merge 1 commit into
Open
Conversation
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>
There was a problem hiding this comment.
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
sysand replace"python"withsys.executablein subprocess invocations. - Update subprocess command construction in
launch_app,get_tree, andget_tree_screenshot.
Comments suppressed due to low confidence (1)
macapptree/run.py:36
subprocess.check_call()does not capture stderr/stdout, soe.stderrin this handler will always beNone. If you want to print the failing command’s stderr, switch tosubprocess.run(..., capture_output=True, text=True, check=True)(or passstderr=subprocess.PIPE) and loge.stderr/e.stdout; otherwise loge/ 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 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 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 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
run.pycalled subprocess with"python"hardcoded in three places (launch_app,get_tree,get_tree_screenshot)pythonisn't in PATH (onlypython3)sys.executable, which always refers to the interpreter that is actually running the processTest plan
get_tree("com.apple.TextEdit")works from inside a virtualenvget_tree_screenshot("com.apple.TextEdit")works from inside a virtualenv🤖 Generated with Claude Code