Skip to content

Commit

Permalink
Merge pull request #4 from spyoungtech/console-scripts
Browse files Browse the repository at this point in the history
Pyperclip3 -> PyClip; Console scripts
  • Loading branch information
spyoungtech authored Feb 1, 2021
2 parents e8fe6b4 + bc353a0 commit b9da582
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 26 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pyperclip3
# PyClip

Cross-platform clipboard utilities supporting both binary and text data.

Expand All @@ -14,35 +14,41 @@ are supported
Requires python 3.7+

```bash
pip install pyperclip3
pip install pyclip
```

## Usage

pyperclip3 can be used in Python code
```python
import pyperclip3
import pyclip

pyperclip3.copy("hello clipboard") # copy data to the clipboard
cb_data = pyperclip3.paste() # retrieve clipboard contents
pyclip.copy("hello clipboard") # copy data to the clipboard
cb_data = pyclip.paste() # retrieve clipboard contents
print(cb_data)

pyperclip3.clear() # clears the clipboard contents
assert not pyperclip3.paste()
pyclip.clear() # clears the clipboard contents
assert not pyclip.paste()
```

Or a CLI

```bash
# paste clipboard contents to stdout
python -m pyperclip3 paste
python -m pyclip paste

# load contents to the clipboard from stdin
python -m pyperclip3 copy < myfile.text
# same as above, but pipe from another command
some-program | python -m pyperclip3 copy
```

Installing via pip also provides the console script `pyclip`:

```bash
pyclip copy < my_file.txt
```

This library implements functionality for several platforms and clipboard utilities.

- [x] MacOS
Expand All @@ -69,3 +75,8 @@ data being lost on copy/paste. This backend may be removed in a future release.
### Linux

Linux requires `xclip` to work (which means you must also use X). Install with your package manager, e.g. `sudo apt install xclip`

# Acknowledgements

Big thanks to [Howard Mao](https://github.com/zhemao) for donating the PyClip project name on PyPI to
this project.
1 change: 0 additions & 1 deletion pyperclip3/__init__.py → pyclip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import sys
from .util import detect_clipboard
from .base import ClipboardSetupException
import warnings

try:
DEFAULT_CLIPBOARD = detect_clipboard()
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions pyperclip3/cli.py → pyclip/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def _main(args):
from pyperclip3 import copy, clear, paste
from pyclip import copy, clear, paste
if args.command == "copy":
copy(sys.stdin.buffer.read())
elif args.command == 'paste':
Expand All @@ -30,7 +30,7 @@ def _main(args):


def main():
parser = argparse.ArgumentParser('pyperclip3')
parser = argparse.ArgumentParser('pyclip')
subparsers = parser.add_subparsers(title='commands', dest='command', required=True, description='Valid commands')
copy_parser = subparsers.add_parser('copy', help='Copy contents from stdin to the clipboard')
paste_parser = subparsers.add_parser('paste', help='Output clipboard contents to stdout')
Expand Down
1 change: 0 additions & 1 deletion pyperclip3/macos_clip.py → pyclip/macos_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
from .base import ClipboardBase, ClipboardException, ClipboardSetupException
import subprocess
import sys
import shutil
from typing import Union
import logging
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pyperclip3/win_clip.py → pyclip/win_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import Union, Dict, Tuple, Any
import os
import ctypes
from .base import ClipboardBase, ClipboardSetupException, ClipboardException
from .base import ClipboardBase, ClipboardSetupException
import warnings
import time
try:
Expand Down
File renamed without changes.
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@


setup(
name='pyperclip3',
version='0.4.0',
name='pyclip',
version='0.5.0',
license='Apache',
url='https://github.com/spyoungtech/pyperclip3',
url='https://github.com/spyoungtech/pyclip',
description='Cross-platform clipboard utilities supporting both binary and text data.',
long_description=long_description,
long_description_content_type="text/markdown",
author_email='[email protected]',
author='Spencer Young',
packages=['pyperclip3'],
packages=['pyclip'],
install_requires=[
'pywin32 >= 1.0 ; platform_system=="Windows"',
'pasteboard == 0.3.3 ; platform_system=="Darwin"',
Expand All @@ -33,6 +33,9 @@
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
entry_points={
'console_scripts': ['pyclip = pyclip.cli:main']
},
tests_require=test_requirements,
keywords='pyperclip clipboard cross-platform binary bytes files'
)
18 changes: 9 additions & 9 deletions tests/test_clipboard.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys, os
try:
import pyperclip3 as clip
import pyclip as clip
except ImportError:
# XXX: probably shouldn't do this, but oh well ¯\_(ツ)_/¯
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import pyperclip3 as clip
import pyclip as clip
import pytest

from unittest import mock
Expand Down Expand Up @@ -39,7 +39,7 @@ def test_clear():

@pytest.mark.skipif(sys.platform != 'darwin', reason='This test is for MacOS only')
def test_copypaste_pbcopy_backend():
from pyperclip3.macos_clip import _PBCopyPBPasteBackend, MacOSClip
from pyclip.macos_clip import _PBCopyPBPasteBackend, MacOSClip
backend = _PBCopyPBPasteBackend()
clip = MacOSClip(_backend=backend)
clip.copy('foo')
Expand All @@ -48,7 +48,7 @@ def test_copypaste_pbcopy_backend():
assert clip.paste(text=True) == 'foo'
@pytest.mark.skipif(sys.platform != 'darwin', reason='This test is for MacOS only')
def test_copypaste_unicode_pbcopy_backend():
from pyperclip3.macos_clip import _PBCopyPBPasteBackend, MacOSClip
from pyclip.macos_clip import _PBCopyPBPasteBackend, MacOSClip
backend = _PBCopyPBPasteBackend()
clip = MacOSClip(_backend=backend)
unicode = 'א ב ג ד ה ו ז ח ט י ך כ ל ם מ ן נ ס ע ף פ ץ צ ק ר ש ת װ ױ'
Expand All @@ -58,7 +58,7 @@ def test_copypaste_unicode_pbcopy_backend():

@pytest.mark.skipif(sys.platform != 'darwin', reason='This test is for MacOS only')
def test_clear_pbcopy_backend():
from pyperclip3.macos_clip import _PBCopyPBPasteBackend, MacOSClip
from pyclip.macos_clip import _PBCopyPBPasteBackend, MacOSClip
backend = _PBCopyPBPasteBackend()
clip = MacOSClip(_backend=backend)
clip.copy('foo')
Expand All @@ -68,8 +68,8 @@ def test_clear_pbcopy_backend():
assert not data, f'clipboard contents unexpectly present: {repr(data)}'

def test_cli():
from pyperclip3.cli import _main, main
args = ['pyperclip3', 'copy']
from pyclip.cli import _main, main
args = ['pyclip', 'copy']
import io
stdin = io.BytesIO(b"foo")
class MockStdin:
Expand All @@ -78,15 +78,15 @@ def __init__(self, b):
with mock.patch('sys.exit', new=lambda x: x):
with mock.patch('sys.argv', new=args), mock.patch('sys.stdin', new=MockStdin(b'foo')):
main()
args = ['pyperclip3', 'paste']
args = ['pyclip', 'paste']
class MockStdout:
def __init__(self):
self.buffer = io.BytesIO()
stdout = MockStdout()
with mock.patch('sys.argv', new=args), mock.patch('sys.stdout', new=stdout):
main()
assert stdout.buffer.getvalue() == b'foo'
args = ['pyperclip3', 'clear']
args = ['pyclip', 'clear']
with mock.patch('sys.argv', new=args):
main()
assert not clip.paste()

0 comments on commit b9da582

Please sign in to comment.