From 96f8bcf7712c25781ae43a6f65a563db4b74ad0a Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Mon, 21 Feb 2022 16:52:10 +0000 Subject: [PATCH 1/5] Fix cython in scipy-notebook --- scipy-notebook/Dockerfile | 10 ++++-- .../scipy-notebook/data/cython/helloworld.pyx | 1 + tests/scipy-notebook/data/cython/setup.py | 9 +++++ tests/scipy-notebook/test_cython.py | 36 +++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/scipy-notebook/data/cython/helloworld.pyx create mode 100644 tests/scipy-notebook/data/cython/setup.py create mode 100644 tests/scipy-notebook/test_cython.py diff --git a/scipy-notebook/Dockerfile b/scipy-notebook/Dockerfile index 8e36c706b4..7ca8d9e72a 100644 --- a/scipy-notebook/Dockerfile +++ b/scipy-notebook/Dockerfile @@ -8,9 +8,15 @@ LABEL maintainer="Jupyter Project " USER root -# ffmpeg for matplotlib anim & dvipng+cm-super for latex labels RUN apt-get update --yes && \ - apt-get install --yes --no-install-recommends ffmpeg dvipng cm-super && \ + apt-get install --yes --no-install-recommends \ + # for cython: https://cython.readthedocs.io/en/latest/src/quickstart/install.html + build-essential \ + # for latex labels + cm-super \ + dvipng \ + # for matplotlib anim + ffmpeg && \ apt-get clean && rm -rf /var/lib/apt/lists/* USER ${NB_UID} diff --git a/tests/scipy-notebook/data/cython/helloworld.pyx b/tests/scipy-notebook/data/cython/helloworld.pyx new file mode 100644 index 0000000000..ad35e5ae34 --- /dev/null +++ b/tests/scipy-notebook/data/cython/helloworld.pyx @@ -0,0 +1 @@ +print("Hello World") diff --git a/tests/scipy-notebook/data/cython/setup.py b/tests/scipy-notebook/data/cython/setup.py new file mode 100644 index 0000000000..3065be3b3b --- /dev/null +++ b/tests/scipy-notebook/data/cython/setup.py @@ -0,0 +1,9 @@ +from setuptools import setup +from Cython.Build import cythonize +from pathlib import Path + + +THIS_DIR = Path(__file__).parent.resolve() + + +setup(ext_modules=cythonize(str(THIS_DIR / "helloworld.pyx"))) diff --git a/tests/scipy-notebook/test_cython.py b/tests/scipy-notebook/test_cython.py new file mode 100644 index 0000000000..31c92cf223 --- /dev/null +++ b/tests/scipy-notebook/test_cython.py @@ -0,0 +1,36 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. + +import logging +from pathlib import Path +import shutil +import tempfile + +from conftest import TrackedContainer + +LOGGER = logging.getLogger(__name__) +THIS_DIR = Path(__file__).parent.resolve() + + +def test_cython(container: TrackedContainer) -> None: + data_dir = THIS_DIR / "data/cython" + + with tempfile.TemporaryDirectory() as host_data_dir: + """We create temporary dir with the same content to mount it as a writeable folder + This allows to run this test in parallel many times + """ + shutil.copy(data_dir / "helloworld.pyx", host_data_dir) + shutil.copy(data_dir / "setup.py", host_data_dir) + + cont_data_dir = "/home/jovyan/data" + command = "sleep infinity" + + running_container = container.run_detached( + volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "rw"}}, + tty=True, + command=["start.sh", "bash", "-c", command], + ) + command = f"python {cont_data_dir}/setup.py build_ext --inplace" + cmd = running_container.exec_run(command) + LOGGER.debug(cmd.output.decode("utf-8")) + assert cmd.exit_code == 0, f"Command {command} failed" From 9b2484a38b892370e299c052aa884f86e7316df2 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Mon, 21 Feb 2022 17:29:20 +0000 Subject: [PATCH 2/5] Use DEBUG log level --- tests/pytest.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytest.ini b/tests/pytest.ini index 11eec270a8..49f609a808 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -1,7 +1,7 @@ [pytest] addopts = -ra --color=yes log_cli = 1 -log_cli_level = INFO +log_cli_level = DEBUG log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s) log_cli_date_format=%Y-%m-%d %H:%M:%S markers = From 0fae846c340607d8ff54e002ec472e61d207ce81 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Mon, 21 Feb 2022 18:47:42 +0000 Subject: [PATCH 3/5] Simplify test --- tests/scipy-notebook/data/cython/setup.py | 7 +---- tests/scipy-notebook/test_cython.py | 38 +++++++++-------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/tests/scipy-notebook/data/cython/setup.py b/tests/scipy-notebook/data/cython/setup.py index 3065be3b3b..de123d62c5 100644 --- a/tests/scipy-notebook/data/cython/setup.py +++ b/tests/scipy-notebook/data/cython/setup.py @@ -1,9 +1,4 @@ from setuptools import setup from Cython.Build import cythonize -from pathlib import Path - -THIS_DIR = Path(__file__).parent.resolve() - - -setup(ext_modules=cythonize(str(THIS_DIR / "helloworld.pyx"))) +setup(ext_modules=cythonize("helloworld.pyx")) diff --git a/tests/scipy-notebook/test_cython.py b/tests/scipy-notebook/test_cython.py index 31c92cf223..ba5808e8ab 100644 --- a/tests/scipy-notebook/test_cython.py +++ b/tests/scipy-notebook/test_cython.py @@ -3,8 +3,6 @@ import logging from pathlib import Path -import shutil -import tempfile from conftest import TrackedContainer @@ -13,24 +11,18 @@ def test_cython(container: TrackedContainer) -> None: - data_dir = THIS_DIR / "data/cython" - - with tempfile.TemporaryDirectory() as host_data_dir: - """We create temporary dir with the same content to mount it as a writeable folder - This allows to run this test in parallel many times - """ - shutil.copy(data_dir / "helloworld.pyx", host_data_dir) - shutil.copy(data_dir / "setup.py", host_data_dir) - - cont_data_dir = "/home/jovyan/data" - command = "sleep infinity" - - running_container = container.run_detached( - volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "rw"}}, - tty=True, - command=["start.sh", "bash", "-c", command], - ) - command = f"python {cont_data_dir}/setup.py build_ext --inplace" - cmd = running_container.exec_run(command) - LOGGER.debug(cmd.output.decode("utf-8")) - assert cmd.exit_code == 0, f"Command {command} failed" + host_data_dir = THIS_DIR / "data/cython" + cont_data_dir = "/home/jovyan/data" + + logs = container.run_and_wait( + timeout=10, + volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}}, + tty=True, + command=[ + "start.sh", + "bash", + "-c", + f"cp -r {cont_data_dir}/ /tmp/test/ && cd /tmp/test && python3 setup.py build_ext", + ], + ) + assert "building 'helloworld' extension" in logs From 9196fb296a4ac2836d877715600a790ebb9eabe8 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Mon, 21 Feb 2022 18:49:05 +0000 Subject: [PATCH 4/5] Add comment --- tests/scipy-notebook/test_cython.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/scipy-notebook/test_cython.py b/tests/scipy-notebook/test_cython.py index ba5808e8ab..343bcc99db 100644 --- a/tests/scipy-notebook/test_cython.py +++ b/tests/scipy-notebook/test_cython.py @@ -22,6 +22,7 @@ def test_cython(container: TrackedContainer) -> None: "start.sh", "bash", "-c", + # We copy our data to temporary folder to be able to modify the directory f"cp -r {cont_data_dir}/ /tmp/test/ && cd /tmp/test && python3 setup.py build_ext", ], ) From 3b8325419eaffea8cdac7d6164f82862376240fb Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Mon, 21 Feb 2022 19:06:55 +0000 Subject: [PATCH 5/5] Remove unused variable --- tests/scipy-notebook/test_cython.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/scipy-notebook/test_cython.py b/tests/scipy-notebook/test_cython.py index 343bcc99db..e5e4e8ea0e 100644 --- a/tests/scipy-notebook/test_cython.py +++ b/tests/scipy-notebook/test_cython.py @@ -1,12 +1,10 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -import logging from pathlib import Path from conftest import TrackedContainer -LOGGER = logging.getLogger(__name__) THIS_DIR = Path(__file__).parent.resolve()