forked from ESMCI/cime
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jgfouca/add_code_checking' (PR #267)
Add a new tool that checks that all python library source files are 100% clean for a certain configuration of pylint. Fix all pylint errors discovered by the tool. Add a test to run this tool every night. Test suite: scripts_regression_tests Test baseline: Test namelist changes: Test status: bit for bit Fixes: [CIME Github issue #] User interface changes?: Code review: @jedwards4b * jgfouca/add_code_checking: Fix a couple remaining pylint issues Made code_checker parallel, fix test name so it actually runs Fix remaining test failures Bug fix All scripts passing Add code checker test. Remove refactor disablings from scripts_regression_tests.py Progress. Tool added. build.py 100% Conflicts: utils/python/CIME/case_setup.py
- Loading branch information
Showing
71 changed files
with
584 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Ensure that all CIME python files are free of errors | ||
and follow the PEP8 standard. | ||
""" | ||
|
||
from standard_script_setup import * | ||
|
||
from CIME.utils import run_cmd, run_cmd_no_fail, expect, get_python_libs_root | ||
|
||
import argparse, sys, os, doctest | ||
from multiprocessing.dummy import Pool as ThreadPool | ||
|
||
############################################################################### | ||
def parse_command_line(args, description): | ||
############################################################################### | ||
parser = argparse.ArgumentParser( | ||
usage="""\n%s [--verbose] | ||
OR | ||
%s --help | ||
OR | ||
%s --test | ||
\033[1mEXAMPLES:\033[0m | ||
\033[1;32m# Check code \033[0m | ||
> %s | ||
""" % ((os.path.basename(args[0]), ) * 4), | ||
|
||
description=description, | ||
|
||
formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
) | ||
|
||
CIME.utils.setup_standard_logging_options(parser) | ||
|
||
parser.add_argument("--dir", default=get_python_libs_root(), | ||
help="The root directory containing python files to check.") | ||
|
||
parser.add_argument("-j", "--num-procs", type=int, default=8, | ||
help="The number of files to check in parallel") | ||
|
||
args = parser.parse_args(args[1:]) | ||
|
||
CIME.utils.handle_standard_logging_options(args) | ||
|
||
return args.dir, args.num_procs | ||
|
||
############################################################################### | ||
def run_pylint(on_file): | ||
############################################################################### | ||
cmd = "pylint --disable I,C,R,logging-not-lazy,wildcard-import,unused-wildcard-import,fixme,broad-except,bare-except,eval-used,exec-used,global-statement %s" % on_file | ||
stat = run_cmd(cmd)[0] | ||
if stat != 0: | ||
sys.stdout.write("File %s has pylint problems, please fix\n Use command: %s\n" % (on_file, cmd)) | ||
return False | ||
else: | ||
sys.stdout.write("File %s has no pylint problems\n" % on_file) | ||
return True | ||
|
||
############################################################################### | ||
def check_code(dir_to_check, num_procs): | ||
############################################################################### | ||
""" | ||
Check all python files in the given directory | ||
Returns True if all files had no problems | ||
""" | ||
# Pylint won't work right if the imports within the checked files fails | ||
if "PYTHONPATH" in os.environ: | ||
os.environ["PYTHONPATH"] += dir_to_check | ||
else: | ||
os.environ["PYTHONPATH"] = dir_to_check | ||
|
||
# Get list of files to check | ||
files_to_check = run_cmd_no_fail('find %s -name "*.py"' % dir_to_check).splitlines() | ||
pool = ThreadPool(num_procs) | ||
results = pool.map(run_pylint, files_to_check) | ||
|
||
return False not in results | ||
|
||
############################################################################### | ||
def _main_func(description): | ||
############################################################################### | ||
if ("--test" in sys.argv): | ||
test_results = doctest.testmod(verbose=True) | ||
sys.exit(1 if test_results.failed > 0 else 0) | ||
|
||
dir_to_check, num_procs = parse_command_line(sys.argv, description) | ||
|
||
sys.exit(0 if check_code(dir_to_check, num_procs) else 1) | ||
|
||
############################################################################### | ||
|
||
if (__name__ == "__main__"): | ||
_main_func(__doc__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.