From 37b794b26b8adf7c4ad5381c0489d39399d3ba32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <amuoz@ed.ac.uk>
Date: Tue, 25 Jan 2022 10:21:30 +0000
Subject: [PATCH] read yaml from str

---
 abc.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/abc.py b/abc.py
index 3b216c4a..95185d80 100644
--- a/abc.py
+++ b/abc.py
@@ -57,9 +57,15 @@ class ParametersABC(ABC):
         return dump(self.to_dict())
 
     @classmethod
-    def from_yaml(cls, path: Union[PosixPath, str]):
-        with open(Path(path)) as f:
-            params = safe_load(f)
+    def from_yaml(cls, source: Union[PosixPath, str]):
+        """Returns class from a yaml filename or stdin"""
+        fpath = Path(source)
+        if fpath.exists():
+            with open(fpath) as f:
+                params = safe_load(f)
+        else:
+            params = safe_load(source)
+
         return cls(**params)
 
     @classmethod
-- 
GitLab