corelp 1.0.28__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.
Files changed (48) hide show
  1. corelp/__init__.py +29 -0
  2. corelp/icon_pythonLP.ico +0 -0
  3. corelp/modules/Path_LP/Path.py +92 -0
  4. corelp/modules/Path_LP/__init__.py +0 -0
  5. corelp/modules/Path_LP/test_Path.py +37 -0
  6. corelp/modules/Section_LP/Section.py +176 -0
  7. corelp/modules/Section_LP/__init__.py +0 -0
  8. corelp/modules/Section_LP/test_Section.py +43 -0
  9. corelp/modules/__init__.py +0 -0
  10. corelp/modules/debug_LP/__init__.py +0 -0
  11. corelp/modules/debug_LP/debug.py +66 -0
  12. corelp/modules/debug_LP/test_debug.py +34 -0
  13. corelp/modules/folder_LP/__init__.py +0 -0
  14. corelp/modules/folder_LP/folder.py +96 -0
  15. corelp/modules/folder_LP/test_folder.py +43 -0
  16. corelp/modules/getmodule_LP/__init__.py +0 -0
  17. corelp/modules/getmodule_LP/getmodule.py +101 -0
  18. corelp/modules/kwargsself_LP/__init__.py +0 -0
  19. corelp/modules/kwargsself_LP/kwargsself.py +80 -0
  20. corelp/modules/kwargsself_LP/test_kwargsself.py +59 -0
  21. corelp/modules/main_LP/__init__.py +0 -0
  22. corelp/modules/main_LP/main.py +237 -0
  23. corelp/modules/main_LP/test_main.py +74 -0
  24. corelp/modules/print_LP/__init__.py +0 -0
  25. corelp/modules/print_LP/print.py +317 -0
  26. corelp/modules/print_LP/test_print.py +108 -0
  27. corelp/modules/prop_LP/__init__.py +0 -0
  28. corelp/modules/prop_LP/prop.py +134 -0
  29. corelp/modules/prop_LP/test_prop.py +104 -0
  30. corelp/modules/rfrom_LP/__init__.py +0 -0
  31. corelp/modules/rfrom_LP/rfrom.py +72 -0
  32. corelp/modules/rfrom_LP/test_rfrom.py +37 -0
  33. corelp/modules/selfkwargs_LP/__init__.py +0 -0
  34. corelp/modules/selfkwargs_LP/selfkwargs.py +51 -0
  35. corelp/modules/selfkwargs_LP/test_selfkwargs.py +41 -0
  36. corelp/modules/test_LP/__init__.py +0 -0
  37. corelp/modules/test_LP/test.py +61 -0
  38. corelp/modules/test_LP/test_test.py +33 -0
  39. corelp/modules/user_inputs_LP/__init__.py +0 -0
  40. corelp/modules/user_inputs_LP/test_user_inputs.py +45 -0
  41. corelp/modules/user_inputs_LP/user_inputs.py +81 -0
  42. corelp/modules.json +80 -0
  43. corelp/py.typed +0 -0
  44. corelp/scripts/__init__.py +0 -0
  45. corelp/scripts.json +1 -0
  46. corelp-1.0.28.dist-info/METADATA +41 -0
  47. corelp-1.0.28.dist-info/RECORD +48 -0
  48. corelp-1.0.28.dist-info/WHEEL +4 -0
corelp/__init__.py ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-08-25
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : coreLP
7
+
8
+ """
9
+ A library that gathers core functions for python programming.
10
+ """
11
+
12
+
13
+
14
+ from pathlib import Path as PathlibPath
15
+
16
+ # %% Lazy imports
17
+ if __name__ == "__main__":
18
+ from modules.getmodule_LP.getmodule import getmodule # type: ignore
19
+ else :
20
+ from .modules.getmodule_LP.getmodule import getmodule
21
+ __getattr__, __all__ = getmodule(__file__)
22
+ icon = PathlibPath(__file__).parent / "icon_pythonLP.ico"
23
+
24
+
25
+
26
+ # %% Test function run
27
+ if __name__ == "__main__":
28
+ from corelp import test
29
+ test(__file__)
Binary file
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-09-02
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : coreLP
7
+ # Module : Path
8
+
9
+ """
10
+ This function is a wrapper around the pathlib.Path and returns a compatible Path with a windows path copied inside Linux (for WSL)
11
+ """
12
+
13
+
14
+
15
+ # %% Libraries
16
+ from pathlib import Path as PathlibPath
17
+ import os
18
+
19
+
20
+
21
+ # %% Detect if running inside WSL
22
+ def _is_wsl() -> bool:
23
+ """True if WSL."""
24
+ if os.name != "posix":
25
+ return False
26
+ try:
27
+ with open("/proc/version", "r") as f:
28
+ return "microsoft" in f.read().lower()
29
+ except FileNotFoundError:
30
+ return False
31
+
32
+
33
+ IS_WSL = _is_wsl()
34
+
35
+
36
+ # %% Function
37
+ def Path(path, *args, **kwargs) :
38
+ '''
39
+ This function is a wrapper around the pathlib.Path and returns a compatible Path with a windows path copied inside Linux (for WSL)
40
+
41
+ Parameters
42
+ ----------
43
+ path : str of pathlib.Path
44
+ path string to convert to Path.
45
+
46
+ Returns
47
+ -------
48
+ path : pathlib.Path
49
+ compatible Path.
50
+
51
+ Examples
52
+ --------
53
+ >>> Path("C:\\Users\\Name\\Documents")
54
+ PosixPath('/mnt/c/Users/Name/Documents') # under WSL
55
+ >>> Path("/home/user/project")
56
+ PosixPath('/home/user/project') # under Linux
57
+ >>> Path("C:\\Users\\Name\\Documents")
58
+ WindowsPath('C:/Users/Name/Documents') # under Windows
59
+ '''
60
+
61
+ # Windows case → no conversion
62
+ if os.name == "nt":
63
+ return PathlibPath(path, *args, **kwargs)
64
+
65
+ # Conversion in string
66
+ pathstring = str(path).replace("\\", "/")
67
+
68
+ # If not in WSL → no touching
69
+ if not IS_WSL:
70
+ return PathlibPath(pathstring, *args, **kwargs)
71
+
72
+ # Detection of UNC Windows paths (\\server\share)
73
+ if pathstring.startswith("//"):
74
+ unc_path = pathstring.lstrip("/")
75
+ pathstring = f"/mnt/unc/{unc_path}"
76
+ return PathlibPath(pathstring, *args, **kwargs)
77
+
78
+ # Conversion of paths Windows with disk (C:/Users/...)
79
+ if ":" in pathstring:
80
+ drive, rest = pathstring.split(":", 1)
81
+ pathstring = f"/mnt/{drive.lower()}{rest}"
82
+ return PathlibPath(pathstring, *args, **kwargs)
83
+
84
+ # Else → already a native/relative Linux path
85
+ return PathlibPath(pathstring, *args, **kwargs)
86
+
87
+
88
+
89
+ # %% Test function run
90
+ if __name__ == "__main__":
91
+ from corelp import test
92
+ test(__file__)
File without changes
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-09-02
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : coreLP
7
+ # Module : Path
8
+
9
+ """
10
+ This file allows to test Path
11
+
12
+ Path : This function is a wrapper around the pathlib.Path and returns a compatible Path with a windows path copied inside Linux (for WSL)
13
+ """
14
+
15
+
16
+
17
+ # %% Libraries
18
+ from corelp import print, debug
19
+ import pytest
20
+ from corelp import Path
21
+ debug_folder = debug(__file__)
22
+
23
+
24
+
25
+ # %% Function test
26
+ def test_function() :
27
+ '''
28
+ Test Path function
29
+ '''
30
+ print('Hello world!')
31
+
32
+
33
+
34
+ # %% Test function run
35
+ if __name__ == "__main__":
36
+ from corelp import test
37
+ test(__file__)
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-08-28
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : coreLP
7
+ # Module : Section
8
+
9
+ """
10
+ This class defines decorator instances allowing to create section functions.
11
+ """
12
+
13
+
14
+
15
+ # %% Libraries
16
+ from corelp import print, folder, selfkwargs, kwargsself
17
+ from dataclasses import dataclass, field
18
+ import pickle
19
+ import joblib
20
+ from pathlib import Path
21
+ from functools import wraps
22
+ import hashlib
23
+ import inspect
24
+ import os
25
+
26
+
27
+
28
+ # %% Class
29
+ @dataclass(slots=True, kw_only=True)
30
+ class Section() :
31
+ '''
32
+ This class defines decorator instances allowing to create section functions.
33
+ Cache results into a folder, if another call occurs, can load-back the precalculated data.
34
+
35
+ Parameters
36
+ ----------
37
+ path : str or Path
38
+ path where to save section folder results.
39
+ new : bool
40
+ True to ignore pre-calculated data and crush them.
41
+ num : int
42
+ Index of section, after one call, adds 1 for next call.
43
+ parent_path : str or Path
44
+ Path to the parent folder if bulk processing.
45
+
46
+ Examples
47
+ --------
48
+ >>> from corelp import Section
49
+ ...
50
+ >>> section = Section(path=export_path)
51
+ ...
52
+ >>> @section()
53
+ ... def add(a, b=0) :
54
+ ... testfunc.print('Hello World')
55
+ ... return a + b
56
+ ...
57
+ >>> testfunc.print('3+0=', add(3)) # First call calculates and save result
58
+ >>> testfunc.print('3+0=', add(3, 0)) # Second call loads back precalculated results
59
+ >>> testfunc.print('1+3=', add(1, 3)) # New call with other parameters : crushed previous results with new ones
60
+ >>> testfunc.print('1+3=', add(1, b=3)) # Second call with these parameters : loads precalculated results
61
+ ...
62
+ >>> @section(cache=False) # Creates an index of 2, does no caching
63
+ ... def sub(a, b=0) :
64
+ ... return a - b
65
+ ...
66
+ >>> @section(num=10) # Creates an index of 10
67
+ ... def mul(a, b=0) :
68
+ ... return a * b
69
+ ...
70
+ >>> @section(new=True) # Creates an index of 11, always creates new cache
71
+ ... def div(a, b) :
72
+ ... return a / b
73
+ '''
74
+
75
+ # Attributes
76
+ path : Path | str = None
77
+ new :bool = False
78
+ num :int = 0
79
+ parent_path : Path | str = None
80
+
81
+ # Init
82
+ def __post_init__(self) :
83
+ if self.path is not None :
84
+ self.path = Path(self.path)
85
+ if self.parent_path is not None :
86
+ self.parent_path = Path(self.parent_path)
87
+
88
+ # Decorator
89
+ def __call__(self, *, new=None, num=None, symlink=None, cache=True):
90
+ if new is None :
91
+ new = self.new
92
+ if num is None :
93
+ num = self.num
94
+ self.num = num+1
95
+
96
+ def decorator(func) :
97
+ name = func.__name__
98
+
99
+ @wraps(func)
100
+ def wrapper(*args, **kwargs):
101
+ wrapper.path = self.path / f"{num:03}_{name}"
102
+ print(f'\n#### {num}. {name.replace("_"," ")} section\n')
103
+
104
+ # Creating hash
105
+ if cache :
106
+ print('**Call hash:**')
107
+ bound = inspect.signature(func).bind(*args, **kwargs)
108
+ bound.apply_defaults()
109
+ serialized = pickle.dumps(bound.arguments)
110
+ args_hash = hashlib.md5(serialized).hexdigest()
111
+ result_file = wrapper.path / f'{args_hash}.pkl'
112
+ print(f'*{args_hash}*\n')
113
+
114
+ # Checking already calculated exists
115
+ if result_file.exists() and not new :
116
+ print('**Loading from *precalculated* results...**')
117
+ with open(result_file, 'rb') as f:
118
+ result = joblib.load(f)
119
+ print('...loaded\n')
120
+ return result
121
+
122
+ # Calculations
123
+ folder(wrapper.path, warning=False)
124
+ print('**Calculating results:**')
125
+ print_status = kwargsself(print)
126
+ print.file = wrapper.path / f'{name}_log.md'
127
+ result = func(*args, **kwargs)
128
+ selfkwargs(print, print_status)
129
+ print('...calculated\n')
130
+
131
+ # Caching
132
+ if cache :
133
+ print('**Saving results:**')
134
+ with open(result_file, 'wb') as f:
135
+ joblib.dump(result, f)
136
+ print('...saved\n')
137
+
138
+ # Create symlink
139
+ if symlink is not None :
140
+ print('**Creating symlinks:**')
141
+ for link in symlink :
142
+ print(f"- {link}")
143
+ link_path = Path(link)
144
+ link_folder = self.parent_path / link_path.stem
145
+ new_stem = str(self.subfolder.as_posix()).replace('/', '--')
146
+ if not link_folder.exists() :
147
+ folder(link_folder, warning=False)
148
+ link_from = wrapper.path / link_path
149
+ link_to = link_folder / f"{new_stem}{link_path.suffix}"
150
+ if link_to.exists() or link_to.is_symlink():
151
+ link_to.unlink()
152
+ if os.name == "nt":
153
+ try :
154
+ link_to.symlink_to(link_from, link_from.is_dir())
155
+ except OSError :
156
+ print("Windows does not allow to create symlink, aborting. Consider using Windows in Developper mode.")
157
+ break
158
+ else:
159
+ link_to.symlink_to(link_from, link_from.is_dir())
160
+ print('...created\n')
161
+
162
+
163
+ return result
164
+ return wrapper
165
+ return decorator
166
+
167
+ @property
168
+ def subfolder(self) :
169
+ return self.path.relative_to(self.parent_path)
170
+
171
+
172
+
173
+ # %% Test function run
174
+ if __name__ == "__main__":
175
+ from corelp import test
176
+ test(__file__)
File without changes
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-08-28
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : coreLP
7
+ # Module : Section
8
+
9
+ """
10
+ This file allows to test Section
11
+
12
+ Section : This class defines decorator instances allowing to create section functions.
13
+ """
14
+
15
+
16
+
17
+ # %% Libraries
18
+ from corelp import debug, Section
19
+ debug_folder = debug(__file__)
20
+
21
+
22
+
23
+ # %% Function test
24
+ def test_function() :
25
+ '''
26
+ Test Section function
27
+ '''
28
+ section = Section(path=debug_folder)
29
+
30
+ @section()
31
+ def add(a, b=0) :
32
+ return a+b
33
+ assert add(3) == 3
34
+ assert add(3, 0) == 3
35
+ assert add(1, 3) == 4
36
+ assert add(1, b=3) == 4
37
+
38
+
39
+
40
+ # %% Test function run
41
+ if __name__ == "__main__":
42
+ from corelp import test
43
+ test(__file__)
File without changes
File without changes
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-08-25
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : coreLP
7
+ # Module : debug
8
+
9
+ """
10
+ This function will give and create the debug folder for a given python file.
11
+ """
12
+
13
+
14
+
15
+ # %% Libraries
16
+ from corelp import folder
17
+ from pathlib import Path
18
+ import os
19
+
20
+
21
+
22
+
23
+ # %% Function
24
+ def debug(file, new=True, *, project_index=2) :
25
+ '''
26
+ This function will give and create the debug folder for a given python file.
27
+
28
+ Parameters
29
+ ----------
30
+ file : str
31
+ __file__ string in the current python file to be debugged.
32
+ new : bool
33
+ True to create new folder at each call.
34
+ project_index : int
35
+ Index of parent of file containing project name, by default 2 : projectlp / modules / module_LP / file.py.
36
+
37
+ Returns
38
+ -------
39
+ debug_folder : Path
40
+ Path to the debug folder.
41
+
42
+ Examples
43
+ --------
44
+ >>> from corelp import debug
45
+ ...
46
+ >>> debug_folder = debug(__file__)
47
+ '''
48
+
49
+ # Get paths
50
+ file = Path(file)
51
+ module_name = file.stem.replace("test_", "")
52
+ lib_name = file.parents[project_index].name # lib_name / modules / module_LP / file.py
53
+ debug_parent = Path.home() / 'pythonLP/.debug'
54
+ debug_folder = debug_parent / f'{lib_name}_{module_name}'
55
+
56
+ # Create folders
57
+ if not debug_parent.exists() : # Create parent folder if does not exist yet
58
+ os.makedirs(debug_parent)
59
+ return folder(debug_folder, False, new=new)
60
+
61
+
62
+
63
+ # %% Test function run
64
+ if __name__ == "__main__":
65
+ from corelp import test
66
+ test(__file__)
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-08-25
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : coreLP
7
+ # Module : debug
8
+
9
+ """
10
+ This file allows to test debug
11
+
12
+ debug : This function will give and create the debug folder for a given python file.
13
+ """
14
+
15
+
16
+
17
+ # %% Libraries
18
+ from corelp import debug
19
+ from pathlib import Path
20
+ debug_folder = debug(__file__)
21
+
22
+
23
+
24
+ # %% Test folder exists
25
+ def test_path() :
26
+ assert debug_folder.exists(), "Debug folder should exist"
27
+ assert debug_folder == (Path.home() / 'pythonLP/.debug/corelp_debug')
28
+
29
+
30
+
31
+ # %% Test function run
32
+ if __name__ == "__main__":
33
+ from corelp import test
34
+ test(__file__)
File without changes
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-08-25
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : coreLP
7
+ # Module : folder
8
+
9
+ """
10
+ This function creates a new folder, while crushing previous instances if already exists.
11
+ """
12
+
13
+
14
+
15
+ # %% Libraries
16
+ from pathlib import Path
17
+ import shutil
18
+ import os
19
+
20
+
21
+
22
+ # %% Function
23
+ def folder(path, /, warning=True, *, new=True) :
24
+ '''
25
+ This function creates a new folder, while crushing previous instances if already exists.
26
+
27
+ Parameters
28
+ ----------
29
+ path : str or Path
30
+ Full path to folder to create.
31
+ warning : bool
32
+ True to print a warning if a folder already exist.
33
+ new : bool
34
+ True to crush folder if already exists.
35
+
36
+ Returns
37
+ -------
38
+ folder_path : Path
39
+ Path object to created folder.
40
+
41
+ Raises
42
+ ------
43
+ SyntaxError
44
+ If user answers *no* to crush existing folder when warning asked.
45
+
46
+ Examples
47
+ --------
48
+ >>> from corelp import folder
49
+ ...
50
+ >>> folder_path = folder(path) # Creates folder
51
+ >>> folder_path = folder(path) # Launch warning before crushing
52
+ >>> folder_path = folder(path, warning=False) # Crushes without warning
53
+ >>> folder_path = folder(path, new=False) # Does not crush old folder
54
+ '''
55
+
56
+ path = Path(path)
57
+
58
+ # Folder already exists
59
+ if path.exists() :
60
+ if not new : # Nothing to do
61
+ return path
62
+
63
+ # Decide if crushing
64
+ if warning :
65
+ print('\n**********************')
66
+ print("FOLDER WILL BE DELETED")
67
+ print(str(path))
68
+ erase = input('Continue? [y]/n >>> ')
69
+ crush = str(erase).lower() in ["yes", "y", "true", "1"]
70
+ else :
71
+ crush = True
72
+
73
+ # Error
74
+ if not crush :
75
+ raise SyntaxError(f"Folder {path} already exists and cannot be crushed")
76
+
77
+ # Removes folder
78
+ def remove_protection(func, directory, info):
79
+ if os.name == "nt":
80
+ os.system(f'attrib -h -s -r "{directory}"')
81
+ if os.path.isdir(directory):
82
+ shutil.rmtree(directory, onexc=remove_protection)
83
+ else:
84
+ os.remove(directory)
85
+ shutil.rmtree(path, onexc=remove_protection)
86
+
87
+ # End
88
+ os.makedirs(path)
89
+ return path
90
+
91
+
92
+
93
+ # %% Test function run
94
+ if __name__ == "__main__":
95
+ from corelp import test
96
+ test(__file__)
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-08-25
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : coreLP
7
+ # Module : folder
8
+
9
+ """
10
+ This file allows to test folder
11
+
12
+ folder : This function creates a new folder, while crushing previous instances if already exists.
13
+ """
14
+
15
+
16
+
17
+ # %% Libraries
18
+ from corelp import debug, folder
19
+ import pytest
20
+ debug_folder = debug(__file__)
21
+
22
+
23
+
24
+ # %% Test function
25
+ def test_function() :
26
+ path = debug_folder / 'test_folder'
27
+ subpath = path / "test_subfolder"
28
+ folder(subpath, False)
29
+ assert path.exists()
30
+ assert subpath.exists()
31
+ folder(path, False, new=False)
32
+ assert path.exists()
33
+ assert subpath.exists()
34
+ folder(path, False, new=True)
35
+ assert path.exists()
36
+ assert not subpath.exists()
37
+
38
+
39
+
40
+ # %% Test function run
41
+ if __name__ == "__main__":
42
+ from corelp import test
43
+ test(__file__)
File without changes