scripthelper 25.1__tar.gz → 26.1__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.
- {scripthelper-25.1 → scripthelper-26.1}/PKG-INFO +270 -272
- scripthelper-26.1/pyproject.toml +63 -0
- scripthelper-25.1/pyproject.toml → scripthelper-26.1/pyproject.toml.orig +7 -9
- {scripthelper-25.1 → scripthelper-26.1}/src/scripthelper/__init__.py +3 -3
- scripthelper-25.1/.gitignore +0 -23
- scripthelper-25.1/CHANGELOG.md +0 -105
- scripthelper-25.1/LICENSE +0 -21
- scripthelper-25.1/README.md +0 -91
- scripthelper-25.1/compile-readme.py +0 -19
- scripthelper-25.1/example1.py +0 -12
- scripthelper-25.1/example10.py +0 -7
- scripthelper-25.1/example2.py +0 -11
- scripthelper-25.1/example2b.py +0 -17
- scripthelper-25.1/example3.py +0 -16
- scripthelper-25.1/example4.py +0 -6
- scripthelper-25.1/example4module.py +0 -9
- scripthelper-25.1/example5.py +0 -13
- scripthelper-25.1/example6.py +0 -10
- scripthelper-25.1/example7.py +0 -22
- scripthelper-25.1/example8.py +0 -8
- scripthelper-25.1/example9.py +0 -14
- scripthelper-25.1/justfile +0 -51
- scripthelper-25.1/mypy.ini +0 -3
- scripthelper-25.1/test_examples.py +0 -298
- scripthelper-25.1/venv/.gitignore +0 -1
- scripthelper-25.1/venv/.tox-info.json +0 -6
- scripthelper-25.1/venv/CACHEDIR.TAG +0 -1
- scripthelper-25.1/venv/Scripts/python.exe +0 -0
- scripthelper-25.1/venv/Scripts/pythonw.exe +0 -0
- {scripthelper-25.1 → scripthelper-26.1}/README.compiled.md +0 -0
- {scripthelper-25.1 → scripthelper-26.1}/src/scripthelper/py.typed +0 -0
|
@@ -1,290 +1,288 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scripthelper
|
|
3
|
-
Version:
|
|
3
|
+
Version: 26.1
|
|
4
4
|
Summary: Helper module for creating simple Python scripts
|
|
5
|
-
|
|
6
|
-
Project-URL: Changelog, https://github.com/presidento/scripthelper/blob/main/CHANGELOG.md
|
|
5
|
+
Author: Máté Farkas
|
|
7
6
|
Author-email: Máté Farkas <fm@farkas-mate.hu>
|
|
8
|
-
License: MIT
|
|
9
|
-
License-File: LICENSE
|
|
7
|
+
License-Expression: MIT
|
|
10
8
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
9
|
Classifier: Intended Audience :: Developers
|
|
12
10
|
Classifier: Intended Audience :: System Administrators
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
11
|
Classifier: Operating System :: OS Independent
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
17
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
19
14
|
Classifier: Programming Language :: Python :: 3.13
|
|
20
15
|
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
21
17
|
Classifier: Topic :: Utilities
|
|
22
18
|
Classifier: Typing :: Typed
|
|
23
|
-
Requires-
|
|
19
|
+
Requires-Dist: tqdm>=4.31.1
|
|
24
20
|
Requires-Dist: coloredlogs>=10.0
|
|
25
|
-
Requires-Dist: persistedstate>=23.6
|
|
26
|
-
Requires-Dist: prettyprinter>=0.18.0
|
|
27
21
|
Requires-Dist: stackprinter>=0.2.10
|
|
28
|
-
Requires-Dist:
|
|
22
|
+
Requires-Dist: prettyprinter>=0.18.0
|
|
23
|
+
Requires-Dist: persistedstate>=23.6
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Project-URL: Homepage, https://github.com/presidento/scripthelper
|
|
26
|
+
Project-URL: Changelog, https://github.com/presidento/scripthelper/blob/main/CHANGELOG.md
|
|
29
27
|
Description-Content-Type: text/markdown
|
|
30
28
|
|
|
31
|
-
# scripthelper
|
|
32
|
-
|
|
33
|
-
Helper module for simple command line Python scripts.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
## Basic usage
|
|
37
|
-
|
|
38
|
-
[example1.py](https://github.com/presidento/scripthelper/blob/master/example1.py):
|
|
39
|
-
|
|
40
|
-
```python
|
|
41
|
-
#!/usr/bin/env python3
|
|
42
|
-
import scripthelper
|
|
43
|
-
|
|
44
|
-
logger = scripthelper.bootstrap()
|
|
45
|
-
|
|
46
|
-
logger.critical("critical message")
|
|
47
|
-
logger.error("error message")
|
|
48
|
-
logger.warning("warning message")
|
|
49
|
-
logger.info("info message")
|
|
50
|
-
logger.verbose("verbose message")
|
|
51
|
-
logger.debug("debug message")
|
|
52
|
-
logger.spam("spam message")
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
It just works. Try `--verbose` and `--quiet` command line options, too.
|
|
56
|
-
It uses colored log messages on a terminal.
|
|
57
|
-
See `--help` for more information.
|
|
58
|
-
|
|
59
|
-
## Adding other command line parameters
|
|
60
|
-
|
|
61
|
-
[example2.py](https://github.com/presidento/scripthelper/blob/master/example2.py):
|
|
62
|
-
|
|
63
|
-
```python
|
|
64
|
-
#!/usr/bin/env python3
|
|
65
|
-
import scripthelper
|
|
66
|
-
|
|
67
|
-
scripthelper.add_argument("-n", "--name", help="Name to greet")
|
|
68
|
-
logger, args = scripthelper.bootstrap_args()
|
|
69
|
-
|
|
70
|
-
if args.name:
|
|
71
|
-
logger.debug("Name was provided")
|
|
72
|
-
logger.info(f"Hello {args.name}")
|
|
73
|
-
else:
|
|
74
|
-
logger.warning("Name was not provided")
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
For bigger scripts it is good idea to have the logger at the very beginning, and encapsulate the argument parsing phase, which is typically in the main function:
|
|
78
|
-
|
|
79
|
-
[example2b.py](https://github.com/presidento/scripthelper/blob/master/example2b.py):
|
|
80
|
-
|
|
81
|
-
```python
|
|
82
|
-
#!/usr/bin/env python3
|
|
83
|
-
import scripthelper
|
|
84
|
-
|
|
85
|
-
logger = scripthelper.getLogger()
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def greet(name):
|
|
89
|
-
logger.info(f"Hello {name}")
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def main():
|
|
93
|
-
scripthelper.add_argument("--name", default="World")
|
|
94
|
-
args = scripthelper.initialize()
|
|
95
|
-
greet(args.name)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
main()
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## Progressbar works with logging, too
|
|
102
|
-
|
|
103
|
-
[example3.py](https://github.com/presidento/scripthelper/blob/master/example3.py):
|
|
104
|
-
|
|
105
|
-
```python
|
|
106
|
-
#!/usr/bin/env python3
|
|
107
|
-
import scripthelper
|
|
108
|
-
import time
|
|
109
|
-
|
|
110
|
-
logger = scripthelper.bootstrap()
|
|
111
|
-
|
|
112
|
-
logger.info("Doing the calculations...")
|
|
113
|
-
for i in scripthelper.progressbar(range(100)):
|
|
114
|
-
if i % 20 == 0:
|
|
115
|
-
logger.verbose(f"Iteration {i}")
|
|
116
|
-
if i % 5 == 0:
|
|
117
|
-
logger.debug(f"Iteration {i}")
|
|
118
|
-
if logger.isEnabledFor(scripthelper.SPAM):
|
|
119
|
-
logger.spam(f"Iteration {i}")
|
|
120
|
-
time.sleep(0.01)
|
|
121
|
-
logger.info("Done")
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
It is automatically disabled on non-tty `stderr` by default.
|
|
125
|
-
|
|
126
|
-
## Extended log levels can be used in modules
|
|
127
|
-
|
|
128
|
-
[example4.py](https://github.com/presidento/scripthelper/blob/master/example4.py):
|
|
129
|
-
|
|
130
|
-
```python
|
|
131
|
-
#!/usr/bin/env python3
|
|
132
|
-
import scripthelper
|
|
133
|
-
import example4module
|
|
134
|
-
|
|
135
|
-
scripthelper.bootstrap()
|
|
136
|
-
example4module.do_the_things()
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
[example4module.py](https://github.com/presidento/scripthelper/blob/master/example4module.py):
|
|
140
|
-
|
|
141
|
-
```python
|
|
142
|
-
#!/usr/bin/env python3
|
|
143
|
-
import scripthelper
|
|
144
|
-
|
|
145
|
-
logger = scripthelper.getLogger(__name__)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
def do_the_things():
|
|
149
|
-
logger.verbose("Calling logger.verbose raises an exception if it does not work.")
|
|
150
|
-
logger.info("Hello from a module.")
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## You can easily preserve logs in files
|
|
154
|
-
|
|
155
|
-
[example5.py](https://github.com/presidento/scripthelper/blob/master/example5.py):
|
|
156
|
-
|
|
157
|
-
```python
|
|
158
|
-
#!/usr/bin/env python3
|
|
159
|
-
import scripthelper
|
|
160
|
-
|
|
161
|
-
logger = scripthelper.bootstrap()
|
|
162
|
-
scripthelper.setup_file_logging()
|
|
163
|
-
|
|
164
|
-
logger.critical("critical message")
|
|
165
|
-
logger.error("error message")
|
|
166
|
-
logger.warning("warning message")
|
|
167
|
-
logger.info("info message")
|
|
168
|
-
logger.verbose("verbose message")
|
|
169
|
-
logger.debug("debug message")
|
|
170
|
-
logger.spam("spam message")
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## It handles exceptions, warnings
|
|
174
|
-
|
|
175
|
-
[example6.py](https://github.com/presidento/scripthelper/blob/master/example6.py):
|
|
176
|
-
|
|
177
|
-
```python
|
|
178
|
-
#!/usr/bin/env python3
|
|
179
|
-
import scripthelper
|
|
180
|
-
|
|
181
|
-
scripthelper.bootstrap()
|
|
182
|
-
|
|
183
|
-
scripthelper.warn("This user warning will be captured.")
|
|
184
|
-
|
|
185
|
-
this_variable = "will be displayed in stack trace"
|
|
186
|
-
as_well_as = "the other variables"
|
|
187
|
-
raise RuntimeError("This exception should be handled.")
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
The local variables will be displayed in stack trace, for example:
|
|
191
|
-
|
|
192
|
-
```
|
|
193
|
-
WARNING example6.py:6: UserWarning: This user warning will be captured.
|
|
194
|
-
scripthelper.warn("This user warning will be captured.")
|
|
195
|
-
|
|
196
|
-
CRITICAL Uncaught RuntimeError: This exception should be handled.
|
|
197
|
-
File "example6.py", line 10, in <module>
|
|
198
|
-
6 scripthelper.warn("This user warning will be captured.")
|
|
199
|
-
7
|
|
200
|
-
8 this_variable = "will be displayed in stack trace"
|
|
201
|
-
9 as_well_as = "the other variables"
|
|
202
|
-
--> 10 raise RuntimeError("This exception should be handled.")
|
|
203
|
-
..................................................
|
|
204
|
-
this_variable = 'will be displayed in stack trace'
|
|
205
|
-
as_well_as = 'the other variables'
|
|
206
|
-
..................................................
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
## Has built-in colored pretty printer
|
|
210
|
-
|
|
211
|
-
[example7.py](https://github.com/presidento/scripthelper/blob/master/example7.py):
|
|
212
|
-
|
|
213
|
-
```python
|
|
214
|
-
#!/usr/bin/env python3
|
|
215
|
-
import scripthelper
|
|
216
|
-
from dataclasses import dataclass
|
|
217
|
-
|
|
218
|
-
scripthelper.bootstrap()
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
@dataclass
|
|
222
|
-
class Item:
|
|
223
|
-
name: str
|
|
224
|
-
value: int
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
something = {
|
|
228
|
-
"string": "value1",
|
|
229
|
-
"bool": True,
|
|
230
|
-
"none": None,
|
|
231
|
-
"integer": 1234,
|
|
232
|
-
"item": Item("name", 999),
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
scripthelper.pp(something)
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
## Has built-in persisted state handler
|
|
239
|
-
|
|
240
|
-
The state is persisted immediately in the background in YAML. Mutable objects (`list`, `dict`) also can be used.
|
|
241
|
-
|
|
242
|
-
[example9.py](https://github.com/presidento/scripthelper/blob/master/example9.py):
|
|
243
|
-
|
|
244
|
-
```python
|
|
245
|
-
#!/usr/bin/env python3
|
|
246
|
-
import scripthelper
|
|
247
|
-
|
|
248
|
-
logger = scripthelper.bootstrap()
|
|
249
|
-
state = scripthelper.PersistedState(processed_id=0, to_remember=[])
|
|
250
|
-
|
|
251
|
-
state.processed_id += 1
|
|
252
|
-
state.to_remember.append(f"Element {state.processed_id}")
|
|
253
|
-
while len(state.to_remember) > 2:
|
|
254
|
-
state.to_remember.pop(0)
|
|
255
|
-
|
|
256
|
-
logger.info(f"Processing item #{state.processed_id}")
|
|
257
|
-
for item in state.to_remember:
|
|
258
|
-
logger.info(f"- {item}")
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
```
|
|
262
|
-
$ python3 example9.py
|
|
263
|
-
INFO example9 Processing item #1
|
|
264
|
-
INFO example9 - Element 1
|
|
265
|
-
|
|
266
|
-
$ python3 example9.py
|
|
267
|
-
INFO example9 Processing item #2
|
|
268
|
-
INFO example9 - Element 1
|
|
269
|
-
INFO example9 - Element 2
|
|
270
|
-
|
|
271
|
-
$ python3 example9.py
|
|
272
|
-
INFO example9 Processing item #3
|
|
273
|
-
INFO example9 - Element 2
|
|
274
|
-
INFO example9 - Element 3
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
## Helps issuing a warning only once
|
|
278
|
-
|
|
279
|
-
[example10.py](https://github.com/presidento/scripthelper/blob/master/example10.py):
|
|
280
|
-
|
|
281
|
-
```python
|
|
282
|
-
#!/usr/bin/env python3
|
|
283
|
-
import scripthelper
|
|
284
|
-
|
|
285
|
-
scripthelper.bootstrap()
|
|
286
|
-
|
|
287
|
-
for _ in range(10):
|
|
288
|
-
scripthelper.warning_once("Item #12 has some errors")
|
|
289
|
-
```
|
|
290
|
-
|
|
29
|
+
# scripthelper
|
|
30
|
+
|
|
31
|
+
Helper module for simple command line Python scripts.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## Basic usage
|
|
35
|
+
|
|
36
|
+
[example1.py](https://github.com/presidento/scripthelper/blob/master/example1.py):
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
#!/usr/bin/env python3
|
|
40
|
+
import scripthelper
|
|
41
|
+
|
|
42
|
+
logger = scripthelper.bootstrap()
|
|
43
|
+
|
|
44
|
+
logger.critical("critical message")
|
|
45
|
+
logger.error("error message")
|
|
46
|
+
logger.warning("warning message")
|
|
47
|
+
logger.info("info message")
|
|
48
|
+
logger.verbose("verbose message")
|
|
49
|
+
logger.debug("debug message")
|
|
50
|
+
logger.spam("spam message")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
It just works. Try `--verbose` and `--quiet` command line options, too.
|
|
54
|
+
It uses colored log messages on a terminal.
|
|
55
|
+
See `--help` for more information.
|
|
56
|
+
|
|
57
|
+
## Adding other command line parameters
|
|
58
|
+
|
|
59
|
+
[example2.py](https://github.com/presidento/scripthelper/blob/master/example2.py):
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
#!/usr/bin/env python3
|
|
63
|
+
import scripthelper
|
|
64
|
+
|
|
65
|
+
scripthelper.add_argument("-n", "--name", help="Name to greet")
|
|
66
|
+
logger, args = scripthelper.bootstrap_args()
|
|
67
|
+
|
|
68
|
+
if args.name:
|
|
69
|
+
logger.debug("Name was provided")
|
|
70
|
+
logger.info(f"Hello {args.name}")
|
|
71
|
+
else:
|
|
72
|
+
logger.warning("Name was not provided")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
For bigger scripts it is good idea to have the logger at the very beginning, and encapsulate the argument parsing phase, which is typically in the main function:
|
|
76
|
+
|
|
77
|
+
[example2b.py](https://github.com/presidento/scripthelper/blob/master/example2b.py):
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
#!/usr/bin/env python3
|
|
81
|
+
import scripthelper
|
|
82
|
+
|
|
83
|
+
logger = scripthelper.getLogger()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def greet(name):
|
|
87
|
+
logger.info(f"Hello {name}")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def main():
|
|
91
|
+
scripthelper.add_argument("--name", default="World")
|
|
92
|
+
args = scripthelper.initialize()
|
|
93
|
+
greet(args.name)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
main()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Progressbar works with logging, too
|
|
100
|
+
|
|
101
|
+
[example3.py](https://github.com/presidento/scripthelper/blob/master/example3.py):
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
#!/usr/bin/env python3
|
|
105
|
+
import scripthelper
|
|
106
|
+
import time
|
|
107
|
+
|
|
108
|
+
logger = scripthelper.bootstrap()
|
|
109
|
+
|
|
110
|
+
logger.info("Doing the calculations...")
|
|
111
|
+
for i in scripthelper.progressbar(range(100)):
|
|
112
|
+
if i % 20 == 0:
|
|
113
|
+
logger.verbose(f"Iteration {i}")
|
|
114
|
+
if i % 5 == 0:
|
|
115
|
+
logger.debug(f"Iteration {i}")
|
|
116
|
+
if logger.isEnabledFor(scripthelper.SPAM):
|
|
117
|
+
logger.spam(f"Iteration {i}")
|
|
118
|
+
time.sleep(0.01)
|
|
119
|
+
logger.info("Done")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
It is automatically disabled on non-tty `stderr` by default.
|
|
123
|
+
|
|
124
|
+
## Extended log levels can be used in modules
|
|
125
|
+
|
|
126
|
+
[example4.py](https://github.com/presidento/scripthelper/blob/master/example4.py):
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
#!/usr/bin/env python3
|
|
130
|
+
import scripthelper
|
|
131
|
+
import example4module
|
|
132
|
+
|
|
133
|
+
scripthelper.bootstrap()
|
|
134
|
+
example4module.do_the_things()
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
[example4module.py](https://github.com/presidento/scripthelper/blob/master/example4module.py):
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
#!/usr/bin/env python3
|
|
141
|
+
import scripthelper
|
|
142
|
+
|
|
143
|
+
logger = scripthelper.getLogger(__name__)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def do_the_things():
|
|
147
|
+
logger.verbose("Calling logger.verbose raises an exception if it does not work.")
|
|
148
|
+
logger.info("Hello from a module.")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## You can easily preserve logs in files
|
|
152
|
+
|
|
153
|
+
[example5.py](https://github.com/presidento/scripthelper/blob/master/example5.py):
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
#!/usr/bin/env python3
|
|
157
|
+
import scripthelper
|
|
158
|
+
|
|
159
|
+
logger = scripthelper.bootstrap()
|
|
160
|
+
scripthelper.setup_file_logging()
|
|
161
|
+
|
|
162
|
+
logger.critical("critical message")
|
|
163
|
+
logger.error("error message")
|
|
164
|
+
logger.warning("warning message")
|
|
165
|
+
logger.info("info message")
|
|
166
|
+
logger.verbose("verbose message")
|
|
167
|
+
logger.debug("debug message")
|
|
168
|
+
logger.spam("spam message")
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## It handles exceptions, warnings
|
|
172
|
+
|
|
173
|
+
[example6.py](https://github.com/presidento/scripthelper/blob/master/example6.py):
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
#!/usr/bin/env python3
|
|
177
|
+
import scripthelper
|
|
178
|
+
|
|
179
|
+
scripthelper.bootstrap()
|
|
180
|
+
|
|
181
|
+
scripthelper.warn("This user warning will be captured.")
|
|
182
|
+
|
|
183
|
+
this_variable = "will be displayed in stack trace"
|
|
184
|
+
as_well_as = "the other variables"
|
|
185
|
+
raise RuntimeError("This exception should be handled.")
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
The local variables will be displayed in stack trace, for example:
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
WARNING example6.py:6: UserWarning: This user warning will be captured.
|
|
192
|
+
scripthelper.warn("This user warning will be captured.")
|
|
193
|
+
|
|
194
|
+
CRITICAL Uncaught RuntimeError: This exception should be handled.
|
|
195
|
+
File "example6.py", line 10, in <module>
|
|
196
|
+
6 scripthelper.warn("This user warning will be captured.")
|
|
197
|
+
7
|
|
198
|
+
8 this_variable = "will be displayed in stack trace"
|
|
199
|
+
9 as_well_as = "the other variables"
|
|
200
|
+
--> 10 raise RuntimeError("This exception should be handled.")
|
|
201
|
+
..................................................
|
|
202
|
+
this_variable = 'will be displayed in stack trace'
|
|
203
|
+
as_well_as = 'the other variables'
|
|
204
|
+
..................................................
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Has built-in colored pretty printer
|
|
208
|
+
|
|
209
|
+
[example7.py](https://github.com/presidento/scripthelper/blob/master/example7.py):
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
#!/usr/bin/env python3
|
|
213
|
+
import scripthelper
|
|
214
|
+
from dataclasses import dataclass
|
|
215
|
+
|
|
216
|
+
scripthelper.bootstrap()
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
@dataclass
|
|
220
|
+
class Item:
|
|
221
|
+
name: str
|
|
222
|
+
value: int
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
something = {
|
|
226
|
+
"string": "value1",
|
|
227
|
+
"bool": True,
|
|
228
|
+
"none": None,
|
|
229
|
+
"integer": 1234,
|
|
230
|
+
"item": Item("name", 999),
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
scripthelper.pp(something)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Has built-in persisted state handler
|
|
237
|
+
|
|
238
|
+
The state is persisted immediately in the background in YAML. Mutable objects (`list`, `dict`) also can be used.
|
|
239
|
+
|
|
240
|
+
[example9.py](https://github.com/presidento/scripthelper/blob/master/example9.py):
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
#!/usr/bin/env python3
|
|
244
|
+
import scripthelper
|
|
245
|
+
|
|
246
|
+
logger = scripthelper.bootstrap()
|
|
247
|
+
state = scripthelper.PersistedState(processed_id=0, to_remember=[])
|
|
248
|
+
|
|
249
|
+
state.processed_id += 1
|
|
250
|
+
state.to_remember.append(f"Element {state.processed_id}")
|
|
251
|
+
while len(state.to_remember) > 2:
|
|
252
|
+
state.to_remember.pop(0)
|
|
253
|
+
|
|
254
|
+
logger.info(f"Processing item #{state.processed_id}")
|
|
255
|
+
for item in state.to_remember:
|
|
256
|
+
logger.info(f"- {item}")
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
$ python3 example9.py
|
|
261
|
+
INFO example9 Processing item #1
|
|
262
|
+
INFO example9 - Element 1
|
|
263
|
+
|
|
264
|
+
$ python3 example9.py
|
|
265
|
+
INFO example9 Processing item #2
|
|
266
|
+
INFO example9 - Element 1
|
|
267
|
+
INFO example9 - Element 2
|
|
268
|
+
|
|
269
|
+
$ python3 example9.py
|
|
270
|
+
INFO example9 Processing item #3
|
|
271
|
+
INFO example9 - Element 2
|
|
272
|
+
INFO example9 - Element 3
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Helps issuing a warning only once
|
|
276
|
+
|
|
277
|
+
[example10.py](https://github.com/presidento/scripthelper/blob/master/example10.py):
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
#!/usr/bin/env python3
|
|
281
|
+
import scripthelper
|
|
282
|
+
|
|
283
|
+
scripthelper.bootstrap()
|
|
284
|
+
|
|
285
|
+
for _ in range(10):
|
|
286
|
+
scripthelper.warning_once("Item #12 has some errors")
|
|
287
|
+
```
|
|
288
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "scripthelper"
|
|
3
|
+
version = "26.1"
|
|
4
|
+
description = "Helper module for creating simple Python scripts"
|
|
5
|
+
readme = "README.compiled.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
classifiers = [
|
|
8
|
+
"Development Status :: 5 - Production/Stable",
|
|
9
|
+
"Intended Audience :: Developers",
|
|
10
|
+
"Intended Audience :: System Administrators",
|
|
11
|
+
"Operating System :: OS Independent",
|
|
12
|
+
"Programming Language :: Python :: 3.11",
|
|
13
|
+
"Programming Language :: Python :: 3.12",
|
|
14
|
+
"Programming Language :: Python :: 3.13",
|
|
15
|
+
"Programming Language :: Python :: 3.14",
|
|
16
|
+
"Programming Language :: Python :: 3.15",
|
|
17
|
+
"Topic :: Utilities",
|
|
18
|
+
"Typing :: Typed",
|
|
19
|
+
]
|
|
20
|
+
requires-python = ">=3.11"
|
|
21
|
+
dependencies = [
|
|
22
|
+
"tqdm >= 4.31.1",
|
|
23
|
+
"coloredlogs >= 10.0",
|
|
24
|
+
"stackprinter >= 0.2.10",
|
|
25
|
+
"prettyprinter >= 0.18.0",
|
|
26
|
+
"persistedstate >= 23.6",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[[project.authors]]
|
|
30
|
+
name = "Máté Farkas"
|
|
31
|
+
email = "fm@farkas-mate.hu"
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/presidento/scripthelper"
|
|
35
|
+
Changelog = "https://github.com/presidento/scripthelper/blob/main/CHANGELOG.md"
|
|
36
|
+
|
|
37
|
+
[dependency-groups]
|
|
38
|
+
dev = [
|
|
39
|
+
"black",
|
|
40
|
+
"mypy",
|
|
41
|
+
"tox-uv>=1.25",
|
|
42
|
+
"tox",
|
|
43
|
+
"uv",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[tool.tox]
|
|
47
|
+
env_list = [
|
|
48
|
+
"py315",
|
|
49
|
+
"py314",
|
|
50
|
+
"py313",
|
|
51
|
+
"py312",
|
|
52
|
+
"py311",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[tool.tox.env_run_base]
|
|
56
|
+
commands = [[
|
|
57
|
+
"python",
|
|
58
|
+
"test_examples.py",
|
|
59
|
+
]]
|
|
60
|
+
|
|
61
|
+
[build-system]
|
|
62
|
+
requires = ["uv_build>=0.9.10,<0.14.0"]
|
|
63
|
+
build-backend = "uv_build"
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "scripthelper"
|
|
3
|
-
version = "
|
|
3
|
+
version = "26.1"
|
|
4
4
|
description = "Helper module for creating simple Python scripts"
|
|
5
5
|
readme = "README.compiled.md"
|
|
6
|
-
license =
|
|
6
|
+
license = "MIT"
|
|
7
7
|
classifiers = [
|
|
8
8
|
"Development Status :: 5 - Production/Stable",
|
|
9
9
|
"Intended Audience :: Developers",
|
|
10
10
|
"Intended Audience :: System Administrators",
|
|
11
|
-
"License :: OSI Approved :: MIT License",
|
|
12
11
|
"Operating System :: OS Independent",
|
|
13
|
-
"Programming Language :: Python :: 3.9",
|
|
14
|
-
"Programming Language :: Python :: 3.10",
|
|
15
12
|
"Programming Language :: Python :: 3.11",
|
|
16
13
|
"Programming Language :: Python :: 3.12",
|
|
17
14
|
"Programming Language :: Python :: 3.13",
|
|
18
15
|
"Programming Language :: Python :: 3.14",
|
|
16
|
+
"Programming Language :: Python :: 3.15",
|
|
19
17
|
"Topic :: Utilities",
|
|
20
18
|
"Typing :: Typed",
|
|
21
19
|
]
|
|
22
|
-
requires-python = ">=3.
|
|
20
|
+
requires-python = ">=3.11"
|
|
23
21
|
|
|
24
22
|
dependencies = [
|
|
25
23
|
"tqdm >= 4.31.1",
|
|
@@ -39,7 +37,7 @@ dev = [
|
|
|
39
37
|
]
|
|
40
38
|
|
|
41
39
|
[tool.tox]
|
|
42
|
-
env_list = ["py314", "py313", "py312", "py311"
|
|
40
|
+
env_list = ["py315", "py314", "py313", "py312", "py311"]
|
|
43
41
|
|
|
44
42
|
[tool.tox.env_run_base]
|
|
45
43
|
commands = [["python", "test_examples.py"]]
|
|
@@ -54,5 +52,5 @@ Homepage = "https://github.com/presidento/scripthelper"
|
|
|
54
52
|
Changelog = "https://github.com/presidento/scripthelper/blob/main/CHANGELOG.md"
|
|
55
53
|
|
|
56
54
|
[build-system]
|
|
57
|
-
requires = ["
|
|
58
|
-
build-backend = "
|
|
55
|
+
requires = ["uv_build>=0.9.10,<0.14.0"]
|
|
56
|
+
build-backend = "uv_build"
|