rgwfuncs 0.0.80__tar.gz → 0.0.81__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.80
3
+ Version: 0.0.81
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.80"
7
+ version = "0.0.81"
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.80
3
+ version = 0.0.81
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,107 @@
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, unless the output appears to be a prompt.
23
+ """
24
+ def __init__(self, wrapped):
25
+ self.wrapped = wrapped
26
+ self.at_line_start = True
27
+
28
+ def write(self, s):
29
+ # If the written text exactly matches one of our prompt strings,
30
+ # assume it should be displayed as-is (the prompt will be white).
31
+ if s == sys.ps1 or s == sys.ps2:
32
+ self.wrapped.write(s)
33
+ return
34
+
35
+ # Process the text line by line so that each new line gets the blue color.
36
+ # (We only want to color “output”, not the prompt.)
37
+ lines = s.split('\n')
38
+ for i, line in enumerate(lines):
39
+ # Only prepend blue if we are at a new line.
40
+ if self.at_line_start and line:
41
+ self.wrapped.write(BLUE + line)
42
+ else:
43
+ self.wrapped.write(line)
44
+ # If this is not the last line, then the newline was in the string.
45
+ if i < len(lines) - 1:
46
+ self.wrapped.write('\n' + RESET) # reset after newline
47
+ self.at_line_start = True
48
+ else:
49
+ # If the last chunk is non-empty, we are in the middle of a line.
50
+ self.at_line_start = (line == "")
51
+ # Note: Do not flush automatically here.
52
+
53
+ def flush(self):
54
+ self.wrapped.flush()
55
+
56
+ def interactive_shell(local_vars: Dict[str, Any]) -> None:
57
+ """
58
+ Launches an interactive prompt for inspecting and modifying local variables,
59
+ making all methods in the rgwfuncs library available by default.
60
+ Persists command history across sessions.
61
+
62
+ Parameters:
63
+ local_vars (dict): Dictionary of local variables to be available in the interactive shell.
64
+ """
65
+ def setup_readline() -> None:
66
+ """Set up readline for history persistence."""
67
+ HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
68
+ readline.set_history_length(1000)
69
+ readline.parse_and_bind("tab: complete")
70
+ if os.path.exists(HISTORY_FILE):
71
+ try:
72
+ readline.read_history_file(HISTORY_FILE)
73
+ except Exception as e:
74
+ print(f"Warning: Could not load history file: {e}")
75
+ atexit.register(readline.write_history_file, HISTORY_FILE)
76
+
77
+ if not isinstance(local_vars, dict):
78
+ raise TypeError("local_vars must be a dictionary")
79
+
80
+ # Set up readline history and completion
81
+ setup_readline()
82
+
83
+ # Make imported functions available in the REPL
84
+ local_vars.update(globals())
85
+
86
+ # Set up custom prompts.
87
+ # The prompt text itself is printed in white.
88
+ sys.ps1 = WHITE + ">>> " + RESET
89
+ sys.ps2 = WHITE + "... " + RESET
90
+
91
+ # Wrap sys.stdout to emit blue-colored output.
92
+ sys.stdout = BlueStdout(sys.stdout)
93
+
94
+ # Create an interactive console with the provided locals.
95
+ console = code.InteractiveConsole(locals=local_vars)
96
+
97
+ # Custom banner and exit message
98
+ banner = ("Welcome to the rgwfuncs interactive shell.\n"
99
+ "Use up/down arrows for command history.\n"
100
+ "Type 'exit()' or Ctrl+D to quit.")
101
+ exitmsg = "Goodbye."
102
+
103
+ try:
104
+ console.interact(banner=banner)
105
+ finally:
106
+ print(exitmsg)
107
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.80
3
+ Version: 0.0.81
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,84 +0,0 @@
1
- import os
2
- import atexit
3
- import code
4
- import readline # Assuming this is imported elsewhere
5
- import sys
6
- from typing import Dict, Any
7
- from .df_lib import * # noqa: F401, F403, E402
8
- from .algebra_lib import * # noqa: F401, F403, E402
9
- from .str_lib import * # noqa: F401, F403, E402
10
- from .docs_lib import * # noqa: F401, F403, E402
11
-
12
- class CustomConsole(code.InteractiveConsole):
13
- """Custom console to make user input white while keeping prompts and output blue."""
14
- def raw_input(self, prompt=""):
15
- sys.stdout.write("\033[94m" + prompt) # Blue prompt
16
- sys.stdout.write("\033[97m") # White for input
17
- sys.stdout.flush()
18
- try:
19
- line = input() # User types in white
20
- except EOFError:
21
- raise
22
- finally:
23
- sys.stdout.write("\033[94m") # Back to blue
24
- sys.stdout.flush()
25
- return line
26
-
27
- def write(self, data):
28
- sys.stdout.write("\033[94m" + data) # Blue output
29
- sys.stdout.flush()
30
-
31
- def interactive_shell(local_vars: Dict[str, Any], shell_color: str = '\033[94m') -> None:
32
- """
33
- Launches an interactive prompt for inspecting and modifying local variables, making all methods
34
- in the rgwfuncs library available by default. Persists command history across sessions.
35
- User input is displayed in white; other text (prompt, banner, output) is blue.
36
-
37
- Parameters:
38
- local_vars (dict): Dictionary of local variables to be available in the interactive shell.
39
- shell_color (str): ANSI color code for shell output (default: blue '\033[94m').
40
- """
41
-
42
- def setup_readline(shell_color: str = '\033[94m') -> None:
43
- """Set up readline for history persistence with a given shell color."""
44
- HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
45
- readline.set_history_length(1000)
46
- readline.parse_and_bind("tab: complete")
47
- if os.path.exists(HISTORY_FILE):
48
- try:
49
- readline.read_history_file(HISTORY_FILE)
50
- except Exception as e:
51
- print(f"{shell_color}Warning: Could not load history file: {e}\033[94m")
52
- atexit.register(readline.write_history_file, HISTORY_FILE)
53
-
54
- if not isinstance(local_vars, dict):
55
- raise TypeError("local_vars must be a dictionary")
56
-
57
- # Test colors explicitly
58
- sys.stdout.write("\033[94mBLUE TEST\033[0m\n")
59
- sys.stdout.write("\033[97mWHITE TEST\033[0m\n")
60
- sys.stdout.flush()
61
-
62
- # Set initial color to blue
63
- sys.stdout.write("\033[94m")
64
- sys.stdout.flush()
65
-
66
- # Set up readline
67
- setup_readline()
68
-
69
- # Make imported functions available in the REPL
70
- local_vars.update(globals())
71
-
72
- # Set prompt (color handled by raw_input)
73
- sys.ps1 = ">>> "
74
-
75
- # Create custom console
76
- console = CustomConsole(locals=local_vars)
77
-
78
- # Banner and exit message in blue
79
- banner = f"{shell_color}Welcome to the rgwfuncs interactive shell.\nUse up/down arrows for command history.\nType 'exit()' or Ctrl+D to quit.\033[94m"
80
- exitmsg = f"{shell_color}Goodbye.\033[94m"
81
-
82
- # Run the interactive session
83
- console.interact(banner=banner, exitmsg=exitmsg)
84
-
File without changes
File without changes