Skip to content

Commit

Permalink
Add yaml export
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Oct 6, 2020
1 parent 9047a8a commit beb4fe7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions climetlab/plotting/drivers/magics/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __repr__(self):
x.append("\n )")
return "".join(x)

def to_yaml(self):
return {self.action: self.kwargs}

@property
def action(self):
return self.__class__.__name__
Expand Down
14 changes: 11 additions & 3 deletions climetlab/plotting/drivers/magics/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import logging
import os
import yaml

from climetlab.core.bbox import BoundingBox
from climetlab.core.caching import temp_file
Expand Down Expand Up @@ -78,6 +79,10 @@ def temporary_file(self, extension: str = ".tmp") -> str:
:return: Temporary file name.
:rtype: str
"""

if self._options("dump_yaml", False):
return temp_file(extension).path

self._tmp.append(temp_file(extension))
return self._tmp[-1].path

Expand Down Expand Up @@ -334,13 +339,16 @@ def show(self):
self._options("update", False)
self._options("update_foreground", False)

self._options.check_unused()

args = [page] + self.macro()

if int(os.environ.get("CLIMETLAB_DEBUG", "0")):
if self._options("dump_python", False):
print(args)

if self._options("dump_yaml", False):
print(yaml.dump(dict(plot=[a.to_yaml() for a in args]), default_flow_style=False))

self._options.check_unused()

try:
plot(*args)
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pytest]
; addopts=--cov climetlab --verbose --cov-report xml --cov-report html
addopts=-s --cov climetlab --verbose --cov-report xml --cov-report html
; addopts=--no-cov
addopts=--verbose
; addopts=--verbose

0 comments on commit beb4fe7

Please sign in to comment.