Repository: ESMCI/cime

Issue:
MCT cases fail with "argument of type 'NoneType' is not iterable"
With latest cime master, a basic create_test with an mct case (`./create_test ERP_Ln9.f45_g37_rx1.A.cheyenne_intel`) is failing with this traceback:

```
        Traceback (most recent call last):
          File "./case.build", line 165, in <module>
            _main_func(__doc__)
          File "./case.build", line 155, in _main_func
            success = test.build(sharedlib_only=sharedlib_only, model_only=model_only, old_build=use_old, ninja=ninja, dry_run=dry_run)
          File "/glade/work/sacks/cime/scripts/Tools/../../scripts/lib/CIME/SystemTests/system_tests_common.py", line 93, in build
            model_only=(phase_name==MODEL_BUILD_PHASE))
          File "/glade/work/sacks/cime/scripts/Tools/../../scripts/lib/CIME/SystemTests/system_tests_compare_two.py", line 190, in build_phase
            self.build_indv(sharedlib_only=sharedlib_only, model_only=model_only)
          File "/glade/work/sacks/cime/scripts/Tools/../../scripts/lib/CIME/SystemTests/system_tests_common.py", line 131, in build_indv
            use_old=self._old_build, ninja=self._ninja, dry_run=self._dry_run)
          File "/glade/work/sacks/cime/scripts/Tools/../../scripts/lib/CIME/build.py", line 728, in case_build
            return run_and_log_case_status(functor, cb, caseroot=caseroot)
          File "/glade/work/sacks/cime/scripts/Tools/../../scripts/lib/CIME/utils.py", line 1768, in run_and_log_case_status
            rv = func()
          File "/glade/work/sacks/cime/scripts/Tools/../../scripts/lib/CIME/build.py", line 722, in <lambda>
            save_build_provenance, use_old, ninja, dry_run)
          File "/glade/work/sacks/cime/scripts/Tools/../../scripts/lib/CIME/build.py", line 669, in _case_build_impl
            cimeroot, libroot, lid, compiler, buildlist, comp_interface)
          File "/glade/work/sacks/cime/scripts/Tools/../../scripts/lib/CIME/build.py", line 358, in _build_libraries
            if comp_interface == "nuopc" and not cmeps_driver or not 'nems' in cmeps_driver:
        TypeError: argument of type 'NoneType' is not iterable
```

@jedwards4b did you mean to add parentheses in the line in question: i.e., instead of this:

```python
if comp_interface == "nuopc" and not cmeps_driver or not 'nems' in cmeps_driver:
```

did you possibly mean

```python
if comp_interface == "nuopc" and (not cmeps_driver or not 'nems' in cmeps_driver):
```

I haven't looked closely at the logic, but I think adding parentheses would fix the problem I ran into... but I don't know if that's actually the logic you intended.


Discussion:
My suggested change - i.e.,

```diff
diff --git a/scripts/lib/CIME/build.py b/scripts/lib/CIME/build.py
index 908306e48..e4ab38c42 100644
--- a/scripts/lib/CIME/build.py
+++ b/scripts/lib/CIME/build.py
@@ -355,7 +355,7 @@ def _build_libraries(case, exeroot, sharedpath, caseroot, cimeroot, libroot, lid
 
     # Build shared code of CDEPS nuopc data models
     cdeps_build_script = None
-    if comp_interface == "nuopc" and not cmeps_driver or not 'nems' in cmeps_driver:
+    if comp_interface == "nuopc" and (not cmeps_driver or not 'nems' in cmeps_driver):
         libs.append("CDEPS")
         cdeps_build_script = os.path.join(srcroot, "components", "cdeps", "cime_config", "buildlib")
 ```

does let my build proceed for an mct case, but again, I'm not sure if this is the correct logic.
Can we please ensure that tests are run with both mct and nuopc before the
next commit is done. I would propose an I compset in both cases at a
minimum.

On Mon, Aug 24, 2020 at 11:54 AM Bill Sacks <notifications@github.com>
wrote:

> My suggested change - i.e.,
>
> diff --git a/scripts/lib/CIME/build.py b/scripts/lib/CIME/build.py
> index 908306e48..e4ab38c42 100644--- a/scripts/lib/CIME/build.py+++ b/scripts/lib/CIME/build.py@@ -355,7 +355,7 @@ def _build_libraries(case, exeroot, sharedpath, caseroot, cimeroot, libroot, lid
>
>      # Build shared code of CDEPS nuopc data models
>      cdeps_build_script = None-    if comp_interface == "nuopc" and not cmeps_driver or not 'nems' in cmeps_driver:+    if comp_interface == "nuopc" and (not cmeps_driver or not 'nems' in cmeps_driver):
>          libs.append("CDEPS")
>          cdeps_build_script = os.path.join(srcroot, "components", "cdeps", "cime_config", "buildlib")
>
> does let my build proceed for an mct case, but again, I'm not sure if this
> is the correct logic.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/ESMCI/cime/issues/3684#issuecomment-679275787>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AB4XCE6BLHUMRJTP645ZFQLSCKSN3ANCNFSM4QJYFKAQ>
> .
>


-- 
Mariana Vertenstein
CESM Software Engineering Group Head
National Center for Atmospheric Research
Boulder, Colorado
Office 303-497-1349
Email: mvertens@ucar.edu


Resolving patch:
diff --git a/scripts/lib/CIME/build.py b/scripts/lib/CIME/build.py
--- a/scripts/lib/CIME/build.py
+++ b/scripts/lib/CIME/build.py
@@ -339,10 +339,10 @@ def _build_libraries(case, exeroot, sharedpath, caseroot, cimeroot, libroot, lid
             os.makedirs(shared_item)
 
     mpilib = case.get_value("MPILIB")
-    cmeps_driver = os.environ.get("UFS_DRIVER")
-    if cmeps_driver:
-        logger.info("UFS_DRIVER is set to {}".format(cmeps_driver))
-    if cmeps_driver and 'nems' in cmeps_driver:
+    ufs_driver = os.environ.get("UFS_DRIVER")
+    if ufs_driver:
+        logger.info("UFS_DRIVER is set to {}".format(ufs_driver))
+    if ufs_driver and ufs_driver == 'nems':
         libs = []
     else:
         libs = ["gptl", "mct", "pio", "csm_share"]
@@ -355,7 +355,7 @@ def _build_libraries(case, exeroot, sharedpath, caseroot, cimeroot, libroot, lid
 
     # Build shared code of CDEPS nuopc data models
     cdeps_build_script = None
-    if comp_interface == "nuopc" and not cmeps_driver or not 'nems' in cmeps_driver:
+    if comp_interface == "nuopc" and (not ufs_driver or ufs_driver != 'nems'):
         libs.append("CDEPS")
         cdeps_build_script = os.path.join(srcroot, "components", "cdeps", "cime_config", "buildlib")
 


Test patch: