-
Notifications
You must be signed in to change notification settings - Fork 5
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
Eliminate dependence on pyyaml-include by adapting Butler loader #89
Conversation
… it is an absolute path. 2) Otherwise it is interpreted as relative to current file (not necessarily the same as top-level file)
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.
There should be some test code that runs on example yaml files. Those files will also demonstrate more clearly how the include directives can be used.
skycatalogs/utils/config_utils.py
Outdated
return result | ||
|
||
else: | ||
print("Error:: unrecognised node type in !include statement", |
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.
Can a logger be used instead of a print statement here and below so that the output level can be controlled?
stream : text io stream | ||
The stream to parse. | ||
|
||
This code was adapted from the LSST Science Pipelines Butler. |
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.
It would be useful to give a more complete reference to the LSST code, e.g., a url pointing to the daf_butler code.
else: | ||
actual_path = os.path.join(self._current_dir, filepath) | ||
print("Opening YAML file via !include: %s", actual_path) | ||
|
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.
This formatting works for a logger message, but a print statement needs to have
print("Opening YAML file via !include: %s" % actual_path)
skycatalogs/utils/config_utils.py
Outdated
""" | ||
def __init__(self, filestream): | ||
super().__init__(filestream) | ||
self._root = os.path.dirname(filestream.name) |
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.
Are self._root
and self._current_dir
both needed? The base class doesn't seem to have a _root
attribute, so both of these don't seem to be needed.
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.
That may be left over from earlier behavior, where all include paths were evaluated relative to initial file. I changed that to be relative to file with the reference. Will look into it.
Indeed, it's not used anywhere.
skycatalogs/utils/config_utils.py
Outdated
old_current = self._current_dir | ||
self._current_dir = actual_path | ||
# Read all the data from the resource | ||
with open(actual_path) as f: | ||
content = yaml.load(f, YamlIncludeLoader) | ||
self._current_dir = old_current |
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.
You don't need to do any special handling of self._current_dir
here since it's set per-instance of YamlIncludeLoader
. So this code can just be
# Read all the data from the resource
with open(actual_path) as f:
content = yaml.load(f, YamlIncludeLoader)
The other lines don't have any net effect, otherwise it would have been necessary to set self._current_dir = os.path.dirname(actual_path)
on line 79.
69a818e
to
c746f8f
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.
Seems fine, though it would be good to delete the unneeded commented out code.
Adapted the Butler loader, eliminating its use of lsst.resources so there are no dependencies on LSST Science Pipelines.
Moved yaml parsing code into config_utils.py