Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not add empty user mods #1675

Merged
merged 4 commits into from
Jun 12, 2017
Merged

Do not add empty user mods #1675

merged 4 commits into from
Jun 12, 2017

Conversation

billsacks
Copy link
Member

Ignore empty COMP_USER_MODS values

If a component defined a COMPNAME_USER_MODS (e.g., CAM_USER_MODS) entry
in config_component.xml, but the value for the current case ends up
being blank, we were getting incorrect behavior: The expected behavior
is that no user mods directory would be included; the actual behavior
was that it tries to pull in user mods from
PRIMARY_COMPONENT/cime_config/usermods_dirs . This often will be
harmless, because that directory won't contain any user_nl files or
others (it typically just contains some subdirectories with the actual
user mods). But it's confusing, and it could give wrong behavior if that
directory happened to include any files that matched names that are
expected in a user_mods directory (e.g., user_nl files).

This PR fixes this behavior, so that if COMPNAME_USER_MODS evaluates to
an empty string, then we don't try to include it.

Test suite: scripts_regression_tests on yellowstone
Also, manual tests of create_newcase:

  • B1850 (no user_mods)
  • BHIST (picks up user_mods from CAM)
  • FHIST_DEV (picks up user_mods from CAM, the primary_component)

Test baseline: N/A
Test namelist changes: none
Test status: bit for bit

Fixes #1673

User interface changes?: none

Code review:

pylint 1.6.4 on yellowstone kept giving me errors like this:

E:1125,15: Instance of 'int' has no 'isspace' member (no-member)
E:1125,15: Instance of 'float' has no 'isspace' member (no-member)

I tried lots of things, and this EAFP approach is the one way I can
make pylint happy
@billsacks
Copy link
Member Author

cc @mvertens

is_space = comp_user_mods.isspace()
except AttributeError:
is_space = False
if is_space:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking is_space isn't necessary right now, but is necessary to avoid cryptic error messages if someone had something like <default_value> </default_value> (note the space)

if comp_user_mods is None or comp_user_mods == "":
return None
else:
try:
Copy link
Member Author

@billsacks billsacks Jun 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After much trial and error, this try/except block was the only way I could get pylint 1.6.4 (on yellowstone) to accept the use of isspace. Without it, pylint gave errors like this:

    E:1125,15: Instance of 'int' has no 'isspace' member (no-member)
    E:1125,15: Instance of 'float' has no 'isspace' member (no-member)

Returns None if no value was found, or if the value is an empty string.
"""
comp_user_mods = self.get_value("{}_USER_MODS".format(component.upper()))
if comp_user_mods is None or comp_user_mods == "":
Copy link
Member Author

@billsacks billsacks Jun 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally it seems like we'd have some shared handling of empty strings in some common place, but I'm not sure where this should go (e.g., one of the get_value routines somewhere in the inheritance chain?), and I didn't want to risk breaking things this late in the release cycle. So for now I'm just applying this special handling for this one case where I know we need it.

Returns None if no value was found, or if the value is an empty string.
"""
comp_user_mods = self.get_value("{}_USER_MODS".format(component.upper()))
#pylint: disable=no-member
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is cleaner than the exception code - do you agree?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely cleaner. But I was hesitant to bypass this pylint check, figuring that pylint might be seeing some real possibility for problems. In particular: If there is any possibility that comp_user_mods is not a string here, then this code will raise an exception. I'll defer to your understanding here: If you're confident that get_value will always return a string here, then I'm happy with your change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should always return a string and if it doesn't it should be an exception.

@jedwards4b jedwards4b merged commit 876b6fe into ESMCI:master Jun 12, 2017
@billsacks billsacks deleted the do_not_add_empty_user_mods branch June 13, 2017 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Top-level cime_config/usermods_dirs incorrectly added to list of all_user_mods
2 participants