-
Notifications
You must be signed in to change notification settings - Fork 11
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
Clean up sys-param code that reads parameters #668
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
167ed95
refactor: remove abandoned sys_param defaults code
vtnate 450ade0
call get_param instead of get_defaults
vtnate c081ab0
remove another reference to sys-param defaults
vtnate c6b482b
another place to handle a lack of defaults from sys-params
vtnate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,62 +90,34 @@ def resolve_paths(self): | |
new_path = Path(filepath) / match.value | ||
parse(str(match.full_path)).update(self.param_template, new_path.as_posix()) | ||
|
||
# def resolve_defaults(self): | ||
# """This method will expand the default data blocks into all the subsequent custom sections. If the value is | ||
# specificed in the custom block then that will be used, otherwise the default value will be replaced""" | ||
# pass | ||
|
||
def get_default(self, jsonpath, default=None): | ||
"""Return either the default in the system parameter file, or the specified default. | ||
|
||
:param jsonpath: string, raw jsonpath to what parameter was being requested | ||
:param default: variant, default value | ||
:return: value | ||
""" | ||
schema_default = self.get_param(jsonpath, impute_default=False) | ||
return schema_default or default | ||
|
||
def get_param(self, jsonpath, data=None, default=None, impute_default=True): | ||
"""Return the parameter(s) from a jsonpath. If the default is not specified, then will attempt to read the | ||
default from the "default" section of the file. If there is no default there, then it will use the value | ||
specified as the argument. It is not recommended to use the argument default as those values will not be | ||
configurable. Argument-based defaults should be used sparingly. | ||
def get_param(self, jsonpath, data=None): | ||
"""Return the parameter(s) from a jsonpath. | ||
|
||
:param path: string, period delimited path of the data to retrieve | ||
:param data: dict, (optional) the data to parse | ||
:param default: variant, (optional) value to return if can't find the result | ||
:return: variant, the value from the data | ||
""" | ||
if jsonpath is None or jsonpath == "": | ||
return None | ||
|
||
# If this is the first entry into the method, then set the data to the | ||
data = data or self.param_template | ||
matches = parse(jsonpath).find(data) | ||
|
||
default_value = default | ||
if impute_default: | ||
default_value = self.get_default(jsonpath, default) | ||
|
||
results = [] | ||
for index, match in enumerate(matches): | ||
# print(f"Index {index} to update match {match.path} | {match.value} | {match.context}") | ||
if match.value is None: | ||
results.append(default_value) | ||
else: | ||
results.append(match.value) | ||
for match in matches: | ||
results.append(match.value) | ||
|
||
if len(results) == 1: | ||
# If only one value, then return that value and not a list of values | ||
# If only one value, then return that value and not a list of values. | ||
results = results[0] | ||
elif len(results) == 0: | ||
return default_value | ||
return None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, no results means NONE! |
||
|
||
# otherwise return the list of values | ||
return results | ||
|
||
def get_param_by_id(self, param_id, jsonpath): | ||
"""Return a parameter for a specific id. This is similar to get_param but allows the user | ||
"""Return a parameter for a specific id. This wrapper to get_param allows the user | ||
to constrain the data based on the id. | ||
|
||
:param param_id: string, id of the object to look up in the system parameters file | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't like that we do this. I think we should always return a list. I don't know why I did this (I'm guilty for it). I think I was following another API pattern. Regardless, leave it as is, otherwise it will break lots of things.