rgwfuncs 0.0.84__tar.gz → 0.0.85__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.
- {rgwfuncs-0.0.84/src/rgwfuncs.egg-info → rgwfuncs-0.0.85}/PKG-INFO +1 -1
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/pyproject.toml +1 -1
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/setup.cfg +1 -1
- rgwfuncs-0.0.85/src/rgwfuncs/interactive_shell_lib.py +119 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85/src/rgwfuncs.egg-info}/PKG-INFO +1 -1
- rgwfuncs-0.0.84/src/rgwfuncs/interactive_shell_lib.py +0 -124
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/LICENSE +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/README.md +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs/__init__.py +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs/algebra_lib.py +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs/df_lib.py +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs/docs_lib.py +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs/str_lib.py +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs.egg-info/SOURCES.txt +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs.egg-info/dependency_links.txt +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs.egg-info/entry_points.txt +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs.egg-info/requires.txt +0 -0
- {rgwfuncs-0.0.84 → rgwfuncs-0.0.85}/src/rgwfuncs.egg-info/top_level.txt +0 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
import code
|
3
|
+
import readline
|
4
|
+
import rlcompleter # noqa: F401
|
5
|
+
import sys
|
6
|
+
import os
|
7
|
+
import atexit
|
8
|
+
from typing import Dict, Any
|
9
|
+
from .df_lib import * # noqa: F401, F403, E402
|
10
|
+
from .algebra_lib import * # noqa: F401, F403, E402
|
11
|
+
from .str_lib import * # noqa: F401, F403, E402
|
12
|
+
from .docs_lib import * # noqa: F401, F403, E402
|
13
|
+
|
14
|
+
def interactive_shell(local_vars: Dict[str, Any]) -> None:
|
15
|
+
"""
|
16
|
+
Launch an interactive prompt for inspecting and modifying local variables,
|
17
|
+
with a custom blue output and white prompt. All helper definitions are nested within.
|
18
|
+
|
19
|
+
local_vars: dictionary with local variables to be available in the interactive shell.
|
20
|
+
"""
|
21
|
+
|
22
|
+
# ANSI color escape codes.
|
23
|
+
BLUE = "\033[94m"
|
24
|
+
WHITE = "\033[37m"
|
25
|
+
RESET = "\033[0m"
|
26
|
+
|
27
|
+
# Helper: setup readline for history persistence.
|
28
|
+
def setup_readline() -> None:
|
29
|
+
HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
|
30
|
+
readline.set_history_length(1000)
|
31
|
+
readline.parse_and_bind("tab: complete")
|
32
|
+
if os.path.exists(HISTORY_FILE):
|
33
|
+
try:
|
34
|
+
readline.read_history_file(HISTORY_FILE)
|
35
|
+
except Exception as e:
|
36
|
+
print(f"Warning: Could not load history file: {e}")
|
37
|
+
atexit.register(readline.write_history_file, HISTORY_FILE)
|
38
|
+
|
39
|
+
# Nested BlueStdout: a wrapper for sys.stdout that prepends blue color on output.
|
40
|
+
class BlueStdout:
|
41
|
+
def __init__(self, wrapped):
|
42
|
+
self.wrapped = wrapped
|
43
|
+
self.at_line_start = True
|
44
|
+
|
45
|
+
def write(self, s):
|
46
|
+
# Do not interfere with the prompt strings.
|
47
|
+
if s == sys.ps1 or s == sys.ps2:
|
48
|
+
self.wrapped.write(s)
|
49
|
+
return
|
50
|
+
# Process output line by line.
|
51
|
+
lines = s.split('\n')
|
52
|
+
for i, line in enumerate(lines):
|
53
|
+
if self.at_line_start and line:
|
54
|
+
self.wrapped.write(BLUE + line)
|
55
|
+
else:
|
56
|
+
self.wrapped.write(line)
|
57
|
+
if i < len(lines) - 1:
|
58
|
+
self.wrapped.write('\n' + RESET)
|
59
|
+
self.at_line_start = True
|
60
|
+
else:
|
61
|
+
self.at_line_start = (line == "")
|
62
|
+
|
63
|
+
def flush(self):
|
64
|
+
self.wrapped.flush()
|
65
|
+
|
66
|
+
def isatty(self):
|
67
|
+
return self.wrapped.isatty()
|
68
|
+
|
69
|
+
def fileno(self):
|
70
|
+
return self.wrapped.fileno()
|
71
|
+
|
72
|
+
def __getattr__(self, attr):
|
73
|
+
return getattr(self.wrapped, attr)
|
74
|
+
|
75
|
+
# Nested ColorInteractiveConsole: a subclass of InteractiveConsole that temporarily
|
76
|
+
# restores the original stdout when reading input so that readline functions properly.
|
77
|
+
class ColorInteractiveConsole(code.InteractiveConsole):
|
78
|
+
def raw_input(self, prompt=""):
|
79
|
+
saved_stdout = sys.stdout
|
80
|
+
sys.stdout = sys.__stdout__
|
81
|
+
try:
|
82
|
+
line = input(prompt)
|
83
|
+
except EOFError:
|
84
|
+
raise
|
85
|
+
finally:
|
86
|
+
sys.stdout = saved_stdout
|
87
|
+
return line
|
88
|
+
|
89
|
+
# Ensure that the passed local_vars is a dictionary.
|
90
|
+
if not isinstance(local_vars, dict):
|
91
|
+
raise TypeError("local_vars must be a dictionary")
|
92
|
+
|
93
|
+
# Setup readline.
|
94
|
+
setup_readline()
|
95
|
+
|
96
|
+
# Make imported functions available in the REPL by merging globals.
|
97
|
+
local_vars.update(globals())
|
98
|
+
|
99
|
+
# Wrap ANSI escape sequences in markers recognized by readline so that they do not count
|
100
|
+
# toward the visible prompt length.
|
101
|
+
sys.ps1 = "\001" + WHITE + "\002" + ">>> " + "\001" + RESET + "\002"
|
102
|
+
sys.ps2 = "\001" + WHITE + "\002" + "... " + "\001" + RESET + "\002"
|
103
|
+
|
104
|
+
# Replace sys.stdout with our blue-printing wrapper.
|
105
|
+
sys.stdout = BlueStdout(sys.__stdout__)
|
106
|
+
|
107
|
+
# Instantiate our custom interactive console.
|
108
|
+
console = ColorInteractiveConsole(locals=local_vars)
|
109
|
+
|
110
|
+
banner = ("Welcome to the rgwfuncs interactive shell.\n"
|
111
|
+
"Use up/down arrows for command history.\n"
|
112
|
+
"Type 'exit()' or Ctrl+D to quit.")
|
113
|
+
exitmsg = "Goodbye."
|
114
|
+
|
115
|
+
try:
|
116
|
+
console.interact(banner=banner)
|
117
|
+
finally:
|
118
|
+
print(exitmsg)
|
119
|
+
|
@@ -1,124 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
import code
|
3
|
-
import readline
|
4
|
-
import rlcompleter # noqa: F401
|
5
|
-
import sys
|
6
|
-
import os
|
7
|
-
import atexit
|
8
|
-
from typing import Dict, Any
|
9
|
-
from .df_lib import * # noqa: F401, F403, E402
|
10
|
-
from .algebra_lib import * # noqa: F401, F403, E402
|
11
|
-
from .str_lib import * # noqa: F401, F403, E402
|
12
|
-
from .docs_lib import * # noqa: F401, F403, E402
|
13
|
-
|
14
|
-
# ANSI color escape codes
|
15
|
-
BLUE = "\033[34m"
|
16
|
-
WHITE = "\033[37m"
|
17
|
-
RESET = "\033[0m"
|
18
|
-
|
19
|
-
class BlueStdout:
|
20
|
-
"""
|
21
|
-
A wrapper for sys.stdout that automatically prepends blue
|
22
|
-
color codes on output.
|
23
|
-
"""
|
24
|
-
def __init__(self, wrapped):
|
25
|
-
self.wrapped = wrapped
|
26
|
-
self.at_line_start = True
|
27
|
-
|
28
|
-
def write(self, s):
|
29
|
-
# Do not interfere with prompt strings.
|
30
|
-
if s == sys.ps1 or s == sys.ps2:
|
31
|
-
self.wrapped.write(s)
|
32
|
-
return
|
33
|
-
|
34
|
-
# Process text line by line so that new lines are colored.
|
35
|
-
lines = s.split('\n')
|
36
|
-
for i, line in enumerate(lines):
|
37
|
-
if self.at_line_start and line:
|
38
|
-
self.wrapped.write(BLUE + line)
|
39
|
-
else:
|
40
|
-
self.wrapped.write(line)
|
41
|
-
if i < len(lines) - 1:
|
42
|
-
self.wrapped.write('\n' + RESET)
|
43
|
-
self.at_line_start = True
|
44
|
-
else:
|
45
|
-
self.at_line_start = (line == "")
|
46
|
-
|
47
|
-
def flush(self):
|
48
|
-
self.wrapped.flush()
|
49
|
-
|
50
|
-
def isatty(self):
|
51
|
-
return self.wrapped.isatty()
|
52
|
-
|
53
|
-
def fileno(self):
|
54
|
-
return self.wrapped.fileno()
|
55
|
-
|
56
|
-
def __getattr__(self, attr):
|
57
|
-
# Delegate attribute access to the original stdout.
|
58
|
-
return getattr(self.wrapped, attr)
|
59
|
-
|
60
|
-
class ColorInteractiveConsole(code.InteractiveConsole):
|
61
|
-
"""Subclass InteractiveConsole to temporarily restore the real stdout when reading input."""
|
62
|
-
def raw_input(self, prompt=""):
|
63
|
-
# Before calling input(), restore the original stdout so that readline works properly.
|
64
|
-
saved_stdout = sys.stdout
|
65
|
-
sys.stdout = sys.__stdout__
|
66
|
-
try:
|
67
|
-
line = input(prompt)
|
68
|
-
except EOFError:
|
69
|
-
raise
|
70
|
-
finally:
|
71
|
-
# Restore our blue-printing stdout.
|
72
|
-
sys.stdout = saved_stdout
|
73
|
-
return line
|
74
|
-
|
75
|
-
def interactive_shell(local_vars: Dict[str, Any]) -> None:
|
76
|
-
"""
|
77
|
-
Launches an interactive prompt for inspecting and modifying local variables,
|
78
|
-
making all methods in the rgwfuncs library available by default.
|
79
|
-
Persists command history across sessions.
|
80
|
-
|
81
|
-
Parameters:
|
82
|
-
local_vars (dict): Dictionary of local variables to be available in the interactive shell.
|
83
|
-
"""
|
84
|
-
def setup_readline() -> None:
|
85
|
-
"""Set up readline for history persistence."""
|
86
|
-
HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
|
87
|
-
readline.set_history_length(1000)
|
88
|
-
readline.parse_and_bind("tab: complete")
|
89
|
-
if os.path.exists(HISTORY_FILE):
|
90
|
-
try:
|
91
|
-
readline.read_history_file(HISTORY_FILE)
|
92
|
-
except Exception as e:
|
93
|
-
print(f"Warning: Could not load history file: {e}")
|
94
|
-
atexit.register(readline.write_history_file, HISTORY_FILE)
|
95
|
-
|
96
|
-
if not isinstance(local_vars, dict):
|
97
|
-
raise TypeError("local_vars must be a dictionary")
|
98
|
-
|
99
|
-
# Set up readline.
|
100
|
-
setup_readline()
|
101
|
-
|
102
|
-
# Make imported functions available in the REPL.
|
103
|
-
local_vars.update(globals())
|
104
|
-
|
105
|
-
# Note: Wrap ANSI codes in markers that readline understands so that they don’t count in prompt length.
|
106
|
-
sys.ps1 = "\001" + WHITE + "\002" + ">>> " + "\001" + RESET + "\002"
|
107
|
-
sys.ps2 = "\001" + WHITE + "\002" + "... " + "\001" + RESET + "\002"
|
108
|
-
|
109
|
-
# Wrap sys.stdout for colored output.
|
110
|
-
sys.stdout = BlueStdout(sys.__stdout__) # Wrap the original stdout.
|
111
|
-
|
112
|
-
# Use our custom interactive console.
|
113
|
-
console = ColorInteractiveConsole(locals=local_vars)
|
114
|
-
|
115
|
-
banner = ("Welcome to the rgwfuncs interactive shell.\n"
|
116
|
-
"Use up/down arrows for command history.\n"
|
117
|
-
"Type 'exit()' or Ctrl+D to quit.")
|
118
|
-
exitmsg = "Goodbye."
|
119
|
-
|
120
|
-
try:
|
121
|
-
console.interact(banner=banner)
|
122
|
-
finally:
|
123
|
-
print(exitmsg)
|
124
|
-
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|