swarmauri_state_clipboard 0.6.1.dev16__tar.gz → 0.7.0.dev3__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.
- {swarmauri_state_clipboard-0.6.1.dev16 → swarmauri_state_clipboard-0.7.0.dev3}/PKG-INFO +3 -6
- {swarmauri_state_clipboard-0.6.1.dev16 → swarmauri_state_clipboard-0.7.0.dev3}/pyproject.toml +33 -32
- swarmauri_state_clipboard-0.7.0.dev3/swarmauri_state_clipboard/ClipboardState.py +157 -0
- swarmauri_state_clipboard-0.6.1.dev16/swarmauri_state_clipboard/ClipboardState.py +0 -74
- {swarmauri_state_clipboard-0.6.1.dev16 → swarmauri_state_clipboard-0.7.0.dev3}/LICENSE +0 -0
- {swarmauri_state_clipboard-0.6.1.dev16 → swarmauri_state_clipboard-0.7.0.dev3}/README.md +0 -0
- {swarmauri_state_clipboard-0.6.1.dev16 → swarmauri_state_clipboard-0.7.0.dev3}/swarmauri_state_clipboard/__init__.py +0 -0
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: swarmauri_state_clipboard
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0.dev3
|
|
4
4
|
Summary: Swarmauri Community Clipboard State
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Author: Jacob Stewart
|
|
7
7
|
Author-email: jacob@swarmauri.com
|
|
8
8
|
Requires-Python: >=3.10,<3.13
|
|
9
9
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
10
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Requires-Dist:
|
|
15
|
-
Requires-Dist:
|
|
16
|
-
Requires-Dist: swarmauri_core (>=0.6.1.dev16,<0.7.0)
|
|
17
|
-
Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
|
|
13
|
+
Requires-Dist: swarmauri_base
|
|
14
|
+
Requires-Dist: swarmauri_core
|
|
18
15
|
Description-Content-Type: text/markdown
|
|
19
16
|
|
|
20
17
|

|
{swarmauri_state_clipboard-0.6.1.dev16 → swarmauri_state_clipboard-0.7.0.dev3}/pyproject.toml
RENAMED
|
@@ -1,57 +1,58 @@
|
|
|
1
|
-
[
|
|
1
|
+
[project]
|
|
2
2
|
name = "swarmauri_state_clipboard"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.0.dev3"
|
|
4
4
|
description = "Swarmauri Community Clipboard State"
|
|
5
|
-
authors = ["Jacob Stewart <jacob@swarmauri.com>"]
|
|
6
5
|
license = "Apache-2.0"
|
|
7
6
|
readme = "README.md"
|
|
8
7
|
repository = "http://github.com/swarmauri/swarmauri-sdk"
|
|
8
|
+
requires-python = ">=3.10,<3.13"
|
|
9
9
|
classifiers = [
|
|
10
10
|
"License :: OSI Approved :: Apache Software License",
|
|
11
11
|
"Programming Language :: Python :: 3.10",
|
|
12
12
|
"Programming Language :: Python :: 3.11",
|
|
13
|
-
"Programming Language :: Python :: 3.12"
|
|
13
|
+
"Programming Language :: Python :: 3.12",
|
|
14
14
|
]
|
|
15
|
+
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
16
|
+
dependencies = ["swarmauri_core", "swarmauri_base"]
|
|
15
17
|
|
|
16
|
-
[tool.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# Swarmauri
|
|
20
|
-
swarmauri_core = {version = "^0.6.1.dev16"}
|
|
21
|
-
swarmauri_base = {version = "^0.6.1.dev16"}
|
|
22
|
-
|
|
23
|
-
# dependencies
|
|
24
|
-
pyperclip = "^1.8.3"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
[tool.poetry.group.dev.dependencies]
|
|
28
|
-
flake8 = "^7.0"
|
|
29
|
-
pytest = "^8.0"
|
|
30
|
-
pytest-asyncio = ">=0.24.0"
|
|
31
|
-
pytest-xdist = "^3.6.1"
|
|
32
|
-
pytest-json-report = "^1.5.0"
|
|
33
|
-
python-dotenv = "*"
|
|
34
|
-
requests = "^2.32.3"
|
|
35
|
-
|
|
36
|
-
[build-system]
|
|
37
|
-
requires = ["poetry-core>=1.0.0"]
|
|
38
|
-
build-backend = "poetry.core.masonry.api"
|
|
18
|
+
[tool.uv.sources]
|
|
19
|
+
swarmauri_core = { workspace = true }
|
|
20
|
+
swarmauri_base = { workspace = true }
|
|
39
21
|
|
|
40
22
|
[tool.pytest.ini_options]
|
|
41
23
|
norecursedirs = ["combined", "scripts"]
|
|
42
|
-
|
|
43
24
|
markers = [
|
|
44
25
|
"test: standard test",
|
|
45
26
|
"unit: Unit tests",
|
|
46
|
-
"
|
|
27
|
+
"i9n: Integration tests",
|
|
28
|
+
"r8n: Regression tests",
|
|
29
|
+
"timeout: mark test to timeout after X seconds",
|
|
30
|
+
"xpass: Expected passes",
|
|
31
|
+
"xfail: Expected failures",
|
|
47
32
|
"acceptance: Acceptance tests",
|
|
48
|
-
"experimental: Experimental tests"
|
|
49
33
|
]
|
|
34
|
+
timeout = 300
|
|
50
35
|
log_cli = true
|
|
51
36
|
log_cli_level = "INFO"
|
|
52
37
|
log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
|
|
53
38
|
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
|
54
39
|
asyncio_default_fixture_loop_scope = "function"
|
|
55
40
|
|
|
56
|
-
[tool.
|
|
57
|
-
ClipboardState = "swarmauri_state_clipboard.ClipboardState:ClipboardState"
|
|
41
|
+
[tool.project.entry-points."swarmauri.states"]
|
|
42
|
+
ClipboardState = "swarmauri_state_clipboard.ClipboardState:ClipboardState"
|
|
43
|
+
[build-system]
|
|
44
|
+
requires = ["poetry-core>=1.0.0"]
|
|
45
|
+
build-backend = "poetry.core.masonry.api"
|
|
46
|
+
|
|
47
|
+
[dependency-groups]
|
|
48
|
+
dev = [
|
|
49
|
+
"pytest>=8.0",
|
|
50
|
+
"pytest-asyncio>=0.24.0",
|
|
51
|
+
"pytest-xdist>=3.6.1",
|
|
52
|
+
"pytest-json-report>=1.5.0",
|
|
53
|
+
"python-dotenv",
|
|
54
|
+
"requests>=2.32.3",
|
|
55
|
+
"flake8>=7.0",
|
|
56
|
+
"pytest-timeout>=2.3.1",
|
|
57
|
+
"ruff>=0.9.9",
|
|
58
|
+
]
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides a ClipboardState class that implements a system clipboard-based approach
|
|
3
|
+
to storing and retrieving state data. It uses only built-in Python modules and platform-specific
|
|
4
|
+
commands (clip on Windows, pbcopy/pbpaste on macOS, xclip on Linux).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
from typing import Dict, Literal
|
|
10
|
+
|
|
11
|
+
from swarmauri_base.ComponentBase import ComponentBase
|
|
12
|
+
from swarmauri_base.state.StateBase import StateBase
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@ComponentBase.register_type(StateBase, "ClipboardState")
|
|
16
|
+
class ClipboardState(StateBase):
|
|
17
|
+
"""A concrete implementation of StateBase that uses the system clipboard
|
|
18
|
+
to store and retrieve state data.
|
|
19
|
+
|
|
20
|
+
The class relies on the standard library for subprocess calls to external
|
|
21
|
+
commands available on each platform. If these commands are missing, a
|
|
22
|
+
FileNotFoundError or subprocess.CalledProcessError may be raised.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
type: Literal["ClipboardState"] = "ClipboardState"
|
|
26
|
+
|
|
27
|
+
@classmethod
|
|
28
|
+
def clipboard_paste(cls, text: str) -> None:
|
|
29
|
+
"""Copy the given text to the system clipboard using standard library calls.
|
|
30
|
+
|
|
31
|
+
text (str): The text to copy to the clipboard.
|
|
32
|
+
RETURNS (None): This method does not return anything.
|
|
33
|
+
RAISES (FileNotFoundError, subprocess.CalledProcessError):
|
|
34
|
+
If the underlying system command is unavailable or fails.
|
|
35
|
+
"""
|
|
36
|
+
platform = sys.platform
|
|
37
|
+
if platform.startswith("win"):
|
|
38
|
+
# Windows: uses 'clip' command
|
|
39
|
+
with subprocess.Popen(["clip"], stdin=subprocess.PIPE, text=True) as proc:
|
|
40
|
+
proc.communicate(text)
|
|
41
|
+
elif platform.startswith("darwin"):
|
|
42
|
+
# macOS: uses 'pbcopy'
|
|
43
|
+
with subprocess.Popen(["pbcopy"], stdin=subprocess.PIPE, text=True) as proc:
|
|
44
|
+
proc.communicate(text)
|
|
45
|
+
else:
|
|
46
|
+
# Linux/Unix: uses 'xclip'
|
|
47
|
+
with subprocess.Popen(
|
|
48
|
+
["xclip", "-selection", "clipboard"], stdin=subprocess.PIPE, text=True
|
|
49
|
+
) as proc:
|
|
50
|
+
proc.communicate(text)
|
|
51
|
+
|
|
52
|
+
@classmethod
|
|
53
|
+
def clipboard_copy(cls) -> str:
|
|
54
|
+
"""Retrieve text from the system clipboard using standard library calls.
|
|
55
|
+
|
|
56
|
+
RETURNS (str): The text contents of the system clipboard.
|
|
57
|
+
RAISES (FileNotFoundError, subprocess.CalledProcessError):
|
|
58
|
+
If the underlying system command is unavailable or fails.
|
|
59
|
+
"""
|
|
60
|
+
platform = sys.platform
|
|
61
|
+
if platform.startswith("win"):
|
|
62
|
+
# Windows: No direct paste command, so we use PowerShell
|
|
63
|
+
completed = subprocess.run(
|
|
64
|
+
["powershell", "-command", "Get-Clipboard"],
|
|
65
|
+
capture_output=True,
|
|
66
|
+
text=True,
|
|
67
|
+
)
|
|
68
|
+
return completed.stdout
|
|
69
|
+
elif platform.startswith("darwin"):
|
|
70
|
+
# macOS: uses 'pbpaste'
|
|
71
|
+
completed = subprocess.run(["pbpaste"], capture_output=True, text=True)
|
|
72
|
+
return completed.stdout
|
|
73
|
+
else:
|
|
74
|
+
# Linux/Unix: uses 'xclip'
|
|
75
|
+
completed = subprocess.run(
|
|
76
|
+
["xclip", "-selection", "clipboard", "-o"],
|
|
77
|
+
capture_output=True,
|
|
78
|
+
text=True,
|
|
79
|
+
)
|
|
80
|
+
return completed.stdout
|
|
81
|
+
|
|
82
|
+
def read(self) -> Dict[str, str]:
|
|
83
|
+
"""Read the current state from the system clipboard as a dictionary.
|
|
84
|
+
|
|
85
|
+
RETURNS (Dict[str, str]): The clipboard data parsed as a dictionary.
|
|
86
|
+
Returns an empty dictionary if clipboard content is empty.
|
|
87
|
+
RAISES (ValueError): If there is an error reading or parsing the state.
|
|
88
|
+
"""
|
|
89
|
+
try:
|
|
90
|
+
# Use the class method via the class
|
|
91
|
+
clipboard_content = self.__class__.clipboard_copy()
|
|
92
|
+
|
|
93
|
+
# For safety, replace eval with safer alternatives
|
|
94
|
+
if clipboard_content.strip():
|
|
95
|
+
import ast
|
|
96
|
+
|
|
97
|
+
# Use ast.literal_eval which is much safer than eval()
|
|
98
|
+
# It only evaluates literals, not arbitrary code
|
|
99
|
+
return ast.literal_eval(clipboard_content)
|
|
100
|
+
return {}
|
|
101
|
+
except Exception as e:
|
|
102
|
+
raise ValueError(f"Failed to read state from clipboard: {e}")
|
|
103
|
+
|
|
104
|
+
def write(self, data: Dict[str, str]) -> None:
|
|
105
|
+
"""Replace the current state with the given data by copying it to the clipboard.
|
|
106
|
+
|
|
107
|
+
data (Dict[str, str]): The state data to write.
|
|
108
|
+
RETURNS (None): This method does not return anything.
|
|
109
|
+
RAISES (ValueError): If there is an error writing to the clipboard.
|
|
110
|
+
"""
|
|
111
|
+
if isinstance(data, str):
|
|
112
|
+
raise ValueError("Must be data must be type Dict.")
|
|
113
|
+
try:
|
|
114
|
+
self.__class__.clipboard_paste(str(data))
|
|
115
|
+
except Exception as e:
|
|
116
|
+
raise ValueError(f"Failed to write state to clipboard: {e}")
|
|
117
|
+
|
|
118
|
+
def update(self, data: Dict[str, str]) -> None:
|
|
119
|
+
"""Update the current clipboard state by merging existing state with new data.
|
|
120
|
+
|
|
121
|
+
data (Dict[str, str]): The new state data to merge into the existing clipboard state.
|
|
122
|
+
RETURNS (None): This method does not return anything.
|
|
123
|
+
RAISES (ValueError): If there is an error updating the clipboard state.
|
|
124
|
+
"""
|
|
125
|
+
try:
|
|
126
|
+
current_state = self.read()
|
|
127
|
+
current_state.update(data)
|
|
128
|
+
self.write(current_state)
|
|
129
|
+
except Exception as e:
|
|
130
|
+
raise ValueError(f"Failed to update state on clipboard: {e}")
|
|
131
|
+
|
|
132
|
+
def reset(self) -> None:
|
|
133
|
+
"""Reset the clipboard state to an empty dictionary.
|
|
134
|
+
|
|
135
|
+
RETURNS (None): This method does not return anything.
|
|
136
|
+
RAISES (ValueError): If there is an error resetting the clipboard state.
|
|
137
|
+
"""
|
|
138
|
+
try:
|
|
139
|
+
self.write({})
|
|
140
|
+
except Exception as e:
|
|
141
|
+
raise ValueError(f"Failed to reset clipboard state: {e}")
|
|
142
|
+
|
|
143
|
+
def deep_copy(self) -> "ClipboardState":
|
|
144
|
+
"""Create a deep copy of the current state as a new ClipboardState instance.
|
|
145
|
+
|
|
146
|
+
RETURNS (ClipboardState): A new ClipboardState instance with the same clipboard data.
|
|
147
|
+
RAISES (ValueError): If there is an error creating the deep copy of the state.
|
|
148
|
+
"""
|
|
149
|
+
try:
|
|
150
|
+
current_state = self.read()
|
|
151
|
+
new_instance = ClipboardState()
|
|
152
|
+
new_instance.write(current_state)
|
|
153
|
+
return new_instance
|
|
154
|
+
except Exception as e:
|
|
155
|
+
raise ValueError(
|
|
156
|
+
f"Failed to create a deep copy of the clipboard state: {e}"
|
|
157
|
+
)
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import pyperclip
|
|
2
|
-
from typing import Dict, Any, Literal
|
|
3
|
-
from swarmauri_base.state.StateBase import StateBase
|
|
4
|
-
from swarmauri_core.ComponentBase import ComponentBase
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@ComponentBase.register_type(StateBase, "ClipboardState")
|
|
8
|
-
class ClipboardState(StateBase):
|
|
9
|
-
"""
|
|
10
|
-
A concrete implementation of StateBase that uses the system clipboard to store and retrieve state data.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
type: Literal["ClipboardState"] = "ClipboardState"
|
|
14
|
-
|
|
15
|
-
def read(self) -> Dict[str, Any]:
|
|
16
|
-
"""
|
|
17
|
-
Reads the current state from the clipboard as a dictionary.
|
|
18
|
-
"""
|
|
19
|
-
try:
|
|
20
|
-
clipboard_content = pyperclip.paste()
|
|
21
|
-
# Ensure the clipboard contains valid data (e.g., a JSON string that can be parsed)
|
|
22
|
-
if clipboard_content:
|
|
23
|
-
return eval(
|
|
24
|
-
clipboard_content
|
|
25
|
-
) # Replace eval with JSON for safer parsing
|
|
26
|
-
return {}
|
|
27
|
-
except Exception as e:
|
|
28
|
-
raise ValueError(f"Failed to read state from clipboard: {e}")
|
|
29
|
-
|
|
30
|
-
def write(self, data: Dict[str, Any]) -> None:
|
|
31
|
-
"""
|
|
32
|
-
Replaces the current state with the given data by copying it to the clipboard.
|
|
33
|
-
"""
|
|
34
|
-
try:
|
|
35
|
-
pyperclip.copy(
|
|
36
|
-
str(data)
|
|
37
|
-
) # Convert dictionary to string for clipboard storage
|
|
38
|
-
except Exception as e:
|
|
39
|
-
raise ValueError(f"Failed to write state to clipboard: {e}")
|
|
40
|
-
|
|
41
|
-
def update(self, data: Dict[str, Any]) -> None:
|
|
42
|
-
"""
|
|
43
|
-
Updates the current state with the given data by merging with clipboard content.
|
|
44
|
-
"""
|
|
45
|
-
try:
|
|
46
|
-
current_state = self.read()
|
|
47
|
-
current_state.update(data)
|
|
48
|
-
self.write(current_state)
|
|
49
|
-
except Exception as e:
|
|
50
|
-
raise ValueError(f"Failed to update state on clipboard: {e}")
|
|
51
|
-
|
|
52
|
-
def reset(self) -> None:
|
|
53
|
-
"""
|
|
54
|
-
Resets the clipboard state to an empty dictionary.
|
|
55
|
-
"""
|
|
56
|
-
try:
|
|
57
|
-
self.write({})
|
|
58
|
-
except Exception as e:
|
|
59
|
-
raise ValueError(f"Failed to reset clipboard state: {e}")
|
|
60
|
-
|
|
61
|
-
def deep_copy(self) -> "ClipboardState":
|
|
62
|
-
"""
|
|
63
|
-
Creates a deep copy of the current state. In this context, simply returns a new
|
|
64
|
-
ClipboardState with the same clipboard data.
|
|
65
|
-
"""
|
|
66
|
-
try:
|
|
67
|
-
current_state = self.read()
|
|
68
|
-
new_instance = ClipboardState()
|
|
69
|
-
new_instance.write(current_state)
|
|
70
|
-
return new_instance
|
|
71
|
-
except Exception as e:
|
|
72
|
-
raise ValueError(
|
|
73
|
-
f"Failed to create a deep copy of the clipboard state: {e}"
|
|
74
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|