Skip to content

Commit fe617e9

Browse files
author
Matthias Koeppe
committed
src/sage/misc/replace_dot_all.py: Fold parse_arguments into main
1 parent ac83a49 commit fe617e9

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

src/sage/misc/replace_dot_all.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,6 @@
6464
r")[.]all")
6565

6666

67-
# to parse arguments passed to the script
68-
69-
def parse_arguments():
70-
r"""
71-
Parse command-line arguments
72-
"""
73-
# Create argument parser
74-
parser = argparse.ArgumentParser()
75-
# Optional arguments
76-
parser.add_argument(
77-
"location",
78-
metavar='files or directories',
79-
nargs='*',
80-
help=("Names of source directories or source files. "
81-
"If none given, walks through all files in src/sage."),
82-
type=str)
83-
parser.add_argument(
84-
"-v", "--verbose",
85-
help="Increase output verbosity. Shows locations of any unusual cases of import statements and the corresponding changes.",
86-
action="store_true") # Parse arguments
87-
args = parser.parse_args()
88-
return args
89-
90-
9167
# Global variables
9268

9369
examples = list('ABCDEFGHIJ') # controls how we print out interesting examples to the console
@@ -105,8 +81,7 @@ def find_replacements(location, package_regex=None, verbose=False):
10581
10682
INPUT:
10783
108-
- ``location`` -- a file path file_to_change = 'schemes/elliptic_curves/ell_rational_field.py'
109-
location = cwd + file_to_change
84+
- ``location`` -- a file path
11085
- ``package_regex`` -- (default: :obj:`default_package_regex`) a regular expression matching
11186
the ``sage.PAC.KAGE.all`` package names from which we do not want to import.
11287
- ``verbose`` -- a parameter which if used will issue print statements when interesting examples are found
@@ -443,8 +418,21 @@ def print_log_messages():
443418
# ******************************************************** EXECUTES MAIN FUNCTION **********************************************************************
444419
# this executes the main function in this file which writes over all import statements matching regex in files in specified location matching fileRegex:
445420
if __name__ == "__main__":
446-
# Parse the arguments
447-
args = parse_arguments()
421+
# Create argument parser
422+
parser = argparse.ArgumentParser()
423+
# Optional arguments
424+
parser.add_argument(
425+
"location",
426+
metavar='files or directories',
427+
nargs='*',
428+
help=("Names of source directories or source files. "
429+
"If none given, walks through all files in src/sage."),
430+
type=str)
431+
parser.add_argument(
432+
"-v", "--verbose",
433+
help="Increase output verbosity. Shows locations of any unusual cases of import statements and the corresponding changes.",
434+
action="store_true") # Parse arguments
435+
args = parser.parse_args()
448436
verbosity = args.verbose
449437
# Declare regular expressions
450438
file_regex = r'.*[.](py|pyx|pxi)$'

0 commit comments

Comments
 (0)