rgwfuncs 0.0.67__tar.gz → 0.0.69__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.67
3
+ Version: 0.0.69
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.67"
7
+ version = "0.0.69"
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.67
3
+ version = 0.0.69
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,75 @@
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
+
15
+ def interactive_shell(local_vars: Dict[str, Any], shell_color: str = '\033[37m') -> None:
16
+ """
17
+ Launches an interactive prompt for inspecting and modifying local variables, making all methods
18
+ in the rgwfuncs library available by default. Persists command history across sessions.
19
+
20
+ Parameters:
21
+ local_vars (dict): Dictionary of local variables to be available in the interactive shell.
22
+ shell_color (str): ANSI color code for shell output (default: non-bright white '\033[37m').
23
+ """
24
+
25
+ def setup_readline(shell_color: str = '\033[37m') -> None:
26
+ """Set up readline for command history persistence with a given shell color."""
27
+ HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
28
+ readline.set_history_length(1000) # Limit history to 1000 lines
29
+ readline.parse_and_bind("tab: complete") # Enable tab completion
30
+ if os.path.exists(HISTORY_FILE):
31
+ try:
32
+ readline.read_history_file(HISTORY_FILE)
33
+ except Exception as e:
34
+ print(f"{shell_color}Warning: Could not load history file: {e}\033[0m")
35
+ atexit.register(readline.write_history_file, HISTORY_FILE)
36
+
37
+
38
+ def colorize_output(text: str, shell_color: str) -> str:
39
+ """Apply shell color to text if it doesn’t already contain ANSI codes."""
40
+ if '\033[' not in text:
41
+ return f"{shell_color}{text}\033[0m"
42
+ return text
43
+
44
+
45
+ if not isinstance(local_vars, dict):
46
+ raise TypeError("local_vars must be a dictionary")
47
+
48
+ # Set up readline for history and completion
49
+ setup_readline(shell_color)
50
+
51
+ # Make imported functions available in the REPL
52
+ local_vars.update(globals())
53
+
54
+ # Create interactive console with local context
55
+ console = code.InteractiveConsole(locals=local_vars)
56
+
57
+ # Start interactive session with a custom banner and exit message
58
+ 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[0m"
59
+ exitmsg = f"{shell_color}Goodbye.\033[0m"
60
+
61
+ # Save original stdout write function
62
+ original_write = sys.stdout.write
63
+
64
+ # Define a pure function to wrap stdout.write
65
+ def colored_write(text: str) -> None:
66
+ original_write(colorize_output(text, shell_color))
67
+
68
+ # Temporarily replace stdout.write
69
+ sys.stdout.write = colored_write
70
+
71
+ # Start the interactive session
72
+ console.interact(banner=banner, exitmsg=exitmsg)
73
+
74
+ # Restore original stdout.write after exiting
75
+ sys.stdout.write = original_write
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.67
3
+ Version: 0.0.69
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,32 +0,0 @@
1
- import code
2
- import readline
3
- import rlcompleter # noqa: F401
4
- import sys # noqa: F401
5
- from typing import Dict, Any
6
- from .df_lib import * # noqa: F401, F403, E402
7
- from .algebra_lib import * # noqa: F401, F403, E402
8
- from .str_lib import * # noqa: F401, F403, E402
9
- from .docs_lib import * # noqa: F401, F403, E402
10
-
11
-
12
- def interactive_shell(local_vars: Dict[str, Any]) -> None:
13
- """
14
- Launches an interactive prompt for inspecting and modifying local variables, making all methods
15
- in the rgwfuncs library available by default.
16
-
17
- Parameters:
18
- local_vars (dict): Dictionary of local variables to be available in the interactive shell.
19
- """
20
- if not isinstance(local_vars, dict):
21
- raise TypeError("local_vars must be a dictionary")
22
-
23
- readline.parse_and_bind("tab: complete")
24
-
25
- # Make imported functions available in the REPL
26
- local_vars.update(globals())
27
-
28
- # Create interactive console with local context
29
- console = code.InteractiveConsole(locals=local_vars)
30
-
31
- # Start interactive session
32
- console.interact(banner="Welcome to the rgwfuncs interactive shell.")
File without changes
File without changes