def main(): parser = OptionParser() parser.add_option( "--verbose", action="store_true", dest="verbose", default=False, help="""Default is %default.""", ) parser.add_option( "--from-commit", action="store_true", dest="from_commit", default=False, help= """From commit hook, do not descend into directories. Default is %default.""", ) parser.add_option( "--abort-on-parsing-error", action="store_true", dest="abort", default=False, help="""Stop if an error occurs, or continue. Default is %default.""", ) options, positional_args = parser.parse_args() if options.from_commit: assert not positional_args for desc in getStagedFileChangeDesc(): autoformat(desc["src_path"], git_stage=desc, abort=options.abort) else: if not positional_args: positional_args = [ "bin", "nuitka", "setup.py", "tests/*/run_all.py" ] my_print("Working on:", positional_args) positional_args = sum( (resolveShellPatternToFilenames(positional_arg) for positional_arg in positional_args), [], ) goHome() filenames = list( scanTargets( positional_args, (".py", ".scons", ".rst", ".txt", ".j2", ".md", ".c", ".h"), )) if not filenames: sys.exit("No files found.") for filename in filenames: autoformat(filename, git_stage=False, abort=options.abort)
def main(): parser = OptionParser() parser.add_option( "--verbose", action="store_true", dest="verbose", default=False, help="""Default is %default.""", ) parser.add_option( "--from-commit", action="store_true", dest="from_commit", default=False, help="""From commit hook, do not descend into directories. Default is %default.""", ) parser.add_option( "--abort-on-parsing-error", action="store_true", dest="abort", default=False, help="""Stop if an error occurs, or continue. Default is %default.""", ) options, positional_args = parser.parse_args() if options.from_commit: assert not positional_args for desc in getStagedFileChangeDesc(): autoformat(desc["src_path"], git_stage=desc, abort=options.abort) else: if not positional_args: positional_args = [ "bin", "nuitka", # "tests/*/run_all.py" ] my_print("Working on:", positional_args) positional_args = sum( ( resolveShellPatternToFilenames(positional_arg) for positional_arg in positional_args ), [], ) goHome() filenames = list( scanTargets(positional_args, (".py", ".scons", ".rst", ".txt")) ) if not filenames: sys.exit("No files found.") for filename in filenames: autoformat(filename, git_stage=False, abort=options.abort)
def main(): parser = OptionParser() parser.add_option( "--verbose", action="store_true", dest="verbose", default=False, help="""Default is %default.""", ) parser.add_option( "--from-commit", action="store_true", dest="from_commit", default=False, help="""From commit hook, do not descend into directories. Default is %default.""", ) parser.add_option( "--check-only", action="store_true", dest="check_only", default=False, help="""For CI testing, check if it's properly formatted. Default is %default.""", ) parser.add_option( "--no-progressbar", action="store_false", dest="progress_bar", default=True, help="""Disable progress bar outputs (if tqdm is installed). Defaults to off.""", ) options, positional_args = parser.parse_args() if options.from_commit: assert not positional_args for desc in getStagedFileChangeDesc(): autoformat(desc["src_path"], git_stage=desc) else: if not positional_args: positional_args = ["bin", "nuitka", "setup.py", "tests/*/run_all.py"] my_print("Working on:", positional_args) positional_args = sum( ( resolveShellPatternToFilenames(positional_arg) for positional_arg in positional_args ), [], ) filenames = list( scanTargets( positional_args, suffixes=(".py", ".scons", ".rst", ".txt", ".j2", ".md", ".c", ".h"), ) ) if not filenames: tools_logger.sysexit("No files found.") result = 0 if options.progress_bar: enableProgressBar() for filename in wrapWithProgressBar( filenames, stage="Autoformat", unit="files" ): if autoformat(filename, git_stage=False, check_only=options.check_only): result += 1 if options.check_only and result > 0: tools_logger.sysexit( """Error, bin/autoformat-nuitka-source would make changes to %d files, \ make sure to have commit hook installed.""" % result ) elif result > 0: tools_logger.info("autoformat: Changes to formatting of %d files" % result) else: tools_logger.info("autoformat: No files needed formatting changes.")