multiCMD 1.65__tar.gz → 1.67__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.
Files changed (44) hide show
  1. {multicmd-1.65/multiCMD.egg-info → multicmd-1.67}/PKG-INFO +31 -4
  2. multicmd-1.65/PKG-INFO → multicmd-1.67/README.md +29 -27
  3. multicmd-1.65/README.md → multicmd-1.67/multiCMD.egg-info/PKG-INFO +54 -1
  4. {multicmd-1.65 → multicmd-1.67}/multiCMD.py +95 -47
  5. multicmd-1.67/setup.py +41 -0
  6. multicmd-1.67/tests/test_helpers.py +934 -0
  7. {multicmd-1.65 → multicmd-1.67}/tests/test_windows.py +37 -5
  8. multicmd-1.65/setup.py +0 -31
  9. multicmd-1.65/tests/test_helpers.py +0 -423
  10. {multicmd-1.65 → multicmd-1.67}/LICENSE +0 -0
  11. {multicmd-1.65 → multicmd-1.67}/multiCMD.egg-info/SOURCES.txt +0 -0
  12. {multicmd-1.65 → multicmd-1.67}/multiCMD.egg-info/dependency_links.txt +0 -0
  13. {multicmd-1.65 → multicmd-1.67}/multiCMD.egg-info/entry_points.txt +0 -0
  14. {multicmd-1.65 → multicmd-1.67}/multiCMD.egg-info/top_level.txt +0 -0
  15. {multicmd-1.65 → multicmd-1.67}/scripts/multiCMD +0 -0
  16. {multicmd-1.65 → multicmd-1.67}/setup.cfg +0 -0
  17. {multicmd-1.65 → multicmd-1.67}/tests/test_api.py +0 -0
  18. {multicmd-1.65 → multicmd-1.67}/tests/test_async_executor.py +0 -0
  19. {multicmd-1.65 → multicmd-1.67}/tests/test_cli.py +0 -0
  20. {multicmd-1.65 → multicmd-1.67}/tests/test_cli_closed_stdout.py +0 -0
  21. {multicmd-1.65 → multicmd-1.67}/tests/test_cli_failed_stdout.py +0 -0
  22. {multicmd-1.65 → multicmd-1.67}/tests/test_cli_input.py +0 -0
  23. {multicmd-1.65 → multicmd-1.67}/tests/test_cli_summary.py +0 -0
  24. {multicmd-1.65 → multicmd-1.67}/tests/test_display.py +0 -0
  25. {multicmd-1.65 → multicmd-1.67}/tests/test_embed.py +0 -0
  26. {multicmd-1.65 → multicmd-1.67}/tests/test_env.py +0 -0
  27. {multicmd-1.65 → multicmd-1.67}/tests/test_expand_ranges.py +0 -0
  28. {multicmd-1.65 → multicmd-1.67}/tests/test_handover.py +0 -0
  29. {multicmd-1.65 → multicmd-1.67}/tests/test_interrupts.py +0 -0
  30. {multicmd-1.65 → multicmd-1.67}/tests/test_packaging.py +0 -0
  31. {multicmd-1.65 → multicmd-1.67}/tests/test_parsing.py +0 -0
  32. {multicmd-1.65 → multicmd-1.67}/tests/test_pass_fds.py +0 -0
  33. {multicmd-1.65 → multicmd-1.67}/tests/test_ping.py +0 -0
  34. {multicmd-1.65 → multicmd-1.67}/tests/test_pool.py +0 -0
  35. {multicmd-1.65 → multicmd-1.67}/tests/test_process_groups.py +0 -0
  36. {multicmd-1.65 → multicmd-1.67}/tests/test_pty.py +0 -0
  37. {multicmd-1.65 → multicmd-1.67}/tests/test_reader.py +0 -0
  38. {multicmd-1.65 → multicmd-1.67}/tests/test_reader_quit.py +0 -0
  39. {multicmd-1.65 → multicmd-1.67}/tests/test_regressions.py +0 -0
  40. {multicmd-1.65 → multicmd-1.67}/tests/test_run_command.py +0 -0
  41. {multicmd-1.65 → multicmd-1.67}/tests/test_run_commands.py +0 -0
  42. {multicmd-1.65 → multicmd-1.67}/tests/test_sudo.py +0 -0
  43. {multicmd-1.65 → multicmd-1.67}/tests/test_supervision.py +0 -0
  44. {multicmd-1.65 → multicmd-1.67}/tests/test_task.py +0 -0
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multiCMD
3
- Version: 1.65
3
+ Version: 1.67
4
4
  Summary: Run commands simultaneously
5
5
  Home-page: https://github.com/yufei-pan/multiCMD
6
6
  Author: Yufei Pan
7
7
  Author-email: pan@zopyr.us
8
- License: GPLv3+
8
+ License-Expression: GPL-3.0-or-later
9
9
  Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
10
  Classifier: Operating System :: POSIX :: Linux
12
11
  Classifier: Operating System :: Microsoft :: Windows
13
12
  Requires-Python: >=3.6
@@ -19,8 +18,8 @@ Dynamic: classifier
19
18
  Dynamic: description
20
19
  Dynamic: description-content-type
21
20
  Dynamic: home-page
22
- Dynamic: license
23
21
  Dynamic: license-file
22
+ Dynamic: license-expression
24
23
  Dynamic: requires-python
25
24
  Dynamic: summary
26
25
 
@@ -559,6 +558,34 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
559
558
 
560
559
  `test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
561
560
 
561
+ ## Upgrading to 1.67 from 1.66
562
+
563
+ - Nothing needs doing. `mcmd` is unchanged.
564
+ - Fix, library: `format_bytes()` counts a size string in whole bytes: `'4.1G'` is 4100000000 (1.66: 4099999999, from a
565
+ float). hpcp's size options (`-L`, `-F`, `-dis`, `-ddr`) take these values with 1.67.
566
+ - Fix, library: `format_bytes()` shows a size of 1000 Y or more in Y, as `'1000.00 Y'` or `'1024.00 Yi'` (1.66: `KeyError`),
567
+ and `float('inf')` as `'inf Yi'` (1.66: it never returned).
568
+ - Packaging: built with setuptools 77 or later, the metadata names the license as `License-Expression: GPL-3.0-or-later`.
569
+
570
+ ## Upgrading to 1.66 from 1.65
571
+
572
+ - Nothing needs doing for `mcmd`, which is unchanged, nor for hpcp 9.92, which checks its sizes itself. hpcp up to 9.91
573
+ hands `-L`, `-F`, `-dis` and `-ddr` to `format_bytes()` as typed and takes its `0` as the size: with 1.66 a value
574
+ with text after the size is `0`, so `-L 10MB/s` there is no limit and `-ddr 100G,50G` a 0-byte partition (1.65
575
+ read 100 G). Upgrade hpcp to 9.92 before or with 1.66, as for 1.65.
576
+ - Changed, library: at a terminal `input_with_timeout_and_countdown()` returns when its timeout runs out, whatever was
577
+ typed: text with no Enter (typed, then one Ctrl-D) is no answer, and a program that loaded `readline` waits no longer
578
+ (1.65: it waited for the line to end). With `readline` loaded, only the terminal's own editing works at this prompt
579
+ ([docs/limitations.md](docs/limitations.md)). A line ended before then, by Enter or by the end of the input, is the
580
+ answer. `timeout` may be a float (1.65: `TypeError`). A stdin that is not a terminal is read as in 1.65: a pipe that
581
+ sent part of a line still holds the call ([docs/limitations.md](docs/limitations.md)). On Windows a key pressed with
582
+ no Enter still holds it ([docs/limitations.md](docs/limitations.md)). A program that read part of a line at a
583
+ terminal itself keeps the rest of it ([docs/limitations.md](docs/limitations.md)).
584
+ - Changed, library: `format_bytes()` takes a string only when all of it is a size: text after the unit (`'5Gb/s'`, `'1e9'`,
585
+ `'5 kB extra'`) or an `i` with no prefix (`'5 iB'`) gives `0` and the "Invalid size format" line, as an unknown unit does
586
+ (1.65: it read the start). Blanks around the size are fine, now before it too. A unit after a number that ends in a point
587
+ is read (`'5.G'`: 5 G; 1.65: 5). With `to_str` such a string comes back as given.
588
+
562
589
  ## Upgrading to 1.65 from 1.64
563
590
 
564
591
  - Nothing needs doing for `mcmd`, which is unchanged. hpcp users upgrade hpcp to 9.92 before or with multiCMD 1.65: hpcp up
@@ -1,29 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: multiCMD
3
- Version: 1.65
4
- Summary: Run commands simultaneously
5
- Home-page: https://github.com/yufei-pan/multiCMD
6
- Author: Yufei Pan
7
- Author-email: pan@zopyr.us
8
- License: GPLv3+
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
- Classifier: Operating System :: POSIX :: Linux
12
- Classifier: Operating System :: Microsoft :: Windows
13
- Requires-Python: >=3.6
14
- Description-Content-Type: text/markdown
15
- License-File: LICENSE
16
- Dynamic: author
17
- Dynamic: author-email
18
- Dynamic: classifier
19
- Dynamic: description
20
- Dynamic: description-content-type
21
- Dynamic: home-page
22
- Dynamic: license
23
- Dynamic: license-file
24
- Dynamic: requires-python
25
- Dynamic: summary
26
-
27
1
  # multiCMD
28
2
 
29
3
  Run many commands at the same time — from the shell or from Python.
@@ -559,6 +533,34 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
559
533
 
560
534
  `test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
561
535
 
536
+ ## Upgrading to 1.67 from 1.66
537
+
538
+ - Nothing needs doing. `mcmd` is unchanged.
539
+ - Fix, library: `format_bytes()` counts a size string in whole bytes: `'4.1G'` is 4100000000 (1.66: 4099999999, from a
540
+ float). hpcp's size options (`-L`, `-F`, `-dis`, `-ddr`) take these values with 1.67.
541
+ - Fix, library: `format_bytes()` shows a size of 1000 Y or more in Y, as `'1000.00 Y'` or `'1024.00 Yi'` (1.66: `KeyError`),
542
+ and `float('inf')` as `'inf Yi'` (1.66: it never returned).
543
+ - Packaging: built with setuptools 77 or later, the metadata names the license as `License-Expression: GPL-3.0-or-later`.
544
+
545
+ ## Upgrading to 1.66 from 1.65
546
+
547
+ - Nothing needs doing for `mcmd`, which is unchanged, nor for hpcp 9.92, which checks its sizes itself. hpcp up to 9.91
548
+ hands `-L`, `-F`, `-dis` and `-ddr` to `format_bytes()` as typed and takes its `0` as the size: with 1.66 a value
549
+ with text after the size is `0`, so `-L 10MB/s` there is no limit and `-ddr 100G,50G` a 0-byte partition (1.65
550
+ read 100 G). Upgrade hpcp to 9.92 before or with 1.66, as for 1.65.
551
+ - Changed, library: at a terminal `input_with_timeout_and_countdown()` returns when its timeout runs out, whatever was
552
+ typed: text with no Enter (typed, then one Ctrl-D) is no answer, and a program that loaded `readline` waits no longer
553
+ (1.65: it waited for the line to end). With `readline` loaded, only the terminal's own editing works at this prompt
554
+ ([docs/limitations.md](docs/limitations.md)). A line ended before then, by Enter or by the end of the input, is the
555
+ answer. `timeout` may be a float (1.65: `TypeError`). A stdin that is not a terminal is read as in 1.65: a pipe that
556
+ sent part of a line still holds the call ([docs/limitations.md](docs/limitations.md)). On Windows a key pressed with
557
+ no Enter still holds it ([docs/limitations.md](docs/limitations.md)). A program that read part of a line at a
558
+ terminal itself keeps the rest of it ([docs/limitations.md](docs/limitations.md)).
559
+ - Changed, library: `format_bytes()` takes a string only when all of it is a size: text after the unit (`'5Gb/s'`, `'1e9'`,
560
+ `'5 kB extra'`) or an `i` with no prefix (`'5 iB'`) gives `0` and the "Invalid size format" line, as an unknown unit does
561
+ (1.65: it read the start). Blanks around the size are fine, now before it too. A unit after a number that ends in a point
562
+ is read (`'5.G'`: 5 G; 1.65: 5). With `to_str` such a string comes back as given.
563
+
562
564
  ## Upgrading to 1.65 from 1.64
563
565
 
564
566
  - Nothing needs doing for `mcmd`, which is unchanged. hpcp users upgrade hpcp to 9.92 before or with multiCMD 1.65: hpcp up
@@ -828,4 +830,4 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
828
830
  ## License
829
831
 
830
832
  GPLv3+ — see the package metadata. Authored by Yufei Pan (<pan@zopyr.us>).
831
- ```
833
+ ```
@@ -1,3 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: multiCMD
3
+ Version: 1.67
4
+ Summary: Run commands simultaneously
5
+ Home-page: https://github.com/yufei-pan/multiCMD
6
+ Author: Yufei Pan
7
+ Author-email: pan@zopyr.us
8
+ License-Expression: GPL-3.0-or-later
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Operating System :: Microsoft :: Windows
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license-file
22
+ Dynamic: license-expression
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
1
26
  # multiCMD
2
27
 
3
28
  Run many commands at the same time — from the shell or from Python.
@@ -533,6 +558,34 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
533
558
 
534
559
  `test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
535
560
 
561
+ ## Upgrading to 1.67 from 1.66
562
+
563
+ - Nothing needs doing. `mcmd` is unchanged.
564
+ - Fix, library: `format_bytes()` counts a size string in whole bytes: `'4.1G'` is 4100000000 (1.66: 4099999999, from a
565
+ float). hpcp's size options (`-L`, `-F`, `-dis`, `-ddr`) take these values with 1.67.
566
+ - Fix, library: `format_bytes()` shows a size of 1000 Y or more in Y, as `'1000.00 Y'` or `'1024.00 Yi'` (1.66: `KeyError`),
567
+ and `float('inf')` as `'inf Yi'` (1.66: it never returned).
568
+ - Packaging: built with setuptools 77 or later, the metadata names the license as `License-Expression: GPL-3.0-or-later`.
569
+
570
+ ## Upgrading to 1.66 from 1.65
571
+
572
+ - Nothing needs doing for `mcmd`, which is unchanged, nor for hpcp 9.92, which checks its sizes itself. hpcp up to 9.91
573
+ hands `-L`, `-F`, `-dis` and `-ddr` to `format_bytes()` as typed and takes its `0` as the size: with 1.66 a value
574
+ with text after the size is `0`, so `-L 10MB/s` there is no limit and `-ddr 100G,50G` a 0-byte partition (1.65
575
+ read 100 G). Upgrade hpcp to 9.92 before or with 1.66, as for 1.65.
576
+ - Changed, library: at a terminal `input_with_timeout_and_countdown()` returns when its timeout runs out, whatever was
577
+ typed: text with no Enter (typed, then one Ctrl-D) is no answer, and a program that loaded `readline` waits no longer
578
+ (1.65: it waited for the line to end). With `readline` loaded, only the terminal's own editing works at this prompt
579
+ ([docs/limitations.md](docs/limitations.md)). A line ended before then, by Enter or by the end of the input, is the
580
+ answer. `timeout` may be a float (1.65: `TypeError`). A stdin that is not a terminal is read as in 1.65: a pipe that
581
+ sent part of a line still holds the call ([docs/limitations.md](docs/limitations.md)). On Windows a key pressed with
582
+ no Enter still holds it ([docs/limitations.md](docs/limitations.md)). A program that read part of a line at a
583
+ terminal itself keeps the rest of it ([docs/limitations.md](docs/limitations.md)).
584
+ - Changed, library: `format_bytes()` takes a string only when all of it is a size: text after the unit (`'5Gb/s'`, `'1e9'`,
585
+ `'5 kB extra'`) or an `i` with no prefix (`'5 iB'`) gives `0` and the "Invalid size format" line, as an unknown unit does
586
+ (1.65: it read the start). Blanks around the size are fine, now before it too. A unit after a number that ends in a point
587
+ is read (`'5.G'`: 5 G; 1.65: 5). With `to_str` such a string comes back as given.
588
+
536
589
  ## Upgrading to 1.65 from 1.64
537
590
 
538
591
  - Nothing needs doing for `mcmd`, which is unchanged. hpcp users upgrade hpcp to 9.92 before or with multiCMD 1.65: hpcp up
@@ -802,4 +855,4 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
802
855
  ## License
803
856
 
804
857
  GPLv3+ — see the package metadata. Authored by Yufei Pan (<pan@zopyr.us>).
805
- ```
858
+ ```
@@ -29,9 +29,9 @@ import traceback
29
29
  from pprint import pformat
30
30
 
31
31
  #%% global vars
32
- version = '1.65'
32
+ version = '1.67'
33
33
  __version__ = version
34
- COMMIT_DATE = '2026-11-13'
34
+ COMMIT_DATE = '2026-11-14'
35
35
  # fire-and-forget threads (run_commands with wait_for_return=False) that join_threads() waits on. multiCMD takes no
36
36
  # lock for it: each update is one set operation and each snapshot one set.copy(), as for _live_procs below
37
37
  __running_threads = set()
@@ -3250,55 +3250,102 @@ def _run_cli():
3250
3250
  #%% misc functions
3251
3251
  def input_with_timeout_and_countdown(timeout, prompt='Please enter your selection'):
3252
3252
  """
3253
- Read an input from the user with a timeout and a countdown. The prompt and its countdown go to stderr, after what is
3253
+ Read a line from the user, counting down timeout seconds. The prompt and its countdown go to stderr, after what is
3254
3254
  waiting in stdout's buffer ( the caller's question ); one that cannot be written is dropped, and the timeout still applies.
3255
3255
 
3256
3256
  @params:
3257
- timeout: The timeout in seconds
3257
+ timeout: The timeout in seconds, an int or a float ( the countdown shows the seconds left, rounded up )
3258
3258
  prompt: The prompt to display to the user
3259
3259
 
3260
3260
  @returns:
3261
- str: The input from the user or None if no input was received: the timeout ran out. A stdin that has ended, is closed
3262
- or is missing ( Ctrl-D, /dev/null ) counts as no answer: the countdown goes on asking, and takes a line typed before its end
3261
+ str: The line typed before the timeout ran out, stripped ( Enter ends it, and so does the end of the input after text );
3262
+ or None if no input was received by then: text not ended, and a stdin that has ended, is closed or is missing
3263
+ ( Ctrl-D, /dev/null ), count as no answer, and the call returns when the timeout runs out, never sooner, and at a
3264
+ terminal never later ( a stdin that is not a terminal, and Windows: docs/limitations.md )
3263
3265
 
3264
3266
  """
3265
3267
  # the question the caller printed goes out first; the prompt and its countdown are for the person at the terminal, not for
3266
3268
  # stdout's reader: they go to stderr, as read -p's and rm -i's do, and one that cannot be written is dropped
3267
3269
  _display.flush()
3268
- _write_error(f"{prompt} [{timeout}s]: ", end='')
3270
+ _write_error(f"{prompt} [{math.ceil(timeout)}s]: ", end='')
3269
3271
  # select() cannot watch stdin on Windows; msvcrt can tell whether a key is waiting
3270
3272
  try:
3271
3273
  import msvcrt
3272
3274
  except ImportError:
3273
3275
  msvcrt = None
3274
- # a stdin with no answer ( none, closed, or at its end: Ctrl-D, /dev/null, a pipe that ended ) is no reason to stop the
3275
- # countdown early: the default applies when it ends, and a Ctrl-C still aborts. It is asked again every second, as the
3276
- # countdown is still asking: a terminal can answer after a Ctrl-D ( one select() and one input() a second: no busy loop )
3276
+ # a stdin that is missing or closed is not asked: the countdown runs out
3277
3277
  no_stdin = sys.stdin is None or getattr(sys.stdin, 'closed', False)
3278
- # stdin is asked at the start of each second and once more at the end, so a line typed in the last second counts too
3279
- for remaining in range(timeout, -1, -1):
3280
- # If there is an input, return it
3281
- if not no_stdin:
3282
- try:
3283
- if msvcrt is not None:
3284
- if msvcrt.kbhit():
3285
- return input().strip()
3286
- elif sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
3278
+ fd = None
3279
+ if msvcrt is None and not no_stdin:
3280
+ # a stdin select() cannot watch ( no descriptor: a StringIO ) raises here: it was not asked, so it is not "no answer"
3281
+ fd = sys.stdin.fileno()
3282
+ # the count is by the clock. A terminal is read by its descriptor, and only as far as select() says there is something:
3283
+ # input() would wait for a whole line with no timeout ( text typed and then Ctrl-D, a program that loaded readline ). In
3284
+ # its line mode it gives at most a line per read, and must be read in whole reads: macOS tells text that a Ctrl-D handed
3285
+ # over from the end of the input only so; out of its line mode ( cbreak, raw ) one read gives all that was typed, the
3286
+ # next line with it, so it is read a byte at a time. Anything else ( a pipe, a file ) is read by Python itself, as in
3287
+ # 1.65: nobody is typing there, and only Python knows what the program's own reading already holds
3288
+ tty = canon = False
3289
+ if fd is not None:
3290
+ try:
3291
+ import termios
3292
+ canon = bool(termios.tcgetattr(fd)[3] & termios.ICANON)
3293
+ tty = True
3294
+ except Exception:
3295
+ # not a terminal, one that is gone, or no termios
3296
+ pass
3297
+ deadline = time.monotonic() + timeout
3298
+ typed = bytearray()
3299
+ shown = None
3300
+ while True:
3301
+ remaining = deadline - time.monotonic()
3302
+ seconds = max(math.ceil(remaining), 0)
3303
+ if seconds and seconds != shown:
3304
+ shown = seconds
3305
+ _write_error(f"\r{prompt} [{seconds}s]: ", end='')
3306
+ # stdin is watched until the next whole second, and asked once more when the countdown ends
3307
+ wait = remaining - (seconds - 1) if seconds else 0
3308
+ # ended: nothing waited for stdin this second ( none to watch, the console, or its end ), so time.sleep() waits
3309
+ ended = fd is None
3310
+ try:
3311
+ if msvcrt is not None:
3312
+ # the console is asked once a second
3313
+ if not no_stdin and msvcrt.kbhit():
3287
3314
  return input().strip()
3288
- except io.UnsupportedOperation:
3289
- # a stdin select() cannot watch ( no descriptor: a StringIO ) was not asked: that is not "no answer", as in 1.64
3290
- raise
3291
- except (EOFError, OSError):
3292
- # no answer this second. EOFError: at its end, or a Ctrl-D; OSError: its descriptor closed, or its terminal gone
3293
- pass
3294
- if remaining == 0:
3295
- break
3296
- # Print the remaining time
3297
- _write_error(f"\r{prompt} [{remaining}s]: ", end='')
3298
- # Wait a second
3299
- time.sleep(1)
3300
- # If there is no input, return None
3301
- return None
3315
+ elif fd is not None and select.select([fd], [], [], wait)[0]:
3316
+ if not tty:
3317
+ return input().strip()
3318
+ data = os.read(fd, 4096 if canon else 1)
3319
+ typed += data
3320
+ if data and b'\n' not in data:
3321
+ # read on at once: the rest of the line is there, or comes. Once the countdown has ended, up to 4096 bytes: the longest
3322
+ # line a terminal's line mode takes in one piece ( Linux 4095 bytes and the newline, macOS 1023; measured ). So a line of
3323
+ # up to that length typed before the end is read to its end, also when that takes many reads ( out of the line mode a
3324
+ # read is a byte; a Ctrl-D splits a line ), and text that keeps coming stops within 4097 reads: more than 4096 bytes with
3325
+ # no end of the line is no answer
3326
+ if remaining <= 0 and len(typed) > 4096:
3327
+ return None
3328
+ continue
3329
+ if typed:
3330
+ # Enter, or the end of the input after text ( Ctrl-D twice )
3331
+ line = bytes(typed).split(b'\n', 1)[0]
3332
+ # decoded as stdin itself decodes: bytes that are not text are kept under the C locale ( surrogateescape ), and a
3333
+ # strict stdin raises, as in 1.65 and as input() does for any other stdin
3334
+ return line.decode(getattr(sys.stdin, 'encoding', None) or 'utf-8', getattr(sys.stdin, 'errors', None) or 'strict').strip()
3335
+ # a Ctrl-D: no answer this second
3336
+ ended = True
3337
+ except io.UnsupportedOperation:
3338
+ # a stdin that cannot be read ( one the program opened for writing ) was not asked: not "no answer", as in 1.65
3339
+ raise
3340
+ except (EOFError, OSError):
3341
+ # no answer this second, as in 1.65. EOFError: input() at the end of the input ( msvcrt's Ctrl-Z too ); OSError: the
3342
+ # descriptor closed, or its terminal gone
3343
+ ended = True
3344
+ if remaining <= 0:
3345
+ return None
3346
+ # an ended stdin is asked again at the next second, not in a busy loop: a terminal can answer after a Ctrl-D
3347
+ if ended:
3348
+ time.sleep(max(deadline - (seconds - 1) - time.monotonic(), 0))
3302
3349
 
3303
3350
  def pretty_format_table(data, delimiter=None, header=None, full=False, remove_empty_columns=False):
3304
3351
  import re
@@ -3626,7 +3673,10 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False, str_form
3626
3673
  if isinstance(size, int):
3627
3674
  return size
3628
3675
  elif isinstance(size, str):
3629
- match = re.match(r"(\d+(\.\d+)?)\s*([a-zA-Z]*)", size)
3676
+ # the whole string is a size: a number, then a unit or none ( K to Y, an i after it for 1024s, a B at the end ), with
3677
+ # blanks around them; anything else, text after the unit too ( '5Gb/s', '1e9' ), is not one ( 1.65 read its start ).
3678
+ # The blanks around go by strip(): a \s* at each end of the pattern would retry every split of a long run of them
3679
+ match = re.fullmatch(r"(\d+(\.\d*)?)\s*((?:[kmgtpezyKMGTPEZY][iI]?)?[bB]?)", size.strip())
3630
3680
  unit_labels = {
3631
3681
  "": 0,
3632
3682
  "k": 1,
@@ -3640,15 +3690,14 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False, str_form
3640
3690
  }
3641
3691
  if match:
3642
3692
  number, _, unit = match.groups()
3643
- number = float(number)
3644
- unit = unit.strip().lower().rstrip("b")
3693
+ unit = unit.lower().rstrip("b")
3645
3694
  if unit.endswith("i"):
3646
3695
  use_1024_bytes = True
3647
3696
  elif use_1024_bytes is None:
3648
3697
  use_1024_bytes = False
3649
3698
  unit = unit.rstrip("i")
3650
- # no number, or a unit that is none of these: not a size ( 1.64 returned None for the unit )
3651
- if not match or unit not in unit_labels:
3699
+ # not a size: no number, a unit it does not know ( 1.64 returned None ), or text after it
3700
+ if not match:
3652
3701
  if to_str:
3653
3702
  return size
3654
3703
  _write_error("Invalid size format. Expected format: 'number [unit]', e.g., '1.5 GiB' or '1.5GiB'\n" f"Got: {size}")
@@ -3657,14 +3706,12 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False, str_form
3657
3706
  power = 2**10
3658
3707
  else:
3659
3708
  power = 10**3
3709
+ # in whole numbers, not a float: '4.1G' is 4100000000 bytes ( 1.66: 4099999999 ); a part of a byte is cut off, as before
3710
+ whole, _, fraction = number.partition(".")
3711
+ size_in_bytes = int(whole + fraction) * power**unit_labels[unit] // 10**len(fraction)
3660
3712
  if to_str:
3661
- return format_bytes(
3662
- size=int(number * (power**unit_labels[unit])),
3663
- use_1024_bytes=use_1024_bytes,
3664
- to_str=True,
3665
- str_format=str_format,
3666
- )
3667
- return int(number * (power**unit_labels[unit]))
3713
+ return format_bytes(size=size_in_bytes, use_1024_bytes=use_1024_bytes, to_str=True, str_format=str_format)
3714
+ return size_in_bytes
3668
3715
  else:
3669
3716
  try:
3670
3717
  return int(size)
@@ -3691,7 +3738,8 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False, str_form
3691
3738
  7: "Zi",
3692
3739
  8: "Yi",
3693
3740
  }
3694
- while size >= power:
3741
+ # Y is the last unit: a larger size stays in Y ( 1.66 stepped past it to a KeyError, and float('inf') never stopped )
3742
+ while size >= power and n < len(power_labels) - 1:
3695
3743
  size /= power
3696
3744
  n += 1
3697
3745
  return f"{size:{str_format}} {' '}{power_labels[n]}".replace(" ", " ")
@@ -3709,7 +3757,7 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False, str_form
3709
3757
  7: "Z",
3710
3758
  8: "Y",
3711
3759
  }
3712
- while size >= power:
3760
+ while size >= power and n < len(power_labels) - 1:
3713
3761
  size /= power
3714
3762
  n += 1
3715
3763
  return f"{size:{str_format}} {' '}{power_labels[n]}".replace(" ", " ")
multicmd-1.67/setup.py ADDED
@@ -0,0 +1,41 @@
1
+ import setuptools
2
+ from setuptools import setup
3
+ from multiCMD import __version__
4
+
5
+ classifiers = [
6
+ 'Programming Language :: Python :: 3',
7
+ 'Operating System :: POSIX :: Linux',
8
+ 'Operating System :: Microsoft :: Windows',
9
+ ]
10
+ # setuptools 77+ (PEP 639) takes an SPDX license expression and warns about license classifiers (an error next to an
11
+ # expression); older ones (the newest for Python 3.8 and earlier, so all a Python 3.6 install has) know only the
12
+ # free-text license and the classifier. Their sdist and wheel take LICENSE by its name (setuptools 56+, wheel 0.32+).
13
+ if int(setuptools.__version__.split('.')[0]) >= 77:
14
+ license_metadata = {'license_expression': 'GPL-3.0-or-later', 'license_files': ['LICENSE']}
15
+ else:
16
+ license_metadata = {'license': 'GPL-3.0-or-later'}
17
+ classifiers.append('License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)')
18
+
19
+ setup(
20
+ name='multiCMD',
21
+ version=__version__,
22
+ description='Run commands simultaneously',
23
+ long_description=open('README.md', encoding='utf-8').read(),
24
+ long_description_content_type='text/markdown',
25
+ author='Yufei Pan',
26
+ author_email='pan@zopyr.us',
27
+ url='https://github.com/yufei-pan/multiCMD',
28
+ py_modules=['multiCMD'],
29
+ # The mixed-case command is a script file and not an entry point: pip 9 (stock on EL7 and EL8) reads entry_points.txt with a
30
+ # parser that folds case, so two commands that differ only in case make it fail to upgrade or uninstall the package.
31
+ scripts=['scripts/multiCMD'],
32
+ entry_points={
33
+ 'console_scripts': [
34
+ 'mcmd=multiCMD:main',
35
+ 'multicmd=multiCMD:main',
36
+ ],
37
+ },
38
+ classifiers=classifiers,
39
+ python_requires='>=3.6',
40
+ **license_metadata
41
+ )