-
Notifications
You must be signed in to change notification settings - Fork 52
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
Switch from getlist to getExpression in config parser #50
Conversation
@pwolfram, this is an enhancement I need in the config parser before getting to work on a solution for #20. It seemed to be best if it got its own PR. With the change, I am using The new approach isn't completely backwards compatible with the old I'm not that worried about the fact that config files will have to be changed to support this update. This is because I anticipate other changes before we merge @pwolfram and @milenaveneziani both, let me know if you have concerns about having to update config files to support this new syntax. |
TestingI ran the alpha7 test I have been using for testing (see #47) and verified that the plots are identical to those produced with |
@pwolfram, once you are happy with this PR, I will squash the commits to keep things cleaner. |
@pwolfram and @milenaveneziani , the solution I'm working on in #52 now does not rely on this capability. Nevertheless, as long as you agree it is useful and the fact that config files will need to be updated, I would like to go forward with this PR. |
@pwolfram, I just added unit testing for This should make the PR easier to review and is more in keeping with the testing approach we want to be moving toward throughout this repo. |
1c1e7bf
to
c702f8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xylar, it appears that at the configuration file stage we are now making assumptions related to integers vs floats in things like lists, tuples, dicts etc via config.getExpression
. I don't have a problem with this but it could potential cause a strange bug in the future if we aren't careful about this issue. Do we need to have some type of flag to explicitly specify the type? I'm not sure we do but this is one of the downsides to using a language like python (i.e., no explicit typing).
Feel free to ignore Not a Big Deal (NBD) comments for expediency.
def test_read_config(self): | ||
self.setup_config() | ||
|
||
# check config.get(...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NBD: probably don't need a comment like this that states essentially the command of the next line of code. This is true of all comments in this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this test!
Last Modified: 12/03/2016 | ||
""" | ||
expressionString = self.get(section, option) | ||
return ast.literal_eval(expressionString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xylar, very nice!!! This removes a ton of code and is a really clean solution.
listType = type(default[0]) | ||
|
||
return self.getlist(section, option, listType) | ||
elif isinstance(default, (list, tuple, dict)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Yes, that had occurred to me, too.
I'm open to this idea. I would be easy to explicitly type each element (or each value). The default should be leaving everything alone, since we want to support lists of heterogeneous type. I'll push something soon. |
@xylar, I would prefer we don't change this PR. At this point I think a new PR would be better because I'd like to get all the PRs merged in batch as we discussed earlier, is that ok with you? |
Oops, too late. I can revert my last commit. Would you like me to do that? |
No worries! I can easily roll back my merge and thankfully wasn't fully in the testing loop yet. This is probably cleaner anyway because of the fast turn-arounds. |
473db9a
to
c702f8a
Compare
@xylar, I messed this up again similar to what happened with a bad rebase. I accidentally didn't have commit |
@pwolfram, these things happen... |
This will support more general python data structures, such as
dictionaries, tuples, etc. It will also support lists of lists,
which will be useful for later work mapping variable names as they
change between MPAS versions.
This changes the syntax supported for lists of strings: they must
now be in single or double quotes.
The function setlist has been removed, since lists and other data
structures can be converted to strings with str(dataStructure).
The default
config.analysis
and the 4 analysis scripts that usedgetlist
have been updated for the newgetExpression
syntax.