rgwfuncs 0.0.84__tar.gz → 0.0.86__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.84
3
+ Version: 0.0.86
4
4
  Summary: A functional programming paradigm for mathematical modelling and data science
5
5
  Home-page: https://github.com/ryangerardwilson/rgwfunc
6
6
  Author: Ryan Gerard Wilson
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rgwfuncs"
7
- version = "0.0.84"
7
+ version = "0.0.86"
8
8
  authors = [
9
9
  { name = "Ryan Gerard Wilson", email = "ryangerardwilson@gmail.com" },
10
10
  ]
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = rgwfuncs
3
- version = 0.0.84
3
+ version = 0.0.86
4
4
  author = Ryan Gerard Wilson
5
5
  author_email = ryangerardwilson@gmail.com
6
6
  description = A functional programming paradigm for mathematical modelling and data science
@@ -0,0 +1,120 @@
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 blue-colored output and a prompt in white. An extra blank line is inserted
18
+ before each new input prompt.
19
+
20
+ local_vars: dictionary of local variables to be available in the interactive shell.
21
+ """
22
+
23
+ # ANSI color escape codes.
24
+ BLUE = "\033[94m"
25
+ WHITE = "\033[37m"
26
+ RESET = "\033[0m"
27
+
28
+ # Function to set up readline history.
29
+ def setup_readline() -> None:
30
+ HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
31
+ readline.set_history_length(1000)
32
+ readline.parse_and_bind("tab: complete")
33
+ if os.path.exists(HISTORY_FILE):
34
+ try:
35
+ readline.read_history_file(HISTORY_FILE)
36
+ except Exception as e:
37
+ print(f"Warning: Could not load history file: {e}")
38
+ atexit.register(readline.write_history_file, HISTORY_FILE)
39
+
40
+ # BlueStdout: wrap stdout so output is printed in blue.
41
+ class BlueStdout:
42
+ def __init__(self, wrapped):
43
+ self.wrapped = wrapped
44
+ self.at_line_start = True
45
+
46
+ def write(self, s):
47
+ # If s matches our prompt strings, write verbatim.
48
+ if s == sys.ps1 or s == sys.ps2:
49
+ self.wrapped.write(s)
50
+ return
51
+ # Write each new line in blue.
52
+ lines = s.split('\n')
53
+ for i, line in enumerate(lines):
54
+ if self.at_line_start and line:
55
+ self.wrapped.write(BLUE + line)
56
+ else:
57
+ self.wrapped.write(line)
58
+ if i < len(lines) - 1:
59
+ self.wrapped.write('\n' + RESET)
60
+ self.at_line_start = True
61
+ else:
62
+ self.at_line_start = (line == "")
63
+
64
+ def flush(self):
65
+ self.wrapped.flush()
66
+
67
+ def isatty(self):
68
+ return self.wrapped.isatty()
69
+
70
+ def fileno(self):
71
+ return self.wrapped.fileno()
72
+
73
+ def __getattr__(self, attr):
74
+ return getattr(self.wrapped, attr)
75
+
76
+ # ColorInteractiveConsole: subclass InteractiveConsole to restore the original
77
+ # stdout during input, and print an extra blank line before each prompt.
78
+ class ColorInteractiveConsole(code.InteractiveConsole):
79
+ def raw_input(self, prompt=""):
80
+ saved_stdout = sys.stdout
81
+ sys.stdout = sys.__stdout__
82
+ try:
83
+ # Print an extra newline before the prompt.
84
+ print("")
85
+ line = input(prompt)
86
+ except EOFError:
87
+ raise
88
+ finally:
89
+ sys.stdout = saved_stdout
90
+ return line
91
+
92
+ # Validate that local_vars is a dictionary.
93
+ if not isinstance(local_vars, dict):
94
+ raise TypeError("local_vars must be a dictionary")
95
+
96
+ setup_readline()
97
+
98
+ # Merge globals into local_vars.
99
+ local_vars.update(globals())
100
+
101
+ # Wrap ANSI color codes with markers for zero-width in the prompt.
102
+ sys.ps1 = "\001" + WHITE + "\002" + ">>> " + "\001" + RESET + "\002"
103
+ sys.ps2 = "\001" + WHITE + "\002" + "... " + "\001" + RESET + "\002"
104
+
105
+ # Use BlueStdout to wrap the original stdout.
106
+ sys.stdout = BlueStdout(sys.__stdout__)
107
+
108
+ # Create the custom interactive console.
109
+ console = ColorInteractiveConsole(locals=local_vars)
110
+
111
+ banner = ("Welcome to the rgwfuncs interactive shell.\n"
112
+ "Use up/down arrows for command history.\n"
113
+ "Type 'exit()' or Ctrl+D to quit.")
114
+ exitmsg = "Goodbye."
115
+
116
+ try:
117
+ console.interact(banner=banner)
118
+ finally:
119
+ print(exitmsg)
120
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.84
3
+ Version: 0.0.86
4
4
  Summary: A functional programming paradigm for mathematical modelling and data science
5
5
  Home-page: https://github.com/ryangerardwilson/rgwfunc
6
6
  Author: Ryan Gerard Wilson
@@ -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