pyallel 1.3.0__tar.gz → 1.3.2__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
1
  Metadata-Version: 2.1
2
2
  Name: pyallel
3
- Version: 1.3.0
3
+ Version: 1.3.2
4
4
  Summary: Run and handle the output of multiple executables in pyallel (as in parallel)
5
5
  Home-page: https://github.com/Danthewaann/pyallel
6
6
  License: MIT
@@ -66,7 +66,7 @@ positional arguments:
66
66
  --------------
67
67
  commands can be grouped using the group separator symbol (:::)
68
68
 
69
- %(prog)s "echo boil kettle" "sleep 1" ::: "echo make coffee"
69
+ pyallel "echo boil kettle" "sleep 1" ::: "echo make coffee"
70
70
 
71
71
  the above will print "boil kettle" and sleep for 1 second first before printing "make coffee"
72
72
 
@@ -79,8 +79,8 @@ positional arguments:
79
79
 
80
80
  lines (only used in interactive mode):
81
81
  the lines modifier allows you to specify how many lines the command output can take up on the screen
82
-
83
- %(prog)s "lines=90 :: echo running long command..." "echo running other command..."
82
+
83
+ pyallel "lines=90 :: echo running long command..." "echo running other command..."
84
84
 
85
85
  90 is expressed as a percentage value, which must be between 1 and 100 inclusive
86
86
 
@@ -42,7 +42,7 @@ positional arguments:
42
42
  --------------
43
43
  commands can be grouped using the group separator symbol (:::)
44
44
 
45
- %(prog)s "echo boil kettle" "sleep 1" ::: "echo make coffee"
45
+ pyallel "echo boil kettle" "sleep 1" ::: "echo make coffee"
46
46
 
47
47
  the above will print "boil kettle" and sleep for 1 second first before printing "make coffee"
48
48
 
@@ -55,8 +55,8 @@ positional arguments:
55
55
 
56
56
  lines (only used in interactive mode):
57
57
  the lines modifier allows you to specify how many lines the command output can take up on the screen
58
-
59
- %(prog)s "lines=90 :: echo running long command..." "echo running other command..."
58
+
59
+ pyallel "lines=90 :: echo running long command..." "echo running other command..."
60
60
 
61
61
  90 is expressed as a percentage value, which must be between 1 and 100 inclusive
62
62
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pyallel"
3
- version = "1.3.0"
3
+ version = "1.3.2"
4
4
  description = "Run and handle the output of multiple executables in pyallel (as in parallel)"
5
5
  authors = ["Daniel Black <danielcrblack@gmail.com>"]
6
6
  license = "MIT"
@@ -35,7 +35,7 @@ def run_interactive(
35
35
  if poll > 0:
36
36
  return poll
37
37
 
38
- printer.clear()
38
+ printer.reset()
39
39
  process_group_manager.run()
40
40
  if not process_group_manager.next():
41
41
  return 0
@@ -243,9 +243,9 @@ class Printer:
243
243
  end="",
244
244
  )
245
245
 
246
- self.clear()
246
+ self.reset()
247
247
 
248
- def clear(self) -> None:
248
+ def reset(self) -> None:
249
249
  self._printed.clear()
250
250
 
251
251
 
@@ -259,32 +259,52 @@ def set_process_lines(
259
259
  lines -= 2
260
260
 
261
261
  # Allocate lines to processes that have a fixed percentage of lines set
262
+ allocated_process_lines = lines // len(output.processes)
263
+ processes_with_dynamic_lines: list[ProcessOutput] = []
262
264
  used_lines = 0
263
- other_processes: list[ProcessOutput] = []
264
- for out in output.processes:
265
- if not out.process.percentage_lines:
266
- other_processes.append(out)
265
+ for process_output in output.processes:
266
+ # This process output doesn't have percentage_lines set, so skip it
267
+ if not process_output.process.percentage_lines:
268
+ processes_with_dynamic_lines.append(process_output)
267
269
  continue
268
270
 
269
- out.process.lines = int(lines * out.process.percentage_lines)
270
- used_lines += out.process.lines
271
+ process_output.process.lines = int(
272
+ lines * process_output.process.percentage_lines
273
+ )
274
+ used_lines += process_output.process.lines
271
275
 
276
+ # Remove the used lines from the total available lines
272
277
  lines -= used_lines
273
278
 
274
- # Allocate the rest of the available lines to the other processes that don't have fixed lines set
275
- num_dynamic_processes = len(other_processes)
276
- if num_dynamic_processes:
277
- remainder = lines % num_dynamic_processes
278
- tail = lines // num_dynamic_processes
279
-
280
- for out in other_processes:
281
- out.process.lines = tail
282
-
283
- # If we have lines left to allocate, we give all of them to the last process
284
- if remainder:
285
- for out in other_processes[-1::-1]:
286
- out.process.lines += remainder
287
- break
279
+ while lines:
280
+ # Calculate how many lines each process should have based on how many processes and lines are left
281
+ num_processes = len(processes_with_dynamic_lines) or 1
282
+ allocated_process_lines = lines // num_processes
283
+ processes_with_excess_output: list[ProcessOutput] = []
284
+ recalculate_lines = False
285
+ for process_output in processes_with_dynamic_lines:
286
+ # If the number of lines in this process output is less than how many terminal lines we would allocate it,
287
+ # Set it's allocated terminal lines to the exact number of lines in its output and remove this number from
288
+ # the total available terminal lines
289
+ if process_output.lines < allocated_process_lines:
290
+ process_output.process.lines = process_output.lines
291
+ lines -= process_output.process.lines
292
+ recalculate_lines = True
293
+ continue
294
+
295
+ processes_with_excess_output.append(process_output)
296
+
297
+ # We need to re-calcuate how many terminal lines we can allocate to each process if the output of at least one process
298
+ # contains less lines than what we would normally allocate it. This is done so we can allocate these extra lines to the
299
+ # other processes that contain more lines of output.
300
+ if recalculate_lines:
301
+ processes_with_dynamic_lines = processes_with_excess_output
302
+ else:
303
+ # All remaining processes exceed the number of terminal lines we will allocate them, so allocate them
304
+ # their terminal lines as normal and break out of the while loop
305
+ for process_output in processes_with_excess_output:
306
+ process_output.process.lines = allocated_process_lines
307
+ break
288
308
 
289
309
 
290
310
  def get_num_lines(line: str, columns: int | None = None) -> int:
@@ -13,10 +13,12 @@ class ProcessOutput:
13
13
  def __init__(self, id: int, process: Process, data: str = "") -> None:
14
14
  self.id = id
15
15
  self.data = data
16
+ self.lines = len(data.splitlines()) + 1
16
17
  self.process = process
17
18
 
18
19
  def merge(self, other: ProcessOutput) -> None:
19
20
  self.data += other.data
21
+ self.lines += len(other.data.splitlines())
20
22
 
21
23
 
22
24
  class Process:
@@ -82,7 +84,7 @@ class Process:
82
84
 
83
85
  args, *parts = cmd
84
86
 
85
- percentage_lines = 0.0
87
+ percentage_lines = 0
86
88
  for arg in args.split(" "):
87
89
  try:
88
90
  arg, value = args.split("=")
@@ -91,17 +93,17 @@ class Process:
91
93
 
92
94
  if arg == "lines":
93
95
  try:
94
- percentage_lines = int(value) / 100
96
+ percentage_lines = int(value)
95
97
  except ValueError:
96
98
  raise InvalidLinesModifierError(
97
99
  "lines modifier must be a number between 1 and 100"
98
100
  )
99
101
 
100
- if not 0.0 < percentage_lines <= 1.0:
102
+ if not 0 < percentage_lines <= 100:
101
103
  raise InvalidLinesModifierError(
102
104
  "lines modifier must be a number between 1 and 100"
103
105
  )
104
106
 
105
107
  break
106
108
 
107
- return cls(id, " ".join(parts), percentage_lines)
109
+ return cls(id, " ".join(parts), round(percentage_lines / 100, 2))
@@ -72,7 +72,7 @@ class ProcessGroup:
72
72
  percentage_lines_sum += process.percentage_lines
73
73
  processes.append(process)
74
74
 
75
- if percentage_lines_sum > 1.0:
75
+ if round(percentage_lines_sum, 2) > 1.0:
76
76
  raise InvalidLinesModifierError(
77
77
  "lines modifier must not exceed 100 across all processes within each process group"
78
78
  )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes