@@ -26,6 +26,11 @@ run_verbose = True
26
26
path_sep = ";" if ";" in os .environ ["PATH" ] else ":"
27
27
path_variable = "$PATH" if path_sep == ":" else "%PATH%"
28
28
29
+ try :
30
+ TERMINAL_WIDTH = os .get_terminal_size ().columns
31
+ except OSError :
32
+ TERMINAL_WIDTH = 80 # assume 80 columns when grepping
33
+
29
34
30
35
# Prints everything in the print_buffer on exit
31
36
def exit_handler (dry_run ):
@@ -520,7 +525,7 @@ def parse_args(argv):
520
525
if custom_exit in e .message :
521
526
error_message = f"Exiting due to { e .message [e .message .index (custom_exit ):]} "
522
527
# Format error message to better fit the terminal width
523
- print ("\n " .join (textwrap .wrap (error_message , width = os . get_terminal_size (). columns )))
528
+ print ("\n " .join (textwrap .wrap (error_message , width = TERMINAL_WIDTH )))
524
529
exit (1 )
525
530
526
531
# If run doesn't have a target, print the help message of the run parser
@@ -1503,12 +1508,12 @@ def run_step(args, target_to_run, target_args):
1503
1508
# running mpi on the CI?
1504
1509
if target_to_run in ["mpiexec" , "mpirun" ] and os .getenv ("MPI_CI" ):
1505
1510
if shutil .which ("ompi_info" ):
1506
- target_args = ["--oversubscribe" ] + target_args
1507
1511
try :
1508
1512
subprocess .check_call ([target_to_run , "--allow-run-as-root" , "dir" ])
1509
1513
target_args = ["--allow-run-as-root" ] + target_args
1510
1514
except subprocess .CalledProcessError :
1511
1515
pass
1516
+ target_args = ["--oversubscribe" ] + target_args
1512
1517
1513
1518
program_arguments = [* debugging_software , target_to_run , * target_args ]
1514
1519
@@ -1569,11 +1574,7 @@ def print_targets_list(ns3_modules: list, ns3_programs: dict) -> None:
1569
1574
def list_to_table (targets_list : list ) -> str :
1570
1575
# Set column width and check how much is space is left at the end
1571
1576
columnwidth = 30
1572
- try :
1573
- terminal_width = os .get_terminal_size ().columns
1574
- except OSError :
1575
- terminal_width = 80 # assume 80 columns when grepping
1576
- dead_space = terminal_width % columnwidth
1577
+ dead_space = TERMINAL_WIDTH % columnwidth
1577
1578
1578
1579
# Filter the targets with names longer than the column width
1579
1580
large_items = list (filter (lambda x : len (x ) >= columnwidth , targets_list ))
@@ -1587,7 +1588,7 @@ def print_targets_list(ns3_modules: list, ns3_programs: dict) -> None:
1587
1588
current_end = len (output )
1588
1589
# If the terminal width minus the written columns is smaller than the dead space,
1589
1590
# we add a new line and start counting the width of the new line from it
1590
- if terminal_width - (current_end - prev_new_line ) < dead_space :
1591
+ if TERMINAL_WIDTH - (current_end - prev_new_line ) < dead_space :
1591
1592
prev_new_line = len (output )
1592
1593
output += "\n "
1593
1594
# After the new line or space, add the item plus some spacing
0 commit comments