ipyclip 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ipyclip-0.0.1/LICENSE +19 -0
- ipyclip-0.0.1/PKG-INFO +15 -0
- ipyclip-0.0.1/README.md +2 -0
- ipyclip-0.0.1/pyproject.toml +23 -0
- ipyclip-0.0.1/setup.cfg +4 -0
- ipyclip-0.0.1/src/iclip/ClipboardManager.py +112 -0
- ipyclip-0.0.1/src/iclip/__init__.py +0 -0
- ipyclip-0.0.1/src/iclip/ipyclip.py +11 -0
- ipyclip-0.0.1/src/ipyclip.egg-info/PKG-INFO +15 -0
- ipyclip-0.0.1/src/ipyclip.egg-info/SOURCES.txt +10 -0
- ipyclip-0.0.1/src/ipyclip.egg-info/dependency_links.txt +1 -0
- ipyclip-0.0.1/src/ipyclip.egg-info/top_level.txt +1 -0
ipyclip-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
ipyclip-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ipyclip
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Clipboard utility for ipython
|
|
5
|
+
Author-email: Boaz <boaz.iclip@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
## iClip
|
|
15
|
+
A clipboard utility similar to windows' clip.exe for ipython.
|
ipyclip-0.0.1/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools >= 82.0.1", "pyperclip >=1.11.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ipyclip"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Boaz", email="boaz.iclip@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "Clipboard utility for ipython"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.9"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
license = "MIT"
|
|
19
|
+
license-files = ["LICEN[CS]E*"]
|
|
20
|
+
|
|
21
|
+
#[project.urls]
|
|
22
|
+
#Homepage = "https://github.com/pypa/sampleproject"
|
|
23
|
+
#Issues = "https://github.com/pypa/sampleproject/issues"
|
ipyclip-0.0.1/setup.cfg
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Clipboard Manager Class.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from pyperclip import copy
|
|
7
|
+
from functools import wraps
|
|
8
|
+
from typing import *
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ClipboardManager:
|
|
12
|
+
"""
|
|
13
|
+
Clipboard Manager Class.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, stream_name: Literal["stdout", "stderr"]):
|
|
17
|
+
# get stream and preserve original write
|
|
18
|
+
self.stream = getattr(sys, stream_name)
|
|
19
|
+
self.original_write = self.stream.write
|
|
20
|
+
|
|
21
|
+
# clip management
|
|
22
|
+
self.copy_invoked = False
|
|
23
|
+
self.copy_buffer = ""
|
|
24
|
+
self.last_clip = ""
|
|
25
|
+
self.stream_buffer = ""
|
|
26
|
+
self.error = None
|
|
27
|
+
|
|
28
|
+
def _stream_write_wrapper(self, stream_write_function):
|
|
29
|
+
wraps(stream_write_function)
|
|
30
|
+
|
|
31
|
+
def wrapper(data, *args, **kwargs):
|
|
32
|
+
"""
|
|
33
|
+
Saves anything written to the stream in the stream buffer.
|
|
34
|
+
:params: same as sys.stdout.write
|
|
35
|
+
:return: same as sys.stdout.write
|
|
36
|
+
"""
|
|
37
|
+
# keep original return value
|
|
38
|
+
result = stream_write_function(data, *args, **kwargs)
|
|
39
|
+
self.stream_buffer += data
|
|
40
|
+
return result
|
|
41
|
+
|
|
42
|
+
return wrapper
|
|
43
|
+
|
|
44
|
+
def _handle_exception(self, e):
|
|
45
|
+
"""
|
|
46
|
+
TODO: Retrofit with a more robust Exception object.
|
|
47
|
+
:param e: exception thrown in execution.
|
|
48
|
+
:return: None
|
|
49
|
+
"""
|
|
50
|
+
self.original_write("An error occurred while copying")
|
|
51
|
+
self.error = e
|
|
52
|
+
|
|
53
|
+
def __lt__(self, other):
|
|
54
|
+
"""
|
|
55
|
+
stage output for copying.
|
|
56
|
+
override current.
|
|
57
|
+
:param other:
|
|
58
|
+
:return: None
|
|
59
|
+
"""
|
|
60
|
+
self.copy_invoked = True
|
|
61
|
+
self.copy_buffer = self.stream_buffer
|
|
62
|
+
return other
|
|
63
|
+
|
|
64
|
+
def __rrshift__(self, other):
|
|
65
|
+
"""
|
|
66
|
+
stage the stdout for copying.
|
|
67
|
+
add to current.
|
|
68
|
+
:param other:
|
|
69
|
+
:return:
|
|
70
|
+
"""
|
|
71
|
+
self.copy_invoked = True
|
|
72
|
+
self.copy_buffer += self.stream_buffer
|
|
73
|
+
return other
|
|
74
|
+
|
|
75
|
+
def __ror__(self, other):
|
|
76
|
+
"""
|
|
77
|
+
Functions exactly the same as __lt__ but keeps the return value of the original statement.
|
|
78
|
+
:return: other
|
|
79
|
+
"""
|
|
80
|
+
self.__lt__(other)
|
|
81
|
+
return other
|
|
82
|
+
|
|
83
|
+
def __call__(self, *args, **kwargs):
|
|
84
|
+
self.copy_invoked = True
|
|
85
|
+
|
|
86
|
+
def reset_buffer(self):
|
|
87
|
+
"""
|
|
88
|
+
resets the clipboard buffer.
|
|
89
|
+
meant to be called by an event handler before execution.
|
|
90
|
+
:return:
|
|
91
|
+
"""
|
|
92
|
+
self.copy_invoked = False
|
|
93
|
+
self.stream_buffer = ""
|
|
94
|
+
self.stream.write = self._stream_write_wrapper(self.stream.write)
|
|
95
|
+
|
|
96
|
+
def flush_to_clipboard(self):
|
|
97
|
+
"""
|
|
98
|
+
Flush buffer to clipboard.
|
|
99
|
+
Used as a callback after every execution.
|
|
100
|
+
:return: None
|
|
101
|
+
"""
|
|
102
|
+
if self.copy_invoked:
|
|
103
|
+
if self.copy_buffer and self.copy_buffer != self.last_clip:
|
|
104
|
+
try:
|
|
105
|
+
copy(self.copy_buffer)
|
|
106
|
+
self.last_clip = self.copy_buffer
|
|
107
|
+
except Exception as e:
|
|
108
|
+
self._handle_exception(e)
|
|
109
|
+
|
|
110
|
+
# stage copy buffer for next-cell invocation
|
|
111
|
+
else:
|
|
112
|
+
self.copy_buffer = self.stream_buffer
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Ipython clipboard management extension
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
def load_ipython_extension(ipython):
|
|
6
|
+
from ClipboardManager import ClipboardManager
|
|
7
|
+
print("IPython loaded")
|
|
8
|
+
clip = ClipboardManager(stream_name="stdout")
|
|
9
|
+
ipython.push("clip")
|
|
10
|
+
ipython.events.register("pre_execute", clip.reset_buffer)
|
|
11
|
+
ipython.events.register("post_execute", clip.flush_to_clipboard)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ipyclip
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Clipboard utility for ipython
|
|
5
|
+
Author-email: Boaz <boaz.iclip@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
## iClip
|
|
15
|
+
A clipboard utility similar to windows' clip.exe for ipython.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/iclip/ClipboardManager.py
|
|
5
|
+
src/iclip/__init__.py
|
|
6
|
+
src/iclip/ipyclip.py
|
|
7
|
+
src/ipyclip.egg-info/PKG-INFO
|
|
8
|
+
src/ipyclip.egg-info/SOURCES.txt
|
|
9
|
+
src/ipyclip.egg-info/dependency_links.txt
|
|
10
|
+
src/ipyclip.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
iclip
|