libPyshell 0.4.1__tar.gz → 0.5.0__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: libPyshell
3
- Version: 0.4.1
3
+ Version: 0.5.0
4
4
  Summary: Support for writing shell scripts in Python
5
5
  Home-page: https://github.com/skogsbaer/libPyshell
6
6
  Author: Stefan Wehr
@@ -8,6 +8,13 @@ Author-email: stefan.wehr@gmail.com
8
8
  Requires-Python: >=3.9
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: home-page
16
+ Dynamic: requires-python
17
+ Dynamic: summary
11
18
 
12
19
  # Pyshell
13
20
 
@@ -37,6 +44,9 @@ magicFiles = run(['grep', 'magic'] + files, captureStdout=splitLines, onError='i
37
44
 
38
45
  ## Changelog
39
46
 
47
+ * 0.5.0 (2025-03-11)
48
+ * support of timeouts for run
49
+
40
50
  * 0.4.1 (2024-09-12)
41
51
  * fix capture handling
42
52
  * add failOnError option to rm commands
@@ -26,6 +26,9 @@ magicFiles = run(['grep', 'magic'] + files, captureStdout=splitLines, onError='i
26
26
 
27
27
  ## Changelog
28
28
 
29
+ * 0.5.0 (2025-03-11)
30
+ * support of timeouts for run
31
+
29
32
  * 0.4.1 (2024-09-12)
30
33
  * fix capture handling
31
34
  * add failOnError option to rm commands
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: libPyshell
3
- Version: 0.4.1
3
+ Version: 0.5.0
4
4
  Summary: Support for writing shell scripts in Python
5
5
  Home-page: https://github.com/skogsbaer/libPyshell
6
6
  Author: Stefan Wehr
@@ -8,6 +8,13 @@ Author-email: stefan.wehr@gmail.com
8
8
  Requires-Python: >=3.9
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: home-page
16
+ Dynamic: requires-python
17
+ Dynamic: summary
11
18
 
12
19
  # Pyshell
13
20
 
@@ -37,6 +44,9 @@ magicFiles = run(['grep', 'magic'] + files, captureStdout=splitLines, onError='i
37
44
 
38
45
  ## Changelog
39
46
 
47
+ * 0.5.0 (2025-03-11)
48
+ * support of timeouts for run
49
+
40
50
  * 0.4.1 (2024-09-12)
41
51
  * fix capture handling
42
52
  * add failOnError option to rm commands
@@ -2,7 +2,7 @@
2
2
 
3
3
  from distutils.core import setup
4
4
 
5
- VERSION = '0.4.1'
5
+ VERSION = '0.5.0'
6
6
 
7
7
  with open("README.md", "r", encoding="utf-8") as fh:
8
8
  long_description = fh.read()
@@ -227,7 +227,8 @@ def run(cmd: Union[list[str], str],
227
227
  decodeErrors: str='replace',
228
228
  decodeErrorsStdout: Optional[str]=None,
229
229
  decodeErrorsStderr: Optional[str]=None,
230
- encodeErrorsStdin: Optional[str]=None
230
+ encodeErrorsStdin: Optional[str]=None,
231
+ timeout: Optional[int]=None
231
232
  ) -> RunResult:
232
233
  """Runs the given command.
233
234
 
@@ -258,7 +259,8 @@ def run(cmd: Union[list[str], str],
258
259
  * `decodeErrors`: how to handle decoding/encoding errors on stdout and stderr and stdin.
259
260
  * `decodeErrorsStdout` and `decodeErrorsStderr` and `encodeErrorsStdin`: overwrite the value
260
261
  of decodeErrors for stdout or stderr or stdin
261
-
262
+ * `timeout`: an optional timeout value in seconds. If a timeout occurs, the exit code will
263
+ be 124 (as for the unix timeout command)
262
264
  Returns:
263
265
  a `RunResult` value, given access to the captured stdout of the child process (if it was
264
266
  captured at all) and to the exit code of the child process.
@@ -315,11 +317,20 @@ def run(cmd: Union[list[str], str],
315
317
  if _PYSHELL_DEBUG:
316
318
  _debug(f'subprocess.run({cmd}, shell={shell}, input={input}, stdout={stdout}, ' \
317
319
  f'stderr={stderr}, cwd={cwd}, env={runEnv})')
318
- res = subprocess.run(cmd, shell=shell, input=input, stdout=stdout, stderr=stderr, cwd=cwd,
319
- env=runEnv)
320
- stdoutData = _massageOutput(res.stdout, encoding, decodeErrorsStdout or decodeErrors, captureStdout)
321
- stderrData = _massageOutput(res.stderr, encoding, decodeErrorsStderr or decodeErrors, captureStderr)
322
- exitcode = res.returncode
320
+ try:
321
+ res = subprocess.run(cmd, shell=shell, input=input, stdout=stdout, stderr=stderr, cwd=cwd,
322
+ env=runEnv, timeout=timeout)
323
+ out = res.stdout
324
+ err = res.stderr
325
+ exitcode = res.returncode
326
+ hadTimeout = False
327
+ except subprocess.TimeoutExpired as e:
328
+ out = e.stdout
329
+ err = e.stderr
330
+ exitcode = 124
331
+ hadTimeout = True
332
+ stdoutData = _massageOutput(out, encoding, decodeErrorsStdout or decodeErrors, captureStdout)
333
+ stderrData = _massageOutput(err, encoding, decodeErrorsStderr or decodeErrors, captureStderr)
323
334
  if onError == 'raise' and exitcode != 0:
324
335
  err = RunError(cmd, exitcode, stdoutData, stderrData)
325
336
  raise err
File without changes
File without changes
File without changes