corelp 1.0.37__py3-none-any.whl → 1.0.39__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.
- corelp/__init__.py +17 -10
- corelp/modules/Path_LP/functions/__template__.py +19 -0
- corelp/modules/Path_LP/test_Path.py +1 -1
- corelp/modules/debug_LP/functions/__template__.py +19 -0
- corelp/modules/folder_LP/functions/__template__.py +19 -0
- corelp/modules/getmodule_LP/functions/__template__.py +19 -0
- corelp/modules/getmodule_LP/getmodule.py +16 -33
- corelp/modules/icon_LP/functions/__init__.py +0 -0
- corelp/modules/icon_LP/functions/__template__.py +19 -0
- corelp/modules/icon_LP/icon.py +46 -0
- corelp/modules/icon_LP/test_icon.py +79 -0
- corelp/modules/kwargsself_LP/functions/__init__.py +0 -0
- corelp/modules/kwargsself_LP/functions/__template__.py +19 -0
- corelp/modules/prop_LP/functions/__init__.py +0 -0
- corelp/modules/prop_LP/functions/__template__.py +19 -0
- corelp/modules/rfrom_LP/functions/__init__.py +0 -0
- corelp/modules/rfrom_LP/functions/__template__.py +19 -0
- corelp/modules/rfrom_LP/test_rfrom.py +1 -1
- corelp/modules/selfkwargs_LP/functions/__init__.py +0 -0
- corelp/modules/selfkwargs_LP/functions/__template__.py +19 -0
- corelp/modules/test_LP/functions/__init__.py +0 -0
- corelp/modules/test_LP/functions/__template__.py +19 -0
- corelp/routines/__init__.py +0 -0
- {corelp-1.0.37.dist-info → corelp-1.0.39.dist-info}/METADATA +1 -6
- corelp-1.0.39.dist-info/RECORD +57 -0
- {corelp-1.0.37.dist-info → corelp-1.0.39.dist-info}/WHEEL +2 -2
- corelp/modules/Section_LP/Section.py +0 -176
- corelp/modules/Section_LP/test_Section.py +0 -43
- corelp/modules/main_LP/main.py +0 -251
- corelp/modules/main_LP/test_main.py +0 -74
- corelp/modules/print_LP/print.py +0 -326
- corelp/modules/print_LP/test_print.py +0 -108
- corelp/modules/user_inputs_LP/test_user_inputs.py +0 -46
- corelp/modules/user_inputs_LP/user_inputs.py +0 -87
- corelp/modules.json +0 -80
- corelp/pythonLP.png:Zone.Identifier +0 -0
- corelp/scripts.json +0 -1
- corelp-1.0.37.dist-info/RECORD +0 -49
- /corelp/modules/{Section_LP → Path_LP/functions}/__init__.py +0 -0
- /corelp/modules/{main_LP → debug_LP/functions}/__init__.py +0 -0
- /corelp/modules/{print_LP → folder_LP/functions}/__init__.py +0 -0
- /corelp/modules/{user_inputs_LP → getmodule_LP/functions}/__init__.py +0 -0
- /corelp/{scripts → modules/icon_LP}/__init__.py +0 -0
corelp/modules/print_LP/print.py
DELETED
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# Date : 2025-08-27
|
|
4
|
-
# Author : Lancelot PINCET
|
|
5
|
-
# GitHub : https://github.com/LancelotPincet
|
|
6
|
-
# Library : coreLP
|
|
7
|
-
# Module : print
|
|
8
|
-
|
|
9
|
-
"""
|
|
10
|
-
This function overrides python built in print function to add functionnalities.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# %% Libraries
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# %% Libraries
|
|
20
|
-
from corelp import prop
|
|
21
|
-
from dataclasses import dataclass, field
|
|
22
|
-
from datetime import datetime, timedelta
|
|
23
|
-
from numpy._core.numeric import True_
|
|
24
|
-
from rich import print as richprint
|
|
25
|
-
from rich.console import Console
|
|
26
|
-
from rich.theme import Theme
|
|
27
|
-
from rich.markdown import Markdown
|
|
28
|
-
from rich.traceback import Traceback
|
|
29
|
-
from rich.progress import (
|
|
30
|
-
Progress,
|
|
31
|
-
BarColumn,
|
|
32
|
-
TextColumn,
|
|
33
|
-
TaskProgressColumn,
|
|
34
|
-
TimeElapsedColumn,
|
|
35
|
-
TimeRemainingColumn,
|
|
36
|
-
ProgressColumn,
|
|
37
|
-
)
|
|
38
|
-
import traceback as tb_module
|
|
39
|
-
from time import perf_counter
|
|
40
|
-
from pathlib import Path
|
|
41
|
-
pyprint = print
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
# %% Class
|
|
46
|
-
@dataclass(slots=True, kw_only=True)
|
|
47
|
-
class Print() :
|
|
48
|
-
r"""
|
|
49
|
-
Enhanced replacement for the built-in :func:`print` function, adding muting,
|
|
50
|
-
logging, rich formatting, and progress utilities.
|
|
51
|
-
|
|
52
|
-
This class is callable and behaves like :func:`print`, with extra arguments.
|
|
53
|
-
|
|
54
|
-
Parameters
|
|
55
|
-
----------
|
|
56
|
-
*strings : tuple
|
|
57
|
-
The objects to print. Its :meth:`__str__` representation is used.
|
|
58
|
-
verbose : bool, optional
|
|
59
|
-
If ``True`` (default), printing is performed.
|
|
60
|
-
If ``False``, printing is skipped unless overridden.
|
|
61
|
-
return_string : bool, optional
|
|
62
|
-
If ``True``, return the processed string instead of ``None``.
|
|
63
|
-
file : str or pathlib.Path or None, optional
|
|
64
|
-
If provided, overrides the configured log file.
|
|
65
|
-
mode : {"w", "a"}, optional
|
|
66
|
-
File mode used when writing logs. Default is ``"a"``.
|
|
67
|
-
end : str, optional
|
|
68
|
-
End-of-line character(s). Defaults to ``"\n"``.
|
|
69
|
-
**kwargs :
|
|
70
|
-
Additional keyword arguments passed to :func:`print` or Rich's :func:`Console.print`.
|
|
71
|
-
|
|
72
|
-
Examples
|
|
73
|
-
--------
|
|
74
|
-
Basic usage::
|
|
75
|
-
|
|
76
|
-
>>> from corelp import print
|
|
77
|
-
>>> s = "Hello *world*!\nThis is a print **example**"
|
|
78
|
-
>>> print(s)
|
|
79
|
-
|
|
80
|
-
Muting::
|
|
81
|
-
|
|
82
|
-
>>> print.verbose = False
|
|
83
|
-
>>> print(s) # muted
|
|
84
|
-
>>> print(s, verbose=True) # forced printing
|
|
85
|
-
>>> print.verbose = True
|
|
86
|
-
>>> print(s) # prints again
|
|
87
|
-
>>> print(s, verbose=False) # forced mute
|
|
88
|
-
|
|
89
|
-
Access to underlying print functions::
|
|
90
|
-
|
|
91
|
-
>>> print.pyprint(s) # built-in print
|
|
92
|
-
>>> print.richprint(s) # rich.print
|
|
93
|
-
>>> print.print(s) # Console.print
|
|
94
|
-
>>> print.log(s) # Console.log
|
|
95
|
-
|
|
96
|
-
Logging::
|
|
97
|
-
|
|
98
|
-
>>> print.file = "log.txt"
|
|
99
|
-
>>> print("Hello") # also writes to file
|
|
100
|
-
|
|
101
|
-
Console styling::
|
|
102
|
-
|
|
103
|
-
>>> print.theme = {"success": "green"}
|
|
104
|
-
>>> print("Done!", style="success")
|
|
105
|
-
>>> try:
|
|
106
|
-
... 1/0
|
|
107
|
-
... except Exception:
|
|
108
|
-
... print.error()
|
|
109
|
-
>>> print.export_html("log.html")
|
|
110
|
-
|
|
111
|
-
Progress / Clock::
|
|
112
|
-
|
|
113
|
-
>>> from time import sleep
|
|
114
|
-
>>> for i in print.clock(15, "Outer"):
|
|
115
|
-
... for j in print.clock(10, "Inner"):
|
|
116
|
-
... sleep(1)
|
|
117
|
-
|
|
118
|
-
Attributes
|
|
119
|
-
----------
|
|
120
|
-
verbose : bool
|
|
121
|
-
Global muting switch.
|
|
122
|
-
pyprint : callable
|
|
123
|
-
Built-in Python :func:`print`.
|
|
124
|
-
richprint : callable
|
|
125
|
-
:mod:`rich` print function.
|
|
126
|
-
console : rich.console.Console
|
|
127
|
-
The Rich console instance used for styled printing.
|
|
128
|
-
file : pathlib.Path or None
|
|
129
|
-
Path to the log file.
|
|
130
|
-
progress : rich.progress.Progress
|
|
131
|
-
Active Rich progress manager.
|
|
132
|
-
bars : dict
|
|
133
|
-
Dictionary storing active progress bars.
|
|
134
|
-
theme : dict
|
|
135
|
-
Custom Rich style definitions.
|
|
136
|
-
"""
|
|
137
|
-
|
|
138
|
-
# Main function
|
|
139
|
-
def __call__(self, *strings, verbose=None, do_stdout=True, do_file=True, return_string=False, file=None, mode='a', end='\n', **kwargs) :
|
|
140
|
-
|
|
141
|
-
# Muting
|
|
142
|
-
verbose = verbose if verbose is not None else self.verbose
|
|
143
|
-
if not verbose :
|
|
144
|
-
return None
|
|
145
|
-
|
|
146
|
-
# Formatting string
|
|
147
|
-
string = ", ".join([str(string) for string in strings]) + end
|
|
148
|
-
|
|
149
|
-
# Printing markdown
|
|
150
|
-
if do_stdout :
|
|
151
|
-
string2print = Markdown(string) if self.apply_markdown else string
|
|
152
|
-
self.print(string2print, **kwargs)
|
|
153
|
-
|
|
154
|
-
# Writting to file
|
|
155
|
-
if do_file :
|
|
156
|
-
file = file if file is not None else self.file
|
|
157
|
-
if file is not None :
|
|
158
|
-
with open(Path(file), mode) as file :
|
|
159
|
-
file.write(string)
|
|
160
|
-
|
|
161
|
-
# Return
|
|
162
|
-
if return_string :
|
|
163
|
-
return string
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
# MUTING
|
|
167
|
-
verbose : bool = True # True to print
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
# PRINT
|
|
172
|
-
|
|
173
|
-
@property
|
|
174
|
-
def print(self) :
|
|
175
|
-
return self.console.print
|
|
176
|
-
@property
|
|
177
|
-
def log(self) :
|
|
178
|
-
return self.console.log
|
|
179
|
-
pyprint = pyprint # python print
|
|
180
|
-
richprint = richprint # rich prints
|
|
181
|
-
apply_markdown : bool = field(default=True, repr=False) # True to apply rich markdown formatting in prints
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
# LOGGING
|
|
186
|
-
|
|
187
|
-
_file : Path = None
|
|
188
|
-
@property
|
|
189
|
-
def file(self) :
|
|
190
|
-
return self._file
|
|
191
|
-
@file.setter
|
|
192
|
-
def file(self, value) :
|
|
193
|
-
self._file = Path(value)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
# CONSOLE
|
|
198
|
-
|
|
199
|
-
_theme = {}
|
|
200
|
-
@property
|
|
201
|
-
def theme(self) :
|
|
202
|
-
return self._theme
|
|
203
|
-
@theme.setter
|
|
204
|
-
def theme(self, value) :
|
|
205
|
-
self._theme.update(value)
|
|
206
|
-
self._console = None
|
|
207
|
-
|
|
208
|
-
_console : Console = field(default=None, repr=False)
|
|
209
|
-
@prop(cache=True)
|
|
210
|
-
def console(self) :
|
|
211
|
-
theme = Theme(self.theme)
|
|
212
|
-
return Console(theme=theme, record=True)
|
|
213
|
-
|
|
214
|
-
def error(self) :
|
|
215
|
-
rich_tb = Traceback.from_exception(*tb_module.sys.exc_info())
|
|
216
|
-
self.console.print(rich_tb)
|
|
217
|
-
|
|
218
|
-
def print_locals(self) :
|
|
219
|
-
self.console.log(log_locals=True)
|
|
220
|
-
|
|
221
|
-
def export_html(self, path) :
|
|
222
|
-
if path is None :
|
|
223
|
-
return
|
|
224
|
-
path = Path(path)
|
|
225
|
-
html_content = self.console.export_html(inline_styles=True)
|
|
226
|
-
with open(path, "w", encoding="utf-8") as file:
|
|
227
|
-
file.write(html_content)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
# CLOCK
|
|
232
|
-
|
|
233
|
-
def clock(self, iterable, title="Working...") :
|
|
234
|
-
|
|
235
|
-
# Get iterable
|
|
236
|
-
iterable = range(iterable) if isinstance(iterable, int) else iterable
|
|
237
|
-
iterable = list(iterable)
|
|
238
|
-
|
|
239
|
-
# Detect if progressbar already exists
|
|
240
|
-
first_bar = getattr(self, "_progress", None) is None
|
|
241
|
-
progress = self.progress
|
|
242
|
-
bars = self.bars
|
|
243
|
-
|
|
244
|
-
# Opens progress
|
|
245
|
-
if first_bar :
|
|
246
|
-
verbose = self.verbose
|
|
247
|
-
self.verbose = False
|
|
248
|
-
|
|
249
|
-
# Write to file
|
|
250
|
-
if self.file is not None :
|
|
251
|
-
with open(Path(self.file), "a") as file :
|
|
252
|
-
file.write(f'{title}...\n')
|
|
253
|
-
progress.start()
|
|
254
|
-
|
|
255
|
-
# Create new task
|
|
256
|
-
task = bars.get(title, None)
|
|
257
|
-
if task is None : # No bar with this name exists
|
|
258
|
-
task = progress.add_task(title, total=len(iterable), avg_time=0.0)
|
|
259
|
-
bars[title] = task # store it
|
|
260
|
-
else :
|
|
261
|
-
progress.reset(task)
|
|
262
|
-
|
|
263
|
-
# Loop
|
|
264
|
-
loop_counter = 0
|
|
265
|
-
start = perf_counter()
|
|
266
|
-
for item in iterable :
|
|
267
|
-
yield item
|
|
268
|
-
loop_counter += 1
|
|
269
|
-
elapsed = perf_counter() - start
|
|
270
|
-
avg_time = elapsed / loop_counter if loop_counter else 0
|
|
271
|
-
progress.update(task, advance=1, avg_time=avg_time)
|
|
272
|
-
|
|
273
|
-
# Clean up
|
|
274
|
-
if first_bar :
|
|
275
|
-
progress.stop()
|
|
276
|
-
del(self.bars)
|
|
277
|
-
del(self.progress)
|
|
278
|
-
self.verbose = verbose
|
|
279
|
-
|
|
280
|
-
_progress : Progress = field(default=None, repr=False)
|
|
281
|
-
@prop(cache=True)
|
|
282
|
-
def progress(self) :
|
|
283
|
-
return Progress(
|
|
284
|
-
TextColumn("{task.description}"),
|
|
285
|
-
BarColumn(),
|
|
286
|
-
TaskProgressColumn(),
|
|
287
|
-
TextColumn("[magenta]/{task.total}[/]"),
|
|
288
|
-
TimeElapsedColumn(),
|
|
289
|
-
AvgLoopTimeColumn(),
|
|
290
|
-
TimeRemainingColumn(),
|
|
291
|
-
EndTimeColumn(),
|
|
292
|
-
transient=False,
|
|
293
|
-
console=self.console
|
|
294
|
-
)
|
|
295
|
-
|
|
296
|
-
_bars : dict = field(default=None, repr=False)
|
|
297
|
-
@prop(cache=True)
|
|
298
|
-
def bars(self) :
|
|
299
|
-
return {}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
# Get instance
|
|
304
|
-
print = Print() # Instance to use everywhere
|
|
305
|
-
|
|
306
|
-
# Custom Progress bar columns
|
|
307
|
-
class AvgLoopTimeColumn(ProgressColumn):
|
|
308
|
-
def render(self, task):
|
|
309
|
-
avg_time = task.fields.get("avg_time", None)
|
|
310
|
-
if avg_time is not None and task.completed > 0:
|
|
311
|
-
string = f"[yellow]↻ {avg_time:.2f}s[/]" if avg_time > 1 else f"[yellow]↻ {avg_time*1000:.2f}ms[/]"
|
|
312
|
-
return string
|
|
313
|
-
return ""
|
|
314
|
-
class EndTimeColumn(ProgressColumn):
|
|
315
|
-
def render(self, task):
|
|
316
|
-
if task.time_remaining is not None:
|
|
317
|
-
end_time = datetime.now() + timedelta(seconds=task.time_remaining)
|
|
318
|
-
return f"[cyan]{end_time:%m-%d %H:%M:%S}[/] "
|
|
319
|
-
return ""
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
# %% Test function run
|
|
324
|
-
if __name__ == "__main__":
|
|
325
|
-
from corelp import test
|
|
326
|
-
test(__file__)
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# Date : 2025-08-27
|
|
4
|
-
# Author : Lancelot PINCET
|
|
5
|
-
# GitHub : https://github.com/LancelotPincet
|
|
6
|
-
# Library : coreLP
|
|
7
|
-
# Module : print
|
|
8
|
-
|
|
9
|
-
"""
|
|
10
|
-
This file allows to test print
|
|
11
|
-
|
|
12
|
-
print : This function overrides python built in print function to add functionnalities.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# %% Libraries
|
|
18
|
-
from corelp import print, debug
|
|
19
|
-
import pytest
|
|
20
|
-
from time import sleep
|
|
21
|
-
debug_folder = debug(__file__)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
# %% test prints
|
|
25
|
-
def test_print() :
|
|
26
|
-
'''
|
|
27
|
-
Test print
|
|
28
|
-
'''
|
|
29
|
-
string = "# TEST\nHello *world*!\n\nThis is 1 print **example**"
|
|
30
|
-
print(string, style="magenta")
|
|
31
|
-
print.print(string, style="magenta")
|
|
32
|
-
print.log(string, style="magenta")
|
|
33
|
-
print.pyprint(string)
|
|
34
|
-
print.richprint(string)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# %% test verbose
|
|
39
|
-
def test_verbose() :
|
|
40
|
-
'''
|
|
41
|
-
Test verbose
|
|
42
|
-
'''
|
|
43
|
-
print.verbose = False # Muting
|
|
44
|
-
print("Should not print") # Does not print
|
|
45
|
-
print("Should print", verbose=True) # Does print
|
|
46
|
-
print("Should not print") # Does not print
|
|
47
|
-
print.verbose = True # Unmuting
|
|
48
|
-
print("Should print") # Does print
|
|
49
|
-
print("Should not print", verbose=False) # Does not print
|
|
50
|
-
print("Should print") # Does print
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
# %% test logging
|
|
55
|
-
def test_logging() :
|
|
56
|
-
'''
|
|
57
|
-
Test logging
|
|
58
|
-
'''
|
|
59
|
-
print.theme = {"success" : "green"}
|
|
60
|
-
string = "# TEST\nHello *world*!\n\nThis is 1 print **example**"
|
|
61
|
-
print(string, style="success")
|
|
62
|
-
print.print_locals()
|
|
63
|
-
try :
|
|
64
|
-
1/0
|
|
65
|
-
except Exception :
|
|
66
|
-
print.error()
|
|
67
|
-
file = debug_folder / "log.html"
|
|
68
|
-
print.export_html(file)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# %% test console
|
|
73
|
-
def test_console() :
|
|
74
|
-
'''
|
|
75
|
-
Test console
|
|
76
|
-
'''
|
|
77
|
-
file = debug_folder / 'log.md'
|
|
78
|
-
print.file = file
|
|
79
|
-
string = "# TEST\nHello *world*!\n\nThis is 1 print **example**"
|
|
80
|
-
print(string, style="magenta")
|
|
81
|
-
assert file.exists()
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
# %% test clock
|
|
86
|
-
def test_clock() :
|
|
87
|
-
'''
|
|
88
|
-
Test clock
|
|
89
|
-
'''
|
|
90
|
-
for i in print.clock(5, "Outer loop") :
|
|
91
|
-
print("Should not print")
|
|
92
|
-
for j in print.clock(5, "Inner loop") :
|
|
93
|
-
sleep(1)
|
|
94
|
-
print("Should not print")
|
|
95
|
-
|
|
96
|
-
for i in print.clock(10, "Other loop") :
|
|
97
|
-
sleep(1)
|
|
98
|
-
print("Should not print")
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
# %% Test function run
|
|
106
|
-
if __name__ == "__main__":
|
|
107
|
-
from corelp import test
|
|
108
|
-
test(__file__)
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# Date : 2025-11-30
|
|
4
|
-
# Author : Lancelot PINCET
|
|
5
|
-
# GitHub : https://github.com/LancelotPincet
|
|
6
|
-
# Library : coreLP
|
|
7
|
-
# Module : user_inputs
|
|
8
|
-
|
|
9
|
-
"""
|
|
10
|
-
This file allows to test user_inputs
|
|
11
|
-
|
|
12
|
-
user_inputs : Gets last user inputs dictionnary from global variables.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# %% Libraries
|
|
18
|
-
from corelp import print, debug
|
|
19
|
-
import pytest
|
|
20
|
-
from corelp import user_inputs
|
|
21
|
-
debug_folder = debug(__file__)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# %% Function test
|
|
26
|
-
def test_user_inputs() :
|
|
27
|
-
'''
|
|
28
|
-
Test user_inputs function
|
|
29
|
-
'''
|
|
30
|
-
user_inputs() #init
|
|
31
|
-
a = 1
|
|
32
|
-
inputs = user_inputs()
|
|
33
|
-
if inputs != {'a': 1} :
|
|
34
|
-
raise ValueError(f'{inputs} should be dict(a=1)')
|
|
35
|
-
user_inputs() #init
|
|
36
|
-
b = 2
|
|
37
|
-
inputs = user_inputs()
|
|
38
|
-
if inputs != {'b': 2} :
|
|
39
|
-
raise ValueError(f'{inputs} should be dict(b=2)')
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
# %% Test function run
|
|
44
|
-
if __name__ == "__main__":
|
|
45
|
-
from corelp import test
|
|
46
|
-
test(__file__)
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# Date : 2025-11-30
|
|
4
|
-
# Author : Lancelot PINCET
|
|
5
|
-
# GitHub : https://github.com/LancelotPincet
|
|
6
|
-
# Library : coreLP
|
|
7
|
-
# Module : user_inputs
|
|
8
|
-
|
|
9
|
-
"""
|
|
10
|
-
Gets last user inputs dictionnary from global variables.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# %% Libraries
|
|
16
|
-
import inspect
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# %% Function
|
|
21
|
-
|
|
22
|
-
def user_inputs(reset=False) :
|
|
23
|
-
r"""
|
|
24
|
-
Return a dictionary of variables defined by the user in the interactive environment.
|
|
25
|
-
|
|
26
|
-
Parameters
|
|
27
|
-
----------
|
|
28
|
-
reset : bool or str
|
|
29
|
-
True to set as first call, String value to define a group of parameters
|
|
30
|
-
|
|
31
|
-
Returns
|
|
32
|
-
-------
|
|
33
|
-
dict
|
|
34
|
-
A dictionary containing the user's currently defined variables.
|
|
35
|
-
|
|
36
|
-
Examples
|
|
37
|
-
--------
|
|
38
|
-
>>> from corelp import user_inputs
|
|
39
|
-
>>> user_inputs(True) # First call (initializes and clears import-related variables)
|
|
40
|
-
None
|
|
41
|
-
>>> a = 1 # User defines a variable
|
|
42
|
-
>>> user_inputs() # Now returns: {'a': 1}
|
|
43
|
-
{'a': 1}
|
|
44
|
-
"""
|
|
45
|
-
frame = inspect.currentframe().f_back
|
|
46
|
-
ns = {**frame.f_globals, **frame.f_locals}
|
|
47
|
-
|
|
48
|
-
# ---- Filter user variables (ignore internals starting with "_") ----
|
|
49
|
-
ns = {key: value for key, value in ns.items() if not key.startswith("_")}
|
|
50
|
-
|
|
51
|
-
# Validate status
|
|
52
|
-
if reset :
|
|
53
|
-
user_inputs.current_group = reset if isinstance(reset, str) else None
|
|
54
|
-
user_inputs.cache = None
|
|
55
|
-
|
|
56
|
-
# Case when user_inputs is on top : cache = None
|
|
57
|
-
if user_inputs.cache is None :
|
|
58
|
-
user_inputs.cache = ns
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
# Case when user_inputs is at bottom : cache = dict
|
|
62
|
-
else :
|
|
63
|
-
updated = { key: value for key, value in ns.items() if key not in user_inputs.cache or user_inputs.cache[key] is not value}
|
|
64
|
-
values = {key: value for key, value in updated.items() if not key.endswith('_')}
|
|
65
|
-
comments = {key: value for key, value in updated.items() if key.endswith('_')}
|
|
66
|
-
|
|
67
|
-
# Group values
|
|
68
|
-
if user_inputs.current_group is not None :
|
|
69
|
-
user_inputs.groups_values[user_inputs.current_group] = values
|
|
70
|
-
user_inputs.groups_comments[user_inputs.current_group] = comments
|
|
71
|
-
|
|
72
|
-
# End
|
|
73
|
-
user_inputs.current_group = None
|
|
74
|
-
user_inputs.cache = None
|
|
75
|
-
return values
|
|
76
|
-
|
|
77
|
-
user_inputs.cache = None
|
|
78
|
-
user_inputs.current_group = None
|
|
79
|
-
user_inputs.groups_values = {}
|
|
80
|
-
user_inputs.groups_comments = {}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
# %% Test function run
|
|
85
|
-
if __name__ == "__main__":
|
|
86
|
-
from corelp import test
|
|
87
|
-
test(__file__)
|
corelp/modules.json
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Path": {
|
|
3
|
-
"date": "2025-09-02",
|
|
4
|
-
"description": "This function is a wrapper around the pathlib.Path and returns a compatible Path with a windows path copied inside Linux (for WSL)",
|
|
5
|
-
"module": "modules/Path_LP/Path",
|
|
6
|
-
"object": "Path"
|
|
7
|
-
},
|
|
8
|
-
"Section": {
|
|
9
|
-
"date": "2025-08-28",
|
|
10
|
-
"description": "This class defines decorator instances allowing to create section functions.",
|
|
11
|
-
"module": "modules/Section_LP/Section",
|
|
12
|
-
"object": "Section"
|
|
13
|
-
},
|
|
14
|
-
"debug": {
|
|
15
|
-
"date": "2025-08-25",
|
|
16
|
-
"description": "This function will give and create the debug folder for a given python file.",
|
|
17
|
-
"module": "modules/debug_LP/debug",
|
|
18
|
-
"object": "debug"
|
|
19
|
-
},
|
|
20
|
-
"folder": {
|
|
21
|
-
"date": "2025-08-25",
|
|
22
|
-
"description": "This function creates a new folder, while crushing previous instances if already exists.",
|
|
23
|
-
"module": "modules/folder_LP/folder",
|
|
24
|
-
"object": "folder"
|
|
25
|
-
},
|
|
26
|
-
"getmodule": {
|
|
27
|
-
"date": "2025-08-25",
|
|
28
|
-
"description": "This function is to be used in a library __init__ file. It creates lazy imports of the module imported and defines __getattr__ and __all__ for this library.",
|
|
29
|
-
"module": "modules/getmodule_LP/getmodule",
|
|
30
|
-
"object": "getmodule"
|
|
31
|
-
},
|
|
32
|
-
"kwargsself": {
|
|
33
|
-
"date": "2025-08-27",
|
|
34
|
-
"description": "This function will return all the attributes of an object (self) into a dictionnary (kwargs)",
|
|
35
|
-
"module": "modules/kwargsself_LP/kwargsself",
|
|
36
|
-
"object": "kwargsself"
|
|
37
|
-
},
|
|
38
|
-
"main": {
|
|
39
|
-
"date": "2025-08-28",
|
|
40
|
-
"description": "This function can decorate the main function of a script.",
|
|
41
|
-
"module": "modules/main_LP/main",
|
|
42
|
-
"object": "main"
|
|
43
|
-
},
|
|
44
|
-
"print": {
|
|
45
|
-
"date": "2025-08-27",
|
|
46
|
-
"description": "This function overrides python built in print function to add functionnalities.",
|
|
47
|
-
"module": "modules/print_LP/print",
|
|
48
|
-
"object": "print"
|
|
49
|
-
},
|
|
50
|
-
"prop": {
|
|
51
|
-
"date": "2025-08-25",
|
|
52
|
-
"description": "This function serves as an improved property decorator.",
|
|
53
|
-
"module": "modules/prop_LP/prop",
|
|
54
|
-
"object": "prop"
|
|
55
|
-
},
|
|
56
|
-
"rfrom": {
|
|
57
|
-
"date": "2025-08-29",
|
|
58
|
-
"description": "This function allows to do a relative import that works in module and script modes.",
|
|
59
|
-
"module": "modules/rfrom_LP/rfrom",
|
|
60
|
-
"object": "rfrom"
|
|
61
|
-
},
|
|
62
|
-
"selfkwargs": {
|
|
63
|
-
"date": "2025-08-27",
|
|
64
|
-
"description": "This function takes a dictionnary and sets all its values to an object (self).",
|
|
65
|
-
"module": "modules/selfkwargs_LP/selfkwargs",
|
|
66
|
-
"object": "selfkwargs"
|
|
67
|
-
},
|
|
68
|
-
"test": {
|
|
69
|
-
"date": "2025-08-25",
|
|
70
|
-
"description": "This function will launch the testfile for the current file using pytest library.",
|
|
71
|
-
"module": "modules/test_LP/test",
|
|
72
|
-
"object": "test"
|
|
73
|
-
},
|
|
74
|
-
"user_inputs": {
|
|
75
|
-
"date": "2025-11-30",
|
|
76
|
-
"description": "Gets last user inputs dictionnary from global variables.",
|
|
77
|
-
"module": "modules/user_inputs_LP/user_inputs",
|
|
78
|
-
"object": "user_inputs"
|
|
79
|
-
}
|
|
80
|
-
}
|
|
Binary file
|
corelp/scripts.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|