MCPcopy
hub / github.com/pandas-dev/pandas / determine_clipboard

Function determine_clipboard

pandas/io/clipboard/__init__.py:527–599  ·  view source on GitHub ↗

Determine the OS/platform and set the copy() and paste() functions accordingly.

()

Source from the content-addressed store, hash-verified

525# Automatic detection of clipboard mechanisms
526# and importing is done in determine_clipboard():
527def determine_clipboard():
528 """
529 Determine the OS/platform and set the copy() and paste() functions
530 accordingly.
531 """
532 global Foundation, AppKit, qtpy, PyQt4, PyQt5
533
534 # Setup for the CYGWIN platform:
535 if (
536 "cygwin" in platform.system().lower()
537 ): # Cygwin has a variety of values returned by platform.system(),
538 # such as 'CYGWIN_NT-6.1'
539 # FIXME(pyperclip#55): pyperclip currently does not support Cygwin,
540 # see https://github.com/asweigart/pyperclip/issues/55
541 if os.path.exists("/dev/clipboard"):
542 warnings.warn(
543 "Pyperclip's support for Cygwin is not perfect, "
544 "see https://github.com/asweigart/pyperclip/issues/55",
545 stacklevel=find_stack_level(),
546 )
547 return init_dev_clipboard_clipboard()
548
549 # Setup for the WINDOWS platform:
550 elif os.name == "nt" or platform.system() == "Windows":
551 return init_windows_clipboard()
552
553 if platform.system() == "Linux":
554 if _executable_exists("wslconfig.exe"):
555 return init_wsl_clipboard()
556
557 # Setup for the macOS platform:
558 if os.name == "mac" or platform.system() == "Darwin":
559 try:
560 import AppKit
561 import Foundation # check if pyobjc is installed
562 except ImportError:
563 return init_osx_pbcopy_clipboard()
564 else:
565 return init_osx_pyobjc_clipboard()
566
567 # Setup for the LINUX platform:
568 if HAS_DISPLAY:
569 if os.environ.get("WAYLAND_DISPLAY") and _executable_exists("wl-copy"):
570 return init_wl_clipboard()
571 if _executable_exists("xsel"):
572 return init_xsel_clipboard()
573 if _executable_exists("xclip"):
574 return init_xclip_clipboard()
575 if _executable_exists("klipper") and _executable_exists("qdbus"):
576 return init_klipper_clipboard()
577
578 try:
579 # qtpy is a small abstraction layer that lets you write applications
580 # using a single api call to either PyQt or PySide.
581 # https://pypi.python.org/project/QtPy
582 import qtpy # check if qtpy is installed
583 except ImportError:
584 # If qtpy isn't installed, fall back on importing PyQt4.

Callers 2

lazy_load_stub_copyFunction · 0.85
lazy_load_stub_pasteFunction · 0.85

Calls 15

find_stack_levelFunction · 0.90
init_windows_clipboardFunction · 0.85
init_wsl_clipboardFunction · 0.85
init_wl_clipboardFunction · 0.85
init_xsel_clipboardFunction · 0.85
init_xclip_clipboardFunction · 0.85
init_klipper_clipboardFunction · 0.85
init_qt_clipboardFunction · 0.85
init_no_clipboardFunction · 0.85

Tested by

no test coverage detected