Skip to content

Commit 23dff24

Browse files
author
Matthias Koeppe
committed
src/sage/misc/replace_dot_all.py: Simplify print_log_messages, fold into main
1 parent 1c19d43 commit 23dff24

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/sage/misc/replace_dot_all.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
# We import this using __import__ so that "tox -e relint" does not complain about this source file.
5858
__import__("sage.all", globals(), locals(), ["*"])
5959

60+
6061
# Keep in sync with SAGE_ROOT/src/.relint.yml (namespace_pkg_all_import)
6162

6263
default_package_regex = (r"sage("
@@ -402,25 +403,6 @@ def walkdir_replace_dot_all(dir, file_regex=r'.*[.](py|pyx|pxi)$', package_regex
402403
make_replacements_in_file(location, package_regex, verbose)
403404

404405

405-
def print_log_messages():
406-
r"""
407-
Print out the messages collected in the global variable ``log_messages``.
408-
409-
This function sorts the lines of ``log_messages`` by the first character of each line (lines are separated by \n).
410-
"""
411-
global log_messages
412-
# split the log messages into a list of strings (each string is a line separated by a newline character)
413-
log_messages = log_messages.split('\n')
414-
# sort the list of strings
415-
log_messages.sort()
416-
# add index to each line
417-
for i, message in enumerate(log_messages):
418-
log_messages[i] = f'{i}. {message}'
419-
# join the list of strings into a single string separated by newline characters
420-
log_messages = '\n'.join(log_messages)[2:]
421-
print(log_messages)
422-
423-
424406
# ******************************************************** EXECUTES MAIN FUNCTION **********************************************************************
425407
# this executes the main function in this file which writes over all import statements matching regex in files in specified location matching fileRegex:
426408
if __name__ == "__main__":
@@ -457,7 +439,10 @@ def print_log_messages():
457439
finally:
458440
# Print report also when interrupted
459441
if verbosity:
460-
print_log_messages()
442+
log_messages = sorted(log_messages.rstrip().split('\n'))
443+
for i, message in enumerate(log_messages, start=1):
444+
# add index to each line
445+
print(f'{i}. {message.rstrip()}')
461446
report = 'REPORT:\n'
462447
report += f'Number of files checked: {numberFiles}\n'
463448
report += f'Number of files matching regex: {numberFilesMatchingRegex}\n'

0 commit comments

Comments
 (0)