diff --git a/maestrowf/abstracts/specification.py b/maestrowf/abstracts/specification.py index d613f464f..6ec527c0b 100644 --- a/maestrowf/abstracts/specification.py +++ b/maestrowf/abstracts/specification.py @@ -46,8 +46,9 @@ def load_specification(cls, path): :param path: Path to a study specification. :returns: A specification object containing the information loaded - from path. + from path. """ + pass @abstractclassmethod def load_specification_from_stream(cls, stream): diff --git a/maestrowf/specification/yamlspecification.py b/maestrowf/specification/yamlspecification.py index 76057b661..5503c5147 100644 --- a/maestrowf/specification/yamlspecification.py +++ b/maestrowf/specification/yamlspecification.py @@ -102,15 +102,7 @@ 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 e @@ -139,9 +131,29 @@ def load_specification_from_stream(cls, stream): ) spec = yaml.load(stream) + 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 = None specification.description = spec.pop("description", {}) specification.environment = spec.pop( "env",