prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Clean up python in unit_testing
  Clean up code in unit_testing/python
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `scripts/lib/CIME/code_checker.py`
  Content:
  ```
  1 """
  2 Libraries for checking python code with pylint
  3 """
  4 
  5 from CIME.XML.standard_module_setup import *
  6 
  7 from CIME.utils import run_cmd, run_cmd_no_fail, expect, get_cime_root, is_python_executable
  8 
  9 from multiprocessing.dummy import Pool as ThreadPool
  10 from distutils.spawn import find_executable
  11 
  12 logger = logging.getLogger(__name__)
  13 
  14 ###############################################################################
  15 def _run_pylint(on_file, interactive):
  16 ###############################################################################
  17     pylint = find_executable("pylint")
  18 
  19     cmd_options = " --disable=I,C,R,logging-not-lazy,wildcard-import,unused-wildcard-import,fixme,broad-except,bare-except,eval-used,exec-used,global-statement"
  20     cimeroot = get_cime_root()
  21 
  22     if "scripts/Tools" in on_file:
  23         cmd_options +=",relative-import"
  24 
  25     # add init-hook option
  26     cmd_options += " --init-hook='sys.path.extend((\"%s\",\"%s\",\"%s\"))'"%\
  27         (os.path.join(cimeroot,"scripts","lib"),
  28          os.path.join(cimeroot,"scripts","Tools"),
  29          os.path.join(cimeroot,"tools","unit_testing","python"))
  30 
  31     cmd = "%s %s %s" % (pylint, cmd_options, on_file)
  32     logger.debug("pylint command is %s"%cmd)
  33     stat, out, err = run_cmd(cmd, verbose=False, from_dir=cimeroot)
  34     if stat != 0:
  35         if interactive:
  36             logger.info("File %s has pylint problems, please fix\n    Use command: %s" % (on_file, cmd))
  37             logger.info(out + "\n" + err)
  38         return (on_file, out + "\n" + err)
  39     else:
  40         if interactive:
  41             logger.info("File %s has no pylint problems" % on_file)
  42         return (on_file, "")
  43 
  44 ###############################################################################
  45 def _matches(file_path, file_ends):
  46 ###############################################################################
  47     for file_end in file_ends:
  48         if file_path.endswith(file_end):
  49             return True
  50 
  51     return False
  52 
  53 ###############################################################################
  54 def _should_pylint_skip(filepath):
  55 ###############################################################################
  56     # TODO - get rid of this
  57     list_of_directories_to_ignore = ("xmlconvertors", "pointclm", "point_clm", "tools", "machines", "apidocs")
  58     for dir_to_skip in list_of_directories_to_ignore:
  59         if dir_to_skip in filepath:
  60             return True
  61 
  62     return False
  63 
  64 ###############################################################################
  65 def get_all_checkable_files():
  66 ###############################################################################
  67     cimeroot = get_cime_root()
  68     all_git_files = run_cmd_no_fail("git ls-files", from_dir=cimeroot, verbose=False).splitlines()
  69 
  70     files_to_test = [item for item in all_git_files
  71                      if ((item.endswith(".py") or is_python_executable(os.path.join(cimeroot, item))) and not _should_pylint_skip(item))]
  72     return files_to_test
  73 
  74 ###############################################################################
  75 def check_code(files, num_procs=10, interactive=False):
  76 ###############################################################################
  77     """
  78     Check all python files in the given directory
  79 
  80     Returns True if all files had no problems
  81     """
  82     # Get list of files to check, we look to see if user-provided file argument
  83     # is a valid file, if not, we search the repo for a file with similar name.
  84     repo_files = run_cmd_no_fail('git ls-files --full-name %s' % get_cime_root(), verbose=False).splitlines()
  85     files_to_check = []
  86     if files:
  87         for filearg in files:
  88             if os.path.exists(filearg):
  89                 files_to_check.append(os.path.abspath(filearg))
  90             else:
  91                 found = False
  92                 for repo_file in repo_files:
  93                     if repo_file.endswith(filearg):
  94                         found = True
  95                         files_to_check.append(repo_file) # could have multiple matches
  96 
  97                 if not found:
  98                     logger.warning("Could not find file matching argument '%s'" % filearg)
  99     else:
  100         # Check every python file
  101         files_to_check = get_all_checkable_files()
  102 
  103     expect(len(files_to_check) > 0, "No matching files found")
  104 
  105     # No point in using more threads than files
  106     if len(files_to_check) < num_procs:
  107         num_procs = len(files_to_check)
  108 
  109     pool = ThreadPool(num_procs)
  110     results = pool.map(lambda x : _run_pylint(x, interactive), files_to_check)
  111     pool.close()
  112     pool.join()
  113     return dict(results)
  114
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/scripts/lib/CIME/code_checker.py b/scripts/lib/CIME/code_checker.py
  --- a/scripts/lib/CIME/code_checker.py
  +++ b/scripts/lib/CIME/code_checker.py
  @@ -26,7 +26,7 @@
       cmd_options += " --init-hook='sys.path.extend((\"%s\",\"%s\",\"%s\"))'"%\
           (os.path.join(cimeroot,"scripts","lib"),
            os.path.join(cimeroot,"scripts","Tools"),
  -         os.path.join(cimeroot,"tools","unit_testing","python"))
  +         os.path.join(cimeroot,"scripts","fortran_unit_testing","python"))
   
       cmd = "%s %s %s" % (pylint, cmd_options, on_file)
       logger.debug("pylint command is %s"%cmd)
  
verification_info: {"golden_diff": "diff --git a/scripts/lib/CIME/code_checker.py b/scripts/lib/CIME/code_checker.py\n--- a/scripts/lib/CIME/code_checker.py\n+++ b/scripts/lib/CIME/code_checker.py\n@@ -26,7 +26,7 @@\n     cmd_options += \" --init-hook='sys.path.extend((\\\"%s\\\",\\\"%s\\\",\\\"%s\\\"))'\"%\\\n         (os.path.join(cimeroot,\"scripts\",\"lib\"),\n          os.path.join(cimeroot,\"scripts\",\"Tools\"),\n-         os.path.join(cimeroot,\"tools\",\"unit_testing\",\"python\"))\n+         os.path.join(cimeroot,\"scripts\",\"fortran_unit_testing\",\"python\"))\n \n     cmd = \"%s %s %s\" % (pylint, cmd_options, on_file)\n     logger.debug(\"pylint command is %s\"%cmd)\n", "issue": "Clean up python in unit_testing\nClean up code in unit_testing/python\n", "before_files": [{"content": "\"\"\"\nLibraries for checking python code with pylint\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\n\nfrom CIME.utils import run_cmd, run_cmd_no_fail, expect, get_cime_root, is_python_executable\n\nfrom multiprocessing.dummy import Pool as ThreadPool\nfrom distutils.spawn import find_executable\n\nlogger = logging.getLogger(__name__)\n\n###############################################################################\ndef _run_pylint(on_file, interactive):\n###############################################################################\n    pylint = find_executable(\"pylint\")\n\n    cmd_options = \" --disable=I,C,R,logging-not-lazy,wildcard-import,unused-wildcard-import,fixme,broad-except,bare-except,eval-used,exec-used,global-statement\"\n    cimeroot = get_cime_root()\n\n    if \"scripts/Tools\" in on_file:\n        cmd_options +=\",relative-import\"\n\n    # add init-hook option\n    cmd_options += \" --init-hook='sys.path.extend((\\\"%s\\\",\\\"%s\\\",\\\"%s\\\"))'\"%\\\n        (os.path.join(cimeroot,\"scripts\",\"lib\"),\n         os.path.join(cimeroot,\"scripts\",\"Tools\"),\n         os.path.join(cimeroot,\"tools\",\"unit_testing\",\"python\"))\n\n    cmd = \"%s %s %s\" % (pylint, cmd_options, on_file)\n    logger.debug(\"pylint command is %s\"%cmd)\n    stat, out, err = run_cmd(cmd, verbose=False, from_dir=cimeroot)\n    if stat != 0:\n        if interactive:\n            logger.info(\"File %s has pylint problems, please fix\\n    Use command: %s\" % (on_file, cmd))\n            logger.info(out + \"\\n\" + err)\n        return (on_file, out + \"\\n\" + err)\n    else:\n        if interactive:\n            logger.info(\"File %s has no pylint problems\" % on_file)\n        return (on_file, \"\")\n\n###############################################################################\ndef _matches(file_path, file_ends):\n###############################################################################\n    for file_end in file_ends:\n        if file_path.endswith(file_end):\n            return True\n\n    return False\n\n###############################################################################\ndef _should_pylint_skip(filepath):\n###############################################################################\n    # TODO - get rid of this\n    list_of_directories_to_ignore = (\"xmlconvertors\", \"pointclm\", \"point_clm\", \"tools\", \"machines\", \"apidocs\")\n    for dir_to_skip in list_of_directories_to_ignore:\n        if dir_to_skip in filepath:\n            return True\n\n    return False\n\n###############################################################################\ndef get_all_checkable_files():\n###############################################################################\n    cimeroot = get_cime_root()\n    all_git_files = run_cmd_no_fail(\"git ls-files\", from_dir=cimeroot, verbose=False).splitlines()\n\n    files_to_test = [item for item in all_git_files\n                     if ((item.endswith(\".py\") or is_python_executable(os.path.join(cimeroot, item))) and not _should_pylint_skip(item))]\n    return files_to_test\n\n###############################################################################\ndef check_code(files, num_procs=10, interactive=False):\n###############################################################################\n    \"\"\"\n    Check all python files in the given directory\n\n    Returns True if all files had no problems\n    \"\"\"\n    # Get list of files to check, we look to see if user-provided file argument\n    # is a valid file, if not, we search the repo for a file with similar name.\n    repo_files = run_cmd_no_fail('git ls-files --full-name %s' % get_cime_root(), verbose=False).splitlines()\n    files_to_check = []\n    if files:\n        for filearg in files:\n            if os.path.exists(filearg):\n                files_to_check.append(os.path.abspath(filearg))\n            else:\n                found = False\n                for repo_file in repo_files:\n                    if repo_file.endswith(filearg):\n                        found = True\n                        files_to_check.append(repo_file) # could have multiple matches\n\n                if not found:\n                    logger.warning(\"Could not find file matching argument '%s'\" % filearg)\n    else:\n        # Check every python file\n        files_to_check = get_all_checkable_files()\n\n    expect(len(files_to_check) > 0, \"No matching files found\")\n\n    # No point in using more threads than files\n    if len(files_to_check) < num_procs:\n        num_procs = len(files_to_check)\n\n    pool = ThreadPool(num_procs)\n    results = pool.map(lambda x : _run_pylint(x, interactive), files_to_check)\n    pool.close()\n    pool.join()\n    return dict(results)\n", "path": "scripts/lib/CIME/code_checker.py"}], "after_files": [{"content": "\"\"\"\nLibraries for checking python code with pylint\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\n\nfrom CIME.utils import run_cmd, run_cmd_no_fail, expect, get_cime_root, is_python_executable\n\nfrom multiprocessing.dummy import Pool as ThreadPool\nfrom distutils.spawn import find_executable\n\nlogger = logging.getLogger(__name__)\n\n###############################################################################\ndef _run_pylint(on_file, interactive):\n###############################################################################\n    pylint = find_executable(\"pylint\")\n\n    cmd_options = \" --disable=I,C,R,logging-not-lazy,wildcard-import,unused-wildcard-import,fixme,broad-except,bare-except,eval-used,exec-used,global-statement\"\n    cimeroot = get_cime_root()\n\n    if \"scripts/Tools\" in on_file:\n        cmd_options +=\",relative-import\"\n\n    # add init-hook option\n    cmd_options += \" --init-hook='sys.path.extend((\\\"%s\\\",\\\"%s\\\",\\\"%s\\\"))'\"%\\\n        (os.path.join(cimeroot,\"scripts\",\"lib\"),\n         os.path.join(cimeroot,\"scripts\",\"Tools\"),\n         os.path.join(cimeroot,\"scripts\",\"fortran_unit_testing\",\"python\"))\n\n    cmd = \"%s %s %s\" % (pylint, cmd_options, on_file)\n    logger.debug(\"pylint command is %s\"%cmd)\n    stat, out, err = run_cmd(cmd, verbose=False, from_dir=cimeroot)\n    if stat != 0:\n        if interactive:\n            logger.info(\"File %s has pylint problems, please fix\\n    Use command: %s\" % (on_file, cmd))\n            logger.info(out + \"\\n\" + err)\n        return (on_file, out + \"\\n\" + err)\n    else:\n        if interactive:\n            logger.info(\"File %s has no pylint problems\" % on_file)\n        return (on_file, \"\")\n\n###############################################################################\ndef _matches(file_path, file_ends):\n###############################################################################\n    for file_end in file_ends:\n        if file_path.endswith(file_end):\n            return True\n\n    return False\n\n###############################################################################\ndef _should_pylint_skip(filepath):\n###############################################################################\n    # TODO - get rid of this\n    list_of_directories_to_ignore = (\"xmlconvertors\", \"pointclm\", \"point_clm\", \"tools\", \"machines\", \"apidocs\")\n    for dir_to_skip in list_of_directories_to_ignore:\n        if dir_to_skip in filepath:\n            return True\n\n    return False\n\n###############################################################################\ndef get_all_checkable_files():\n###############################################################################\n    cimeroot = get_cime_root()\n    all_git_files = run_cmd_no_fail(\"git ls-files\", from_dir=cimeroot, verbose=False).splitlines()\n\n    files_to_test = [item for item in all_git_files\n                     if ((item.endswith(\".py\") or is_python_executable(os.path.join(cimeroot, item))) and not _should_pylint_skip(item))]\n    return files_to_test\n\n###############################################################################\ndef check_code(files, num_procs=10, interactive=False):\n###############################################################################\n    \"\"\"\n    Check all python files in the given directory\n\n    Returns True if all files had no problems\n    \"\"\"\n    # Get list of files to check, we look to see if user-provided file argument\n    # is a valid file, if not, we search the repo for a file with similar name.\n    repo_files = run_cmd_no_fail('git ls-files --full-name %s' % get_cime_root(), verbose=False).splitlines()\n    files_to_check = []\n    if files:\n        for filearg in files:\n            if os.path.exists(filearg):\n                files_to_check.append(os.path.abspath(filearg))\n            else:\n                found = False\n                for repo_file in repo_files:\n                    if repo_file.endswith(filearg):\n                        found = True\n                        files_to_check.append(repo_file) # could have multiple matches\n\n                if not found:\n                    logger.warning(\"Could not find file matching argument '%s'\" % filearg)\n    else:\n        # Check every python file\n        files_to_check = get_all_checkable_files()\n\n    expect(len(files_to_check) > 0, \"No matching files found\")\n\n    # No point in using more threads than files\n    if len(files_to_check) < num_procs:\n        num_procs = len(files_to_check)\n\n    pool = ThreadPool(num_procs)\n    results = pool.map(lambda x : _run_pylint(x, interactive), files_to_check)\n    pool.close()\n    pool.join()\n    return dict(results)\n", "path": "scripts/lib/CIME/code_checker.py"}]}