rgwfuncs 0.0.68__py3-none-any.whl → 0.0.70__py3-none-any.whl

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/__init__.py CHANGED
@@ -2,7 +2,7 @@
2
2
  # Dynamically importing functions from modules
3
3
 
4
4
  from .df_lib import append_columns, append_percentile_classification_column, append_ranged_classification_column, append_ranged_date_classification_column, append_rows, append_xgb_labels, append_xgb_logistic_regression_predictions, append_xgb_regression_predictions, bag_union_join, bottom_n_unique_values, cascade_sort, delete_rows, drop_duplicates, drop_duplicates_retain_first, drop_duplicates_retain_last, filter_dataframe, filter_indian_mobiles, first_n_rows, from_raw_data, insert_dataframe_in_sqlite_database, last_n_rows, left_join, limit_dataframe, load_data_from_path, load_data_from_query, load_data_from_sqlite_path, load_fresh_data_or_pull_from_cache, mask_against_dataframe, mask_against_dataframe_converse, numeric_clean, order_columns, print_correlation, print_dataframe, print_memory_usage, print_n_frequency_cascading, print_n_frequency_linear, rename_columns, retain_columns, right_join, send_data_to_email, send_data_to_slack, send_dataframe_via_telegram, sync_dataframe_to_sqlite_database, top_n_unique_values, union_join, update_rows
5
- from .interactive_shell_lib import interactive_shell, setup_readline
5
+ from .interactive_shell_lib import interactive_shell
6
6
  from .algebra_lib import cancel_polynomial_expression, compute_constant_expression, compute_constant_expression_involving_matrices, compute_constant_expression_involving_ordered_series, compute_prime_factors, expand_polynomial_expression, factor_polynomial_expression, plot_polynomial_functions, plot_x_points_of_polynomial_functions, python_polynomial_expression_to_latex, simplify_polynomial_expression, solve_homogeneous_polynomial_expression
7
7
  from .docs_lib import docs
8
8
  from .str_lib import send_telegram_message
@@ -2,7 +2,7 @@
2
2
  import code
3
3
  import readline
4
4
  import rlcompleter # noqa: F401
5
- import sys # noqa: F401
5
+ import sys
6
6
  import os
7
7
  import atexit
8
8
  from typing import Dict, Any
@@ -11,33 +11,40 @@ from .algebra_lib import * # noqa: F401, F403, E402
11
11
  from .str_lib import * # noqa: F401, F403, E402
12
12
  from .docs_lib import * # noqa: F401, F403, E402
13
13
 
14
- # File for command history
15
- HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
16
-
17
- def setup_readline():
18
- """Set up readline for command history persistence"""
19
- readline.set_history_length(1000) # Limit history to 1000 lines
20
- readline.parse_and_bind("tab: complete") # Enable tab completion
21
- if os.path.exists(HISTORY_FILE):
22
- try:
23
- readline.read_history_file(HISTORY_FILE)
24
- except Exception as e:
25
- print(f"Warning: Could not load history file: {e}")
26
- atexit.register(readline.write_history_file, HISTORY_FILE)
27
-
28
- def interactive_shell(local_vars: Dict[str, Any]) -> None:
14
+ def interactive_shell(local_vars: Dict[str, Any], shell_color: str = '\033[37m') -> None:
29
15
  """
30
16
  Launches an interactive prompt for inspecting and modifying local variables, making all methods
31
17
  in the rgwfuncs library available by default. Persists command history across sessions.
32
18
 
33
19
  Parameters:
34
20
  local_vars (dict): Dictionary of local variables to be available in the interactive shell.
21
+ shell_color (str): ANSI color code for shell output (default: non-bright white '\033[37m').
35
22
  """
23
+
24
+ def setup_readline(shell_color: str = '\033[37m') -> None:
25
+ """Set up readline for command history persistence with a given shell color."""
26
+ HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
27
+ readline.set_history_length(1000) # Limit history to 1000 lines
28
+ readline.parse_and_bind("tab: complete") # Enable tab completion
29
+ if os.path.exists(HISTORY_FILE):
30
+ try:
31
+ readline.read_history_file(HISTORY_FILE)
32
+ except Exception as e:
33
+ print(f"{shell_color}Warning: Could not load history file: {e}\033[0m")
34
+ atexit.register(readline.write_history_file, HISTORY_FILE)
35
+
36
+ def colorize_output(text: str, shell_color: str) -> str:
37
+ """Apply shell color to text only if it doesn’t already contain ANSI codes, preserving existing codes."""
38
+ # Check if the text contains any ANSI escape sequences
39
+ if '\033[' not in text and '\x1b[' not in text:
40
+ return f"{shell_color}{text}\033[0m"
41
+ return text # Return unchanged if it already has ANSI codes
42
+
36
43
  if not isinstance(local_vars, dict):
37
44
  raise TypeError("local_vars must be a dictionary")
38
45
 
39
46
  # Set up readline for history and completion
40
- setup_readline()
47
+ setup_readline(shell_color)
41
48
 
42
49
  # Make imported functions available in the REPL
43
50
  local_vars.update(globals())
@@ -45,6 +52,24 @@ def interactive_shell(local_vars: Dict[str, Any]) -> None:
45
52
  # Create interactive console with local context
46
53
  console = code.InteractiveConsole(locals=local_vars)
47
54
 
48
- # Start interactive session with a custom banner
49
- banner = "Welcome to the rgwfuncs interactive shell.\nUse up/down arrows for command history.\nType 'exit()' or Ctrl+D to quit."
50
- console.interact(banner=banner, exitmsg="Goodbye.")
55
+ # Start interactive session with a custom banner and exit message
56
+ 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"
57
+ exitmsg = f"{shell_color}Goodbye.\033[0m"
58
+
59
+ # Save original stdout write function
60
+ original_write = sys.stdout.write
61
+
62
+ # Define a pure function to wrap stdout.write
63
+ def colored_write(text: str) -> None:
64
+ # Pass text through colorize_output to handle coloring
65
+ colored_text = colorize_output(text, shell_color)
66
+ original_write(colored_text)
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.68
3
+ Version: 0.0.70
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
@@ -0,0 +1,12 @@
1
+ rgwfuncs/__init__.py,sha256=LSn54Tlyskcb6Wab_wUpPLB6UGMe5LdrB3GU88mDEbU,1712
2
+ rgwfuncs/algebra_lib.py,sha256=rKFITfpWfgdBswnbMUuS41XgndEt-jUVz2ObO_ik7eM,42234
3
+ rgwfuncs/df_lib.py,sha256=r6T-MwyDq9NAPW1Xf6NzSy7ZFicIKdemR-UKu6TZt5g,71111
4
+ rgwfuncs/docs_lib.py,sha256=y3wSAOPO3qsA4HZ7xAtW8HimM8w-c8hjcEzMRLJ96ao,1960
5
+ rgwfuncs/interactive_shell_lib.py,sha256=HqYtC-x9J42661d7a-wEOUuEUy0fRZjU3fn-EO6cf7E,3191
6
+ rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
7
+ rgwfuncs-0.0.70.dist-info/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
8
+ rgwfuncs-0.0.70.dist-info/METADATA,sha256=Ftf_xo3s8-m4kAzqxb2wTYOFMgnoXSlmSyKzXtJdVOg,60288
9
+ rgwfuncs-0.0.70.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ rgwfuncs-0.0.70.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
11
+ rgwfuncs-0.0.70.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
12
+ rgwfuncs-0.0.70.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- rgwfuncs/__init__.py,sha256=fvKoJHhjdgBeoUOrQ5bHAQbJdbTNF7a9hMEx71QF_Qo,1728
2
- rgwfuncs/algebra_lib.py,sha256=rKFITfpWfgdBswnbMUuS41XgndEt-jUVz2ObO_ik7eM,42234
3
- rgwfuncs/df_lib.py,sha256=r6T-MwyDq9NAPW1Xf6NzSy7ZFicIKdemR-UKu6TZt5g,71111
4
- rgwfuncs/docs_lib.py,sha256=y3wSAOPO3qsA4HZ7xAtW8HimM8w-c8hjcEzMRLJ96ao,1960
5
- rgwfuncs/interactive_shell_lib.py,sha256=Zu0c_7CWsXPyA7FeCzJiw4xtm4_BrU7oC8fvWX6nLqw,1928
6
- rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
7
- rgwfuncs-0.0.68.dist-info/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
8
- rgwfuncs-0.0.68.dist-info/METADATA,sha256=BPjqpfQUU9azWFph9HHtxthuO65hQj0fJQ5ccbpeAQI,60288
9
- rgwfuncs-0.0.68.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
- rgwfuncs-0.0.68.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
11
- rgwfuncs-0.0.68.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
12
- rgwfuncs-0.0.68.dist-info/RECORD,,