Skip to content

Commit 8ba24d1

Browse files
committed
Replace custom clipboard code with pyperclip
pyperclip supports Wayland and Windows
1 parent 9a0ad31 commit 8ba24d1

File tree

4 files changed

+14
-86
lines changed

4 files changed

+14
-86
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Dependencies
163163
* babel (optional, for internationalization)
164164
* jedi (optional, for experimental multiline completion)
165165
* watchdog (optional, for monitoring imported modules for changes)
166+
* pyperclip (optional, for copying to the clipboard)
166167

167168
bpython-urwid
168169
-------------

bpython/clipboard.py

Lines changed: 0 additions & 78 deletions
This file was deleted.

bpython/repl.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@
3636
from enum import Enum
3737
from itertools import takewhile
3838
from pathlib import Path
39+
from pygments.lexers import Python3Lexer
40+
from pygments.token import Token
3941
from types import ModuleType
4042

41-
from pygments.token import Token
42-
from pygments.lexers import Python3Lexer
43+
have_pyperclip = True
44+
try:
45+
import pyperclip
46+
except ImportError:
47+
have_pyperclip = False
48+
4349
from . import autocomplete, inspection, simpleeval
44-
from .clipboard import get_clipboard, CopyFailed
4550
from .config import getpreferredencoding
4651
from .formatter import Parenthesis
4752
from .history import History
@@ -430,7 +435,6 @@ def __init__(self, interp, config):
430435
# Necessary to fix mercurial.ui.ui expecting sys.stderr to have this
431436
# attribute
432437
self.closed = False
433-
self.clipboard = get_clipboard()
434438

435439
if self.config.hist_file.exists():
436440
try:
@@ -862,14 +866,14 @@ def write2file(self):
862866
def copy2clipboard(self):
863867
"""Copy current content to clipboard."""
864868

865-
if self.clipboard is None:
869+
if not have_pyperclip:
866870
self.interact.notify(_("No clipboard available."))
867871
return
868872

869873
content = self.get_session_formatted_for_file()
870874
try:
871-
self.clipboard.copy(content)
872-
except CopyFailed:
875+
pyperclip.copy(content)
876+
except pyperclip.PyperclipException:
873877
self.interact.notify(_("Could not copy to clipboard."))
874878
else:
875879
self.interact.notify(_("Copied content to clipboard."))

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ install_requires =
2828
pyxdg
2929

3030
[options.extras_require]
31+
clipboard = pyperclip
32+
jedi = jedi >= 0.16
3133
urwid = urwid
3234
watch = watchdog
33-
jedi = jedi >= 0.16
3435

3536
[options.entry_points]
3637
console_scripts =

0 commit comments

Comments
 (0)