Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
src/sage/misc/replace_dot_all.py: Fold parse_arguments into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jan 29, 2023
1 parent ac83a49 commit fe617e9
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions src/sage/misc/replace_dot_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,6 @@
r")[.]all")


# to parse arguments passed to the script

def parse_arguments():
r"""
Parse command-line arguments
"""
# Create argument parser
parser = argparse.ArgumentParser()
# Optional arguments
parser.add_argument(
"location",
metavar='files or directories',
nargs='*',
help=("Names of source directories or source files. "
"If none given, walks through all files in src/sage."),
type=str)
parser.add_argument(
"-v", "--verbose",
help="Increase output verbosity. Shows locations of any unusual cases of import statements and the corresponding changes.",
action="store_true") # Parse arguments
args = parser.parse_args()
return args


# Global variables

examples = list('ABCDEFGHIJ') # controls how we print out interesting examples to the console
Expand All @@ -105,8 +81,7 @@ def find_replacements(location, package_regex=None, verbose=False):
INPUT:
- ``location`` -- a file path file_to_change = 'schemes/elliptic_curves/ell_rational_field.py'
location = cwd + file_to_change
- ``location`` -- a file path
- ``package_regex`` -- (default: :obj:`default_package_regex`) a regular expression matching
the ``sage.PAC.KAGE.all`` package names from which we do not want to import.
- ``verbose`` -- a parameter which if used will issue print statements when interesting examples are found
Expand Down Expand Up @@ -443,8 +418,21 @@ def print_log_messages():
# ******************************************************** EXECUTES MAIN FUNCTION **********************************************************************
# this executes the main function in this file which writes over all import statements matching regex in files in specified location matching fileRegex:
if __name__ == "__main__":
# Parse the arguments
args = parse_arguments()
# Create argument parser
parser = argparse.ArgumentParser()
# Optional arguments
parser.add_argument(
"location",
metavar='files or directories',
nargs='*',
help=("Names of source directories or source files. "
"If none given, walks through all files in src/sage."),
type=str)
parser.add_argument(
"-v", "--verbose",
help="Increase output verbosity. Shows locations of any unusual cases of import statements and the corresponding changes.",
action="store_true") # Parse arguments
args = parser.parse_args()
verbosity = args.verbose
# Declare regular expressions
file_regex = r'.*[.](py|pyx|pxi)$'
Expand Down

0 comments on commit fe617e9

Please sign in to comment.