Skip to content

Commit 1be3d90

Browse files
build: Pass MPI parameters in different order and check terminal width once
1 parent fa16e7a commit 1be3d90

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ns3

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ run_verbose = True
2626
path_sep = ";" if ";" in os.environ["PATH"] else ":"
2727
path_variable = "$PATH" if path_sep == ":" else "%PATH%"
2828

29+
try:
30+
TERMINAL_WIDTH = os.get_terminal_size().columns
31+
except OSError:
32+
TERMINAL_WIDTH = 80 # assume 80 columns when grepping
33+
2934

3035
# Prints everything in the print_buffer on exit
3136
def exit_handler(dry_run):
@@ -520,7 +525,7 @@ def parse_args(argv):
520525
if custom_exit in e.message:
521526
error_message = f"Exiting due to {e.message[e.message.index(custom_exit):]}"
522527
# 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)))
524529
exit(1)
525530

526531
# 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):
15031508
# running mpi on the CI?
15041509
if target_to_run in ["mpiexec", "mpirun"] and os.getenv("MPI_CI"):
15051510
if shutil.which("ompi_info"):
1506-
target_args = ["--oversubscribe"] + target_args
15071511
try:
15081512
subprocess.check_call([target_to_run, "--allow-run-as-root", "dir"])
15091513
target_args = ["--allow-run-as-root"] + target_args
15101514
except subprocess.CalledProcessError:
15111515
pass
1516+
target_args = ["--oversubscribe"] + target_args
15121517

15131518
program_arguments = [*debugging_software, target_to_run, *target_args]
15141519

@@ -1569,11 +1574,7 @@ def print_targets_list(ns3_modules: list, ns3_programs: dict) -> None:
15691574
def list_to_table(targets_list: list) -> str:
15701575
# Set column width and check how much is space is left at the end
15711576
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
15771578

15781579
# Filter the targets with names longer than the column width
15791580
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:
15871588
current_end = len(output)
15881589
# If the terminal width minus the written columns is smaller than the dead space,
15891590
# 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:
15911592
prev_new_line = len(output)
15921593
output += "\n"
15931594
# After the new line or space, add the item plus some spacing

0 commit comments

Comments
 (0)