Skip to content

Commit

Permalink
Dump to YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Nov 19, 2020
1 parent 4b7137d commit 61a8919
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Magics/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,27 @@ def tofortran(self, f):
else:
print(f, "")

def to_yaml(self):

def tidy(x):
if isinstance(x, (list, tuple)):
return [tidy(y) for y in x]
if isinstance(x, dict):
d = {}
for k, v in x.items():
d[k] = tidy(v)
return d

if x == 'on':
return True

if x == 'off':
return False

return x

return {self.verb: tidy(self.args)}

def clean_object(self, obj):
if sys.version_info[0] < 3:
if type(obj) in (int, float, str, bool, numpy.float64, numpy.float32):
Expand Down Expand Up @@ -766,6 +787,14 @@ def _execute(o):

def _plot(*args):

if os.environ.get("MAGICS_DUMP_YAML"):
import yaml
actions = []
for n in args:
actions.append(n.to_yaml())
print(yaml.dump(dict(plot=actions), default_flow_style=False))
return

context.set()
# try :
Magics.init()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def read(fname):
return io.open(file_path, encoding="utf-8").read()


version = "1.5.4"
version = "1.5.5"


setuptools.setup(
Expand Down

0 comments on commit 61a8919

Please sign in to comment.