Skip to content

Commit

Permalink
Merge pull request #25 from eriknw/magic_get
Browse files Browse the repository at this point in the history
Allow the magic to use `afar.get` too using `-g` or `--get`
  • Loading branch information
eriknw authored Aug 30, 2021
2 parents c388549 + 1ab2b13 commit cfc8ce9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions afar/_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from IPython.core.error import UsageError
from IPython.core.magic import Magics, line_cell_magic, magics_class, needs_local_scope

from ._core import Run, run
from ._core import Run, get, run
from ._where import Where, remotely


Expand All @@ -16,14 +16,17 @@ def afar(self, line, cell=None, *, local_ns):
"""Execute the cell on a dask.distributed cluster.
Usage, in line mode:
%afar [-r run -d data -w where -c client] code_to_run
%afar [-g -r run -d data -w where -c client] code_to_run
Usage, in cell mode
%%afar [-r run -d data -w where -c client <variable_names>]
%%afar [-g -r run -d data -w where -c client <variable_names>]
code...
code...
Options:
-g/--get
Get results as values, not as futures. This uses `afar.get` instead of `afar.run`.
-r/--run <run>
A `Run` object from the local namespace such as `run = afar.run(data=mydata)`
Expand Down Expand Up @@ -55,7 +58,8 @@ def afar(self, line, cell=None, *, local_ns):
"""
opts, line = self.parse_options(
line,
"r:d:w:c:",
"gr:d:w:c:",
"get",
"run=",
"data=",
"where=",
Expand All @@ -81,6 +85,8 @@ def afar(self, line, cell=None, *, local_ns):
raise UsageError(f"Variable name {runner!r} for -r or --run {not_found}")
if not isinstance(runner, Run):
raise UsageError(f"-r or --run argument must be of type Run; got: {type(runner)}")
elif "g" in opts or "get" in opts:
runner = get()
else:
runner = run()
client = runner.client
Expand Down

0 comments on commit cfc8ce9

Please sign in to comment.