From 968cce2da9d763d5b4cd4a31577887e2c2d882a6 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Fri, 30 Jul 2021 15:00:10 -0500 Subject: [PATCH 1/4] Set `pure=False` when submitting our magic code. We don't know whether it's pure or not, so let's assume it's not. --- afar/core.py | 6 ++++-- afar/reprs.py | 7 ++++++- setup.cfg | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/afar/core.py b/afar/core.py index bf36c4d..28e1e4c 100644 --- a/afar/core.py +++ b/afar/core.py @@ -38,7 +38,7 @@ def __enter__(self): def __exit__(self, exc_type, exc_value, exc_traceback): # pragma: no cover return False - def __call__(self, *, client=None, **submit_kwargs): + def __call__(self, client=None, **submit_kwargs): return Where(self.where, client, submit_kwargs) @@ -194,7 +194,9 @@ def _exit(self, exc_type, exc_value, exc_traceback): if self._where == "remotely": if client is None: client = distributed.client._get_global_client() - remote_dict = client.submit(run_afar, self._magic_func, names, futures, **submit_kwargs) + remote_dict = client.submit( + run_afar, self._magic_func, names, futures, pure=False, **submit_kwargs + ) if display_expr: repr_val = client.submit( reprs.repr_afar, diff --git a/afar/reprs.py b/afar/reprs.py index 8ba2274..7e028a9 100644 --- a/afar/reprs.py +++ b/afar/reprs.py @@ -116,7 +116,12 @@ def repr_afar(val, repr_methods): rv = traceback.format_exception(*exc_info) return rv, method_name, True else: - if rv is None or not isinstance(rv, str): + if rv is None: + continue + if method_name == "_repr_mimebundle_": + if not isinstance(rv, (dict, tuple)): + continue + elif not isinstance(rv, str): continue return rv, method_name, False return repr(val), "__repr__", False diff --git a/setup.cfg b/setup.cfg index 46efc6f..4120389 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,6 +17,7 @@ ignore = [coverage:run] source = afar +branch = True omit = afar/_version.py, afar/tests/* From d9d991e4553eff853e5772ef25a6fa0fab278c44 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Fri, 30 Jul 2021 22:14:00 -0500 Subject: [PATCH 2/4] Update README to create local Dask cluster --- .github/workflows/test_pip.yml | 1 + README.md | 4 ++++ afar/reprs.py | 1 + 3 files changed, 6 insertions(+) diff --git a/.github/workflows/test_pip.yml b/.github/workflows/test_pip.yml index 8e5c7c4..ce53414 100644 --- a/.github/workflows/test_pip.yml +++ b/.github/workflows/test_pip.yml @@ -26,6 +26,7 @@ jobs: pip install -r requirements.txt pip install -e . - name: PyTest + if: (! contains(matrix.python-version, 'pypy')) || contains(matrix.os, 'windows') run: | pip install pytest coverage coverage run --branch -m pytest diff --git a/README.md b/README.md index 1615084..c884201 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,13 @@ > _Robert A. Heinlein_
+**To install:** `pip install afar` + `afar` allows you to run code on a remote [Dask](https://dask.org/) [cluster](https://distributed.dask.org/en/latest/) using context managers. For example: ```python import afar +from dask.distributed import Client +client = Client() with afar.run, remotely: import dask_cudf diff --git a/afar/reprs.py b/afar/reprs.py index 7e028a9..d2256d8 100644 --- a/afar/reprs.py +++ b/afar/reprs.py @@ -106,6 +106,7 @@ def repr_afar(val, repr_methods): if method is None: continue if method_name == "_ipython_display_": + # Custom display! Send the object to the client return val, method_name, False try: rv = method() From 19c0e735b45e60028e40acb9972285a357c0ff9c Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Fri, 30 Jul 2021 22:17:58 -0500 Subject: [PATCH 3/4] oops --- .github/workflows/test_pip.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_pip.yml b/.github/workflows/test_pip.yml index ce53414..4da729a 100644 --- a/.github/workflows/test_pip.yml +++ b/.github/workflows/test_pip.yml @@ -49,7 +49,7 @@ jobs: - name: Notebook test if: (! contains(matrix.python-version, 'pypy')) || (! contains(matrix.os, 'windows')) run: | - pip install nbconvert jupyter + pip install nbconvert jupyter pytest jupyter nbconvert --to notebook --execute afar/tests/*ipynb finish: From 21846ce751b2e62c4ea5e7386d308287864e2a00 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Fri, 30 Jul 2021 22:44:12 -0500 Subject: [PATCH 4/4] Why does pip-installed pypy not like to run? --- .github/workflows/test_pip.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_pip.yml b/.github/workflows/test_pip.yml index 4da729a..161d3f1 100644 --- a/.github/workflows/test_pip.yml +++ b/.github/workflows/test_pip.yml @@ -47,9 +47,9 @@ jobs: coverage report --show-missing coveralls --service=github - name: Notebook test - if: (! contains(matrix.python-version, 'pypy')) || (! contains(matrix.os, 'windows')) + if: (! contains(matrix.python-version, 'pypy')) run: | - pip install nbconvert jupyter pytest + pip install nbconvert jupyter jupyter nbconvert --to notebook --execute afar/tests/*ipynb finish: