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

Extend the Specification interface to break out loading from streams. #198

Merged
merged 6 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions maestrowf/abstracts/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,21 @@ class Specification(object):
@abstractclassmethod
def load_specification(cls, path):
"""
Method for loading a study specification.
Method for loading a study specification from a file.

:param path: Path to a study specification.
:returns: A specification object containing the information from path.
:returns: A specification object containing the information loaded
from path.
"""
pass

@abstractclassmethod
def load_specification_from_stream(cls, stream):
"""
Method for loading a study specification from a stream.

:param stream: Raw text stream containing specification data.
:returns: A specification object containing the information in string.
"""
pass

Expand Down
32 changes: 22 additions & 10 deletions maestrowf/datastructures/yamlspecification.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,34 @@ def load_specification(cls, path):
try:
# Load the YAML spec from the file.
with open(path, 'r') as data:
try:
spec = yaml.load(data, yaml.FullLoader)
except AttributeError:
logger.warning(
"*** PyYAML is using an unsafe version with a known "
"load vulnerability. Please upgrade your installation "
"to a more recent version! ***")
spec = yaml.load(data)

specification = cls.load_specification_from_stream(data)
except Exception as e:
logger.exception(e.args)
raise

return specification

@classmethod
def load_specification_from_stream(cls, stream):
"""
Load a study specification.

:param stream: Raw text stream to study YAML specification data.
:returns: A specification object containing the information from the
passed stream.
"""

try:
spec = yaml.load(stream, yaml.FullLoader)
except AttributeError:
logger.warning(
"*** PyYAML is using an unsafe version with a known "
"load vulnerability. Please upgrade your installation "
"to a more recent version! ***")
spec = yaml.load(stream)

logger.debug("Loaded specification -- \n%s", spec["description"])
specification = cls()
specification.path = path
FrankD412 marked this conversation as resolved.
Show resolved Hide resolved
specification.description = spec.pop("description", {})
specification.environment = spec.pop("env",
{'variables': {},
Expand Down