corelp 1.0.32__py3-none-any.whl → 1.0.34__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.
@@ -14,7 +14,7 @@ This class defines decorator instances allowing to create section functions.
14
14
 
15
15
  # %% Libraries
16
16
  from corelp import print, folder, selfkwargs, kwargsself
17
- from dataclasses import dataclass, field
17
+ from dataclasses import dataclass
18
18
  import pickle
19
19
  import joblib
20
20
  from pathlib import Path
@@ -25,7 +25,7 @@ import types
25
25
 
26
26
 
27
27
  # %% Function
28
- def main() :
28
+ def main(*, import_path:str=None, export_path:str=None, new:bool=True, bulk=None, overnight:bool=False, run_name:str=None) :
29
29
  '''
30
30
  This function can decorate the main function of a script.
31
31
  User inputs parameters shoud be put in the beginning of the main file, and the decorated function will recognize them.
@@ -52,8 +52,8 @@ class Print() :
52
52
 
53
53
  Parameters
54
54
  ----------
55
- string : object
56
- The object to print. Its :meth:`__str__` representation is used.
55
+ *strings : tuple
56
+ The objects to print. Its :meth:`__str__` representation is used.
57
57
  verbose : bool, optional
58
58
  If ``True`` (default), printing is performed.
59
59
  If ``False``, printing is skipped unless overridden.
@@ -135,14 +135,17 @@ class Print() :
135
135
  """
136
136
 
137
137
  # Main function
138
- def __call__(self, string, verbose=None, *, return_string=False, file=None, mode='a', end='\n', **kwargs) :
138
+ def __call__(self, *strings, verbose=None, return_string=False, file=None, mode='a', end='\n', **kwargs) :
139
+
139
140
  # Muting
140
141
  verbose = verbose if verbose is not None else self.verbose
141
142
  if not verbose :
142
143
  return None
143
144
 
145
+ # Formatting string
146
+ string = ", ".join([str(string) for string in strings]) + end
147
+
144
148
  # Printing markdown
145
- string = str(string) + end
146
149
  self.print(Markdown(string), **kwargs)
147
150
 
148
151
  # Writting to file
@@ -170,7 +173,7 @@ class Print() :
170
173
  def log(self) :
171
174
  return self.console.log
172
175
  pyprint = pyprint # python print
173
- richprint = richprint # rich print
176
+ richprint = richprint # rich prints
174
177
 
175
178
 
176
179
 
@@ -281,7 +284,8 @@ class Print() :
281
284
  AvgLoopTimeColumn(),
282
285
  TimeRemainingColumn(),
283
286
  EndTimeColumn(),
284
- transient=False
287
+ transient=False,
288
+ console=self.console
285
289
  )
286
290
 
287
291
  _bars : dict = field(default=None, repr=False)
@@ -34,7 +34,8 @@ def test_user_inputs() :
34
34
  raise ValueError(f'{inputs} should be dict(a=1)')
35
35
  user_inputs() #init
36
36
  b = 2
37
- if user_inputs() != {'b': 2} :
37
+ inputs = user_inputs()
38
+ if inputs != {'b': 2} :
38
39
  raise ValueError(f'{inputs} should be dict(b=2)')
39
40
 
40
41
 
@@ -14,25 +14,19 @@ Gets last user inputs dictionnary from global variables.
14
14
 
15
15
  # %% Libraries
16
16
  import inspect
17
- from IPython import get_ipython
18
17
 
19
18
 
20
19
 
21
20
  # %% Function
22
- _user_inputs = {} # User inputs cache
23
21
 
24
- def user_inputs() :
22
+ def user_inputs(reset=False) :
25
23
  r"""
26
- Return a dictionary of variables defined by the user in the interactive
27
- environment.
24
+ Return a dictionary of variables defined by the user in the interactive environment.
28
25
 
29
- This function is intended for use inside other functions via
30
- ``function(**user_inputs())``.
31
- **It should not be used to store its return value**, e.g. **do not do**::
32
-
33
- variable = user_inputs()
34
-
35
- Instead, call it directly when needed.
26
+ Parameters
27
+ ----------
28
+ reset : bool
29
+ True to set as first call.
36
30
 
37
31
  Returns
38
32
  -------
@@ -42,36 +36,34 @@ def user_inputs() :
42
36
  Examples
43
37
  --------
44
38
  >>> from corelp import user_inputs
45
- >>> user_inputs() # First call (initializes and clears import-related variables)
46
- {}
39
+ >>> user_inputs(True) # First call (initializes and clears import-related variables)
40
+ None
47
41
  >>> a = 1 # User defines a variable
48
42
  >>> user_inputs() # Now returns: {'a': 1}
49
43
  {'a': 1}
50
44
  """
45
+ frame = inspect.currentframe().f_back
46
+ ns = {**frame.f_globals, **frame.f_locals}
51
47
 
52
- # ---- Detect execution environment ----
53
- ipy = get_ipython()
48
+ # ---- Filter user variables (ignore internals starting with "_") ----
49
+ ns = {key: value for key, value in ns.items() if not key.startswith("_")}
54
50
 
55
- if ipy is not None:
56
- # Running in IPython or Jupyter
57
- ns = ipy.user_ns
58
- else:
59
- # Running in normal Python script
60
- frame = inspect.currentframe().f_back
61
- ns = {**frame.f_globals, **frame.f_locals}
51
+ # Validate status
52
+ if reset :
53
+ user_inputs.cache = None
62
54
 
63
- # ---- Filter user variables (ignore internals starting with "_") ----
64
- ns = {k: v for k, v in ns.items() if not k.startswith("_")}
55
+ # Case when user_inputs is on top : cache = None
56
+ if user_inputs.cache is None :
57
+ user_inputs.cache = ns
58
+ return
65
59
 
66
- # ---- Return only new or updated variables ----
67
- updated = {
68
- k: v
69
- for k, v in ns.items()
70
- if k not in _user_inputs or _user_inputs[k] is not v
71
- }
60
+ # Case when user_inputs is at bottom : cache = dict
61
+ else :
62
+ updated = { key: value for key, value in ns.items() if key not in user_inputs.cache or user_inputs.cache[key] is not value}
63
+ user_inputs.cache = None
64
+ return updated
72
65
 
73
- _user_inputs.update(updated)
74
- return updated
66
+ user_inputs.cache = None
75
67
 
76
68
 
77
69
 
@@ -1,9 +1,7 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: corelp
3
- Version: 1.0.32
3
+ Version: 1.0.34
4
4
  Summary: A library that gathers core functions for python programming.
5
- Requires-Dist: ipython
6
- Requires-Dist: ipywidgets
7
5
  Requires-Dist: joblib
8
6
  Requires-Dist: rich
9
7
  Requires-Python: >=3.12
@@ -3,7 +3,7 @@ corelp/icon_pythonLP.png,sha256=pg386kYEKGspDDRbRF0alOmHXPEm0geMoYIPaxEfQ_o,3805
3
3
  corelp/modules/Path_LP/Path.py,sha256=wfvO1DuewIUSEA9_g66O5nCEp95Pr5XM-yxaOOEimTs,2418
4
4
  corelp/modules/Path_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  corelp/modules/Path_LP/test_Path.py,sha256=8VSn9VVbhc3EDxXpxQV18rnAq_T2a1uuoRFKdmsqX-I,715
6
- corelp/modules/Section_LP/Section.py,sha256=5h7DokassAh08iUqb2tCeEBOzsVLHD6HBuVhPM-iGIg,6067
6
+ corelp/modules/Section_LP/Section.py,sha256=LQwy3rb4XP3aq3mLtZRBg2AeTYX4bosnYJbIsCpbYIs,6060
7
7
  corelp/modules/Section_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  corelp/modules/Section_LP/test_Section.py,sha256=zcrIbJueMDT90t0_M-RD40IWpkx4OT7Q52tE6HzbfIo,812
9
9
  corelp/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -19,10 +19,10 @@ corelp/modules/kwargsself_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
19
19
  corelp/modules/kwargsself_LP/kwargsself.py,sha256=24HVn1G7ALdhQFSLT0U2dVjVzop6c2s-nr7DrMK53iw,1865
20
20
  corelp/modules/kwargsself_LP/test_kwargsself.py,sha256=BaqGu0bqFuFemiYUEDMviFfegTb0aF6lmeFm3KJa8sw,1241
21
21
  corelp/modules/main_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- corelp/modules/main_LP/main.py,sha256=vU9zXt6bLux1Fq6FiPwxhTJVo4SxJYeMbwKF0v_AjDs,10169
22
+ corelp/modules/main_LP/main.py,sha256=KHMcpptT2WV1THzFvjjyesbnY5oq0-4eC1_ewufoWug,10281
23
23
  corelp/modules/main_LP/test_main.py,sha256=mxL645pZdkJ8J5MFdj0K-z8xRCGKQ0zw1NvmW3iPGB4,1741
24
24
  corelp/modules/print_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- corelp/modules/print_LP/print.py,sha256=7TYjAGypT_TI0UHmL9F8zPL7gjFfJn2DnCpx0cu4IGM,8565
25
+ corelp/modules/print_LP/print.py,sha256=qPCqLpY2PdGLQaWmZKv9oh-MnvmpNYAplPeOcizO0uU,8662
26
26
  corelp/modules/print_LP/test_print.py,sha256=uMmCrnyIVSlZg_ZEOk2mr5zDlEpTN2KMq4jFu5p6n4I,2292
27
27
  corelp/modules/prop_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  corelp/modules/prop_LP/prop.py,sha256=lfsENmjg65mpXxt9V9n3Nn__wHgNJA61l8_UXBKn1lc,3999
@@ -37,13 +37,13 @@ corelp/modules/test_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
37
37
  corelp/modules/test_LP/test.py,sha256=KwAeIZWQ7pZX85J50q6qfB4HuJUgREu1ieB_byPqI2g,1361
38
38
  corelp/modules/test_LP/test_test.py,sha256=sXI6G4OBnWXSqrfMy9QdabkYIvcD80EmnNcnQiXxcRI,605
39
39
  corelp/modules/user_inputs_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
- corelp/modules/user_inputs_LP/test_user_inputs.py,sha256=lK8pYm5q5ob9ry3T-gU3J_-KZMKWCCmeuFjjH7DkF_8,927
41
- corelp/modules/user_inputs_LP/user_inputs.py,sha256=2lGkIl2dA_1mcDB8ExvJg4xlcx26viKi878M9ml0MUo,1964
40
+ corelp/modules/user_inputs_LP/test_user_inputs.py,sha256=-6YzBomJxIZSfnfbJPvnfgon3K5RTC3WQKNT4enpVH0,947
41
+ corelp/modules/user_inputs_LP/user_inputs.py,sha256=5VHik_6hY0rhJDWDYn5kTxFkprG1JYPMAUGNPSb4lK4,1779
42
42
  corelp/modules.json,sha256=ZQ8BMU8X2u71wfVj_AufwOoJUPdaxU_AHn7Ohbkp-Pc,3122
43
43
  corelp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
44
  corelp/pythonLP.png:Zone.Identifier,sha256=uVLSTPcBvE56fSHhroXGEYJOgFeaiYNsDLSbGTRGzP4,25
45
45
  corelp/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
46
  corelp/scripts.json,sha256=RBNvo1WzZ4oRRq0W9-hknpT7T8If536DEMBg9hyq_4o,2
47
- corelp-1.0.32.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
48
- corelp-1.0.32.dist-info/METADATA,sha256=6xDMRxnoUSOZa3Y3zhwaKC6yC8Ki9SJHUGCr77IlOJY,1747
49
- corelp-1.0.32.dist-info/RECORD,,
47
+ corelp-1.0.34.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
48
+ corelp-1.0.34.dist-info/METADATA,sha256=4a4JVrRulRRApDoRKaQUB5NoneBNkgOuMpyCltkSMek,1698
49
+ corelp-1.0.34.dist-info/RECORD,,