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

Allow option to load yaml resources relative to yaml file #1460

Merged
merged 7 commits into from Mar 24, 2016

Conversation

@kwmsmith
Copy link
Member

commented Mar 24, 2016

This builds on PR #1427.

@llllllllll, this should address your comments in that PR thread. Further thoughts?

"""Construct a dictionary of resources from a YAML specification.
Parameters
----------
path : str
Path to a YAML specification of resources to load
path : file

This comment has been minimized.

Copy link
@llllllllll

llllllllll Mar 24, 2016

Member

this should be something like f or file if it is a file instead of a path to a file.

cwd = os.path.abspath(os.getcwd())
if root != cwd:
os.chdir(root)
yield

This comment has been minimized.

Copy link
@llllllllll

llllllllll Mar 24, 2016

Member

this should be in a try/finally so that if an exception is raised in the manage_chdir context we still correctly exit.

hidden=False):
@contextmanager
def manage_chdir(root):
"""Context manager that changes to ``root`` directory on ``__entry__`` and

This comment has been minimized.

Copy link
@llllllllll

llllllllll Mar 24, 2016

Member

this data model method here is __enter__; however, I think it is fine to just say on enter or on exit (without the underscores)

def from_yaml(path, ignore=(ValueError, NotImplementedError), followlinks=True,
hidden=False):
@contextmanager
def manage_chdir(root):

This comment has been minimized.

Copy link
@llllllllll

llllllllll Mar 24, 2016

Member

I think an easier name for this might be pushd. manage doesn't quite tell me how it is being managed but the pushd/popd analog might be more clear

This comment has been minimized.

Copy link
@llllllllll

llllllllll Mar 24, 2016

Member

could we call this path, I am not sure what this is the root of.

changes back to ``os.getcwd()`` on __exit__.
"""
root = os.path.abspath(root)
cwd = os.path.abspath(os.getcwd())

This comment has been minimized.

Copy link
@llllllllll

llllllllll Mar 24, 2016

Member

os.getcwd returns the absolute path

"""
root = os.path.abspath(root)
cwd = os.path.abspath(os.getcwd())
if root != cwd:

This comment has been minimized.

Copy link
@llllllllll

llllllllll Mar 24, 2016

Member

is this check just an optimization?

@kwmsmith

This comment has been minimized.

Copy link
Member Author

commented Mar 24, 2016

@llllllllll thanks for the good feedback and quick review.

@brendancol thoughts / input?

@kwmsmith kwmsmith merged commit 1f7702e into blaze:master Mar 24, 2016

1 of 2 checks passed

coverage/coveralls Coverage decreased (-0.1%) to 89.338%
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@kwmsmith kwmsmith deleted the kwmsmith:from-yaml-source-relative-to-yaml branch Mar 24, 2016

@coveralls

This comment has been minimized.

Copy link

commented Apr 7, 2018

Coverage Status

Coverage decreased (-1.09%) to 88.364% when pulling 77f8f2c on kwmsmith:from-yaml-source-relative-to-yaml into 640fe88 on blaze:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.