We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove ESMF from driver code


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `utils/python/CIME/SystemTests/pfs.py`
Content:
```
1 """
2 CIME performance test  This class inherits from SystemTestsCommon
3 
4 20 days performance test, no restart files written
5 """
6 
7 from CIME.XML.standard_module_setup import *
8 from system_tests_common import SystemTestsCommon
9 
10 logger = logging.getLogger(__name__)
11 
12 class PFS(SystemTestsCommon):
13 
14     def __init__(self, case):
15         """
16         initialize an object interface to the PFS system test
17         """
18         SystemTestsCommon.__init__(self, case)
19 
20     def run(self):
21         self._case_set_value("STOP_OPTION", "ndays")
22         self._case.set_value("STOP_N", 20)
23         self._case.set_value("REST_OPTION","none")
24         self._case.set_value("CONTINUE_RUN", False)
25         self._case.flush()
26 
27         logger.info("doing an 20 day initial test, no restarts written")
28         return SystemTestsCommon._run(self)
29 
30     def report(self):
31         SystemTestsCommon.report(self)
32
```

Path: `utils/python/CIME/preview_namelists.py`
Content:
```
1 """
2 API for preview namelist
3 """
4 
5 from CIME.XML.standard_module_setup import *
6 from CIME.utils import expect, run_cmd
7 from CIME.XML.env_mach_specific import EnvMachSpecific
8 
9 import glob, shutil
10 logger = logging.getLogger(__name__)
11 
12 def preview_namelists(case, dryrun=False, casedir=None):
13     # refresh case xml files from object
14     case.flush()
15 
16     # Get data from XML
17     exeroot = case.get_value("EXEROOT")
18     libroot = case.get_value("LIBROOT")
19     incroot = case.get_value("INCROOT")
20     rundir = case.get_value("RUNDIR")
21     caseroot = case.get_value("CASEROOT")
22     casebuild = case.get_value("CASEBUILD")
23     testcase = case.get_value("TESTCASE")
24 
25     logger.debug("LID is: '%s'" % os.getenv("LID", ""))
26     logger.debug("caseroot is: '%s'" % caseroot)
27 
28     dryrun = True if (testcase == "SBN") else dryrun
29 
30     models = ["atm", "lnd", "ice", "ocn", "glc", "wav", "rof", "cpl"]
31     docdir = os.path.join(caseroot, "CaseDocs")
32 
33     if (dryrun):
34         # Only create rundir
35         try:
36             os.makedirs(rundir)
37         except OSError:
38             logger.warning("Not able to create $RUNDIR, trying a subdirectory of $CASEROOT")
39             rundir = os.path.join(caseroot, rundir)
40             try:
41                 os.makedirs(rundir)
42                 logger.info("Success! Setting RUNDIR=%s" % rundir)
43                 case.set_value("RUNDIR", rundir)
44             except OSError:
45                 expect(False, "Could not create rundir")
46 
47     else:
48 
49         # Load modules
50         env_module = case._get_env("mach_specific")
51         env_module.load_env_for_case(compiler=case.get_value("COMPILER"),
52                                      debug=case.get_value("DEBUG"),
53                                      mpilib=case.get_value("MPILIB"))
54 
55         # Make necessary directories
56         dirs_to_make = [os.path.join(exeroot, model, "obj") for model in models]
57         dirs_to_make.extend([exeroot, libroot, incroot, rundir, docdir])
58 
59         for dir_to_make in dirs_to_make:
60             if (not os.path.isdir(dir_to_make)):
61                 try:
62                     logger.debug("Making dir '%s'" % dir_to_make)
63                     os.makedirs(dir_to_make)
64                 except OSError as e:
65                     expect(False, "Could not make directory '%s', error: %s" % (dir_to_make, e))
66 
67     # Create namelists
68     for model in models:
69         model_str = "drv" if model == "cpl" else model
70         config_file = case.get_value("CONFIG_%s_FILE" % model_str.upper())
71         config_dir = os.path.dirname(config_file)
72         cmd = os.path.join(config_dir, "buildnml")
73         logger.info("Running %s"%cmd)
74         if (logger.level == logging.DEBUG):
75             run_cmd("PREVIEW_NML=1 %s %s" % (cmd, caseroot))
76         else:
77             run_cmd("%s %s" % (cmd, caseroot))
78     # refresh case xml object from file
79     case.read_xml(caseroot)
80     # Save namelists to docdir
81     if (not os.path.isdir(docdir)):
82         os.makedirs(docdir)
83         try:
84             with open(os.path.join(docdir, "README"), "w") as fd:
85                 fd.write(" CESM Resolved Namelist Files\n   For documentation only DO NOT MODIFY\n")
86         except (OSError, IOError) as e:
87             expect(False, "Failed to write %s/README: %s" % (docdir, e))
88 
89 
90     for cpglob in ["*_in_[0-9]*", "*modelio*", "*_in",
91                    "*streams*txt*", "*stxt", "*maps.rc", "*cism.config*"]:
92         for file_to_copy in glob.glob(os.path.join(rundir, cpglob)):
93             logger.debug("Copy file from '%s' to '%s'" % (file_to_copy, docdir))
94             shutil.copy2(file_to_copy, docdir)
95 
96     # Copy over chemistry mechanism docs if they exist
97     if (os.path.isdir(os.path.join(casebuild, "camconf"))):
98         for file_to_copy in glob.glob(os.path.join(casebuild, "camconf", "*chem_mech*")):
99             shutil.copy2(file_to_copy, docdir)
100
```
--- 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()

```

diff --git a/utils/python/CIME/SystemTests/pfs.py b/utils/python/CIME/SystemTests/pfs.py
--- a/utils/python/CIME/SystemTests/pfs.py
+++ b/utils/python/CIME/SystemTests/pfs.py
@@ -18,7 +18,7 @@
         SystemTestsCommon.__init__(self, case)
 
     def run(self):
-        self._case_set_value("STOP_OPTION", "ndays")
+        self._case.set_value("STOP_OPTION", "ndays")
         self._case.set_value("STOP_N", 20)
         self._case.set_value("REST_OPTION","none")
         self._case.set_value("CONTINUE_RUN", False)
diff --git a/utils/python/CIME/preview_namelists.py b/utils/python/CIME/preview_namelists.py
--- a/utils/python/CIME/preview_namelists.py
+++ b/utils/python/CIME/preview_namelists.py
@@ -72,9 +72,12 @@
         cmd = os.path.join(config_dir, "buildnml")
         logger.info("Running %s"%cmd)
         if (logger.level == logging.DEBUG):
-            run_cmd("PREVIEW_NML=1 %s %s" % (cmd, caseroot))
+            rc, out, err = run_cmd("PREVIEW_NML=1 %s %s" % (cmd, caseroot), ok_to_fail=True)
+            expect(rc==0,"Command %s failed rc=%d\nout=%s\nerr=%s"%(cmd,rc,out,err))
         else:
-            run_cmd("%s %s" % (cmd, caseroot))
+            rc, out, err = run_cmd("%s %s" % (cmd, caseroot), ok_to_fail=True)
+            expect(rc==0,"Command %s failed rc=%d\nout=%s\nerr=%s"%(cmd,rc,out,err))
+
     # refresh case xml object from file
     case.read_xml(caseroot)
     # Save namelists to docdir

{"golden_diff": "diff --git a/utils/python/CIME/SystemTests/pfs.py b/utils/python/CIME/SystemTests/pfs.py\n--- a/utils/python/CIME/SystemTests/pfs.py\n+++ b/utils/python/CIME/SystemTests/pfs.py\n@@ -18,7 +18,7 @@\n         SystemTestsCommon.__init__(self, case)\n \n     def run(self):\n-        self._case_set_value(\"STOP_OPTION\", \"ndays\")\n+        self._case.set_value(\"STOP_OPTION\", \"ndays\")\n         self._case.set_value(\"STOP_N\", 20)\n         self._case.set_value(\"REST_OPTION\",\"none\")\n         self._case.set_value(\"CONTINUE_RUN\", False)\ndiff --git a/utils/python/CIME/preview_namelists.py b/utils/python/CIME/preview_namelists.py\n--- a/utils/python/CIME/preview_namelists.py\n+++ b/utils/python/CIME/preview_namelists.py\n@@ -72,9 +72,12 @@\n         cmd = os.path.join(config_dir, \"buildnml\")\n         logger.info(\"Running %s\"%cmd)\n         if (logger.level == logging.DEBUG):\n-            run_cmd(\"PREVIEW_NML=1 %s %s\" % (cmd, caseroot))\n+            rc, out, err = run_cmd(\"PREVIEW_NML=1 %s %s\" % (cmd, caseroot), ok_to_fail=True)\n+            expect(rc==0,\"Command %s failed rc=%d\\nout=%s\\nerr=%s\"%(cmd,rc,out,err))\n         else:\n-            run_cmd(\"%s %s\" % (cmd, caseroot))\n+            rc, out, err = run_cmd(\"%s %s\" % (cmd, caseroot), ok_to_fail=True)\n+            expect(rc==0,\"Command %s failed rc=%d\\nout=%s\\nerr=%s\"%(cmd,rc,out,err))\n+\n     # refresh case xml object from file\n     case.read_xml(caseroot)\n     # Save namelists to docdir\n", "issue": "Remove ESMF from driver code\n\n", "before_files": [{"content": "\"\"\"\nCIME performance test  This class inherits from SystemTestsCommon\n\n20 days performance test, no restart files written\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\nfrom system_tests_common import SystemTestsCommon\n\nlogger = logging.getLogger(__name__)\n\nclass PFS(SystemTestsCommon):\n\n    def __init__(self, case):\n        \"\"\"\n        initialize an object interface to the PFS system test\n        \"\"\"\n        SystemTestsCommon.__init__(self, case)\n\n    def run(self):\n        self._case_set_value(\"STOP_OPTION\", \"ndays\")\n        self._case.set_value(\"STOP_N\", 20)\n        self._case.set_value(\"REST_OPTION\",\"none\")\n        self._case.set_value(\"CONTINUE_RUN\", False)\n        self._case.flush()\n\n        logger.info(\"doing an 20 day initial test, no restarts written\")\n        return SystemTestsCommon._run(self)\n\n    def report(self):\n        SystemTestsCommon.report(self)\n", "path": "utils/python/CIME/SystemTests/pfs.py"}, {"content": "\"\"\"\nAPI for preview namelist\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils import expect, run_cmd\nfrom CIME.XML.env_mach_specific import EnvMachSpecific\n\nimport glob, shutil\nlogger = logging.getLogger(__name__)\n\ndef preview_namelists(case, dryrun=False, casedir=None):\n    # refresh case xml files from object\n    case.flush()\n\n    # Get data from XML\n    exeroot = case.get_value(\"EXEROOT\")\n    libroot = case.get_value(\"LIBROOT\")\n    incroot = case.get_value(\"INCROOT\")\n    rundir = case.get_value(\"RUNDIR\")\n    caseroot = case.get_value(\"CASEROOT\")\n    casebuild = case.get_value(\"CASEBUILD\")\n    testcase = case.get_value(\"TESTCASE\")\n\n    logger.debug(\"LID is: '%s'\" % os.getenv(\"LID\", \"\"))\n    logger.debug(\"caseroot is: '%s'\" % caseroot)\n\n    dryrun = True if (testcase == \"SBN\") else dryrun\n\n    models = [\"atm\", \"lnd\", \"ice\", \"ocn\", \"glc\", \"wav\", \"rof\", \"cpl\"]\n    docdir = os.path.join(caseroot, \"CaseDocs\")\n\n    if (dryrun):\n        # Only create rundir\n        try:\n            os.makedirs(rundir)\n        except OSError:\n            logger.warning(\"Not able to create $RUNDIR, trying a subdirectory of $CASEROOT\")\n            rundir = os.path.join(caseroot, rundir)\n            try:\n                os.makedirs(rundir)\n                logger.info(\"Success! Setting RUNDIR=%s\" % rundir)\n                case.set_value(\"RUNDIR\", rundir)\n            except OSError:\n                expect(False, \"Could not create rundir\")\n\n    else:\n\n        # Load modules\n        env_module = case._get_env(\"mach_specific\")\n        env_module.load_env_for_case(compiler=case.get_value(\"COMPILER\"),\n                                     debug=case.get_value(\"DEBUG\"),\n                                     mpilib=case.get_value(\"MPILIB\"))\n\n        # Make necessary directories\n        dirs_to_make = [os.path.join(exeroot, model, \"obj\") for model in models]\n        dirs_to_make.extend([exeroot, libroot, incroot, rundir, docdir])\n\n        for dir_to_make in dirs_to_make:\n            if (not os.path.isdir(dir_to_make)):\n                try:\n                    logger.debug(\"Making dir '%s'\" % dir_to_make)\n                    os.makedirs(dir_to_make)\n                except OSError as e:\n                    expect(False, \"Could not make directory '%s', error: %s\" % (dir_to_make, e))\n\n    # Create namelists\n    for model in models:\n        model_str = \"drv\" if model == \"cpl\" else model\n        config_file = case.get_value(\"CONFIG_%s_FILE\" % model_str.upper())\n        config_dir = os.path.dirname(config_file)\n        cmd = os.path.join(config_dir, \"buildnml\")\n        logger.info(\"Running %s\"%cmd)\n        if (logger.level == logging.DEBUG):\n            run_cmd(\"PREVIEW_NML=1 %s %s\" % (cmd, caseroot))\n        else:\n            run_cmd(\"%s %s\" % (cmd, caseroot))\n    # refresh case xml object from file\n    case.read_xml(caseroot)\n    # Save namelists to docdir\n    if (not os.path.isdir(docdir)):\n        os.makedirs(docdir)\n        try:\n            with open(os.path.join(docdir, \"README\"), \"w\") as fd:\n                fd.write(\" CESM Resolved Namelist Files\\n   For documentation only DO NOT MODIFY\\n\")\n        except (OSError, IOError) as e:\n            expect(False, \"Failed to write %s/README: %s\" % (docdir, e))\n\n\n    for cpglob in [\"*_in_[0-9]*\", \"*modelio*\", \"*_in\",\n                   \"*streams*txt*\", \"*stxt\", \"*maps.rc\", \"*cism.config*\"]:\n        for file_to_copy in glob.glob(os.path.join(rundir, cpglob)):\n            logger.debug(\"Copy file from '%s' to '%s'\" % (file_to_copy, docdir))\n            shutil.copy2(file_to_copy, docdir)\n\n    # Copy over chemistry mechanism docs if they exist\n    if (os.path.isdir(os.path.join(casebuild, \"camconf\"))):\n        for file_to_copy in glob.glob(os.path.join(casebuild, \"camconf\", \"*chem_mech*\")):\n            shutil.copy2(file_to_copy, docdir)\n", "path": "utils/python/CIME/preview_namelists.py"}], "after_files": [{"content": "\"\"\"\nCIME performance test  This class inherits from SystemTestsCommon\n\n20 days performance test, no restart files written\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\nfrom system_tests_common import SystemTestsCommon\n\nlogger = logging.getLogger(__name__)\n\nclass PFS(SystemTestsCommon):\n\n    def __init__(self, case):\n        \"\"\"\n        initialize an object interface to the PFS system test\n        \"\"\"\n        SystemTestsCommon.__init__(self, case)\n\n    def run(self):\n        self._case.set_value(\"STOP_OPTION\", \"ndays\")\n        self._case.set_value(\"STOP_N\", 20)\n        self._case.set_value(\"REST_OPTION\",\"none\")\n        self._case.set_value(\"CONTINUE_RUN\", False)\n        self._case.flush()\n\n        logger.info(\"doing an 20 day initial test, no restarts written\")\n        return SystemTestsCommon._run(self)\n\n    def report(self):\n        SystemTestsCommon.report(self)\n", "path": "utils/python/CIME/SystemTests/pfs.py"}, {"content": "\"\"\"\nAPI for preview namelist\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils import expect, run_cmd\nfrom CIME.XML.env_mach_specific import EnvMachSpecific\n\nimport glob, shutil\nlogger = logging.getLogger(__name__)\n\ndef preview_namelists(case, dryrun=False, casedir=None):\n    # refresh case xml files from object\n    case.flush()\n\n    # Get data from XML\n    exeroot = case.get_value(\"EXEROOT\")\n    libroot = case.get_value(\"LIBROOT\")\n    incroot = case.get_value(\"INCROOT\")\n    rundir = case.get_value(\"RUNDIR\")\n    caseroot = case.get_value(\"CASEROOT\")\n    casebuild = case.get_value(\"CASEBUILD\")\n    testcase = case.get_value(\"TESTCASE\")\n\n    logger.debug(\"LID is: '%s'\" % os.getenv(\"LID\", \"\"))\n    logger.debug(\"caseroot is: '%s'\" % caseroot)\n\n    dryrun = True if (testcase == \"SBN\") else dryrun\n\n    models = [\"atm\", \"lnd\", \"ice\", \"ocn\", \"glc\", \"wav\", \"rof\", \"cpl\"]\n    docdir = os.path.join(caseroot, \"CaseDocs\")\n\n    if (dryrun):\n        # Only create rundir\n        try:\n            os.makedirs(rundir)\n        except OSError:\n            logger.warning(\"Not able to create $RUNDIR, trying a subdirectory of $CASEROOT\")\n            rundir = os.path.join(caseroot, rundir)\n            try:\n                os.makedirs(rundir)\n                logger.info(\"Success! Setting RUNDIR=%s\" % rundir)\n                case.set_value(\"RUNDIR\", rundir)\n            except OSError:\n                expect(False, \"Could not create rundir\")\n\n    else:\n\n        # Load modules\n        env_module = case._get_env(\"mach_specific\")\n        env_module.load_env_for_case(compiler=case.get_value(\"COMPILER\"),\n                                     debug=case.get_value(\"DEBUG\"),\n                                     mpilib=case.get_value(\"MPILIB\"))\n\n        # Make necessary directories\n        dirs_to_make = [os.path.join(exeroot, model, \"obj\") for model in models]\n        dirs_to_make.extend([exeroot, libroot, incroot, rundir, docdir])\n\n        for dir_to_make in dirs_to_make:\n            if (not os.path.isdir(dir_to_make)):\n                try:\n                    logger.debug(\"Making dir '%s'\" % dir_to_make)\n                    os.makedirs(dir_to_make)\n                except OSError as e:\n                    expect(False, \"Could not make directory '%s', error: %s\" % (dir_to_make, e))\n\n    # Create namelists\n    for model in models:\n        model_str = \"drv\" if model == \"cpl\" else model\n        config_file = case.get_value(\"CONFIG_%s_FILE\" % model_str.upper())\n        config_dir = os.path.dirname(config_file)\n        cmd = os.path.join(config_dir, \"buildnml\")\n        logger.info(\"Running %s\"%cmd)\n        if (logger.level == logging.DEBUG):\n            rc, out, err = run_cmd(\"PREVIEW_NML=1 %s %s\" % (cmd, caseroot), ok_to_fail=True)\n            expect(rc==0,\"Command %s failed rc=%d\\nout=%s\\nerr=%s\"%(cmd,rc,out,err))\n        else:\n            rc, out, err = run_cmd(\"%s %s\" % (cmd, caseroot), ok_to_fail=True)\n            expect(rc==0,\"Command %s failed rc=%d\\nout=%s\\nerr=%s\"%(cmd,rc,out,err))\n\n    # refresh case xml object from file\n    case.read_xml(caseroot)\n    # Save namelists to docdir\n    if (not os.path.isdir(docdir)):\n        os.makedirs(docdir)\n        try:\n            with open(os.path.join(docdir, \"README\"), \"w\") as fd:\n                fd.write(\" CESM Resolved Namelist Files\\n   For documentation only DO NOT MODIFY\\n\")\n        except (OSError, IOError) as e:\n            expect(False, \"Failed to write %s/README: %s\" % (docdir, e))\n\n\n    for cpglob in [\"*_in_[0-9]*\", \"*modelio*\", \"*_in\",\n                   \"*streams*txt*\", \"*stxt\", \"*maps.rc\", \"*cism.config*\"]:\n        for file_to_copy in glob.glob(os.path.join(rundir, cpglob)):\n            logger.debug(\"Copy file from '%s' to '%s'\" % (file_to_copy, docdir))\n            shutil.copy2(file_to_copy, docdir)\n\n    # Copy over chemistry mechanism docs if they exist\n    if (os.path.isdir(os.path.join(casebuild, \"camconf\"))):\n        for file_to_copy in glob.glob(os.path.join(casebuild, \"camconf\", \"*chem_mech*\")):\n            shutil.copy2(file_to_copy, docdir)\n", "path": "utils/python/CIME/preview_namelists.py"}]}