Conversation
pyperclip detects Docker-on-Windows containers as WSL because /proc/version contains "microsoft", then unconditionally tries clip.exe which doesn't exist in the container. This causes clipboard_set/clipboard_get to fail entirely. Fix: check whether clip.exe is actually reachable via shutil.which before deciding to use the WSL code path. If clip.exe is absent but xclip is installed, use xclip directly. All other platforms (Windows, macOS, real WSL) fall through to pyperclip as before. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a Linux fallback path for clipboard operations to avoid pyperclip mis-detecting certain Docker-on-Windows containers as WSL and attempting to call an unavailable clip.exe.
Changes:
- Added helper detection functions to decide between
pyperclipandxclip. - Implemented
xclip-based copy/paste helpers and routedclipboard_get/clipboard_setthrough them when selected.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+16
to
+25
| def _use_xclip() -> bool: | ||
| """ | ||
| Returns True when we should use xclip instead of pyperclip. | ||
|
|
||
| pyperclip detects Docker-on-Windows containers as WSL (because /proc/version | ||
| contains "microsoft") and tries clip.exe — which doesn't exist in the container. | ||
| We only use xclip when clip.exe is genuinely unreachable and xclip is installed. | ||
| On real WSL, Windows, or macOS this returns False and pyperclip handles it as normal. | ||
| """ | ||
| return not _clip_exe_available() and _xclip_available() |
Comment on lines
+16
to
+25
| def _use_xclip() -> bool: | ||
| """ | ||
| Returns True when we should use xclip instead of pyperclip. | ||
|
|
||
| pyperclip detects Docker-on-Windows containers as WSL (because /proc/version | ||
| contains "microsoft") and tries clip.exe — which doesn't exist in the container. | ||
| We only use xclip when clip.exe is genuinely unreachable and xclip is installed. | ||
| On real WSL, Windows, or macOS this returns False and pyperclip handles it as normal. | ||
| """ | ||
| return not _clip_exe_available() and _xclip_available() |
Comment on lines
+29
to
+33
| result = subprocess.run( | ||
| ["xclip", "-selection", "clipboard"], | ||
| input=text.encode("utf-8"), | ||
| capture_output=True, | ||
| ) |
Comment on lines
+41
to
+44
| result = subprocess.run( | ||
| ["xclip", "-selection", "clipboard", "-o"], | ||
| capture_output=True, | ||
| ) |
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
pyperclipmisidentifies Docker-on-Windows containers as WSL because/proc/versioncontains"microsoft", then unconditionally triesclip.exe— which doesn't exist inside the containerclipboard_setandclipboard_getboth fail withFileNotFoundError: clip.execlip.exeis actually reachable viashutil.whichbefore using the WSL code path; if absent butxclipis installed, usexclipdirectlyclip.exeexists) fall through topyperclipunchangedTest plan
clipboard_set/clipboard_getstill work via pyperclipxclipinstalled: uses xclip, works correctlyxclip: falls back to pyperclip (which will surface a clear error)🤖 Generated with Claude Code