From 2901a5b5fef3e3ee3dbd094797288725f0c52ee2 Mon Sep 17 00:00:00 2001 From: Stephan Seitz <stephan.seitz@fau.de> Date: Wed, 13 Nov 2019 13:10:40 +0100 Subject: [PATCH] Protect pystencils.opencl.autoinit with try..except --- conftest.py | 3 +-- pystencils/opencl/autoinit.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/conftest.py b/conftest.py index c20bde409..7e369f46d 100644 --- a/conftest.py +++ b/conftest.py @@ -33,8 +33,7 @@ def add_path_to_ignore(path): collect_ignore += [os.path.join(SCRIPT_FOLDER, path, f) for f in os.listdir(os.path.join(SCRIPT_FOLDER, path))] -collect_ignore = [os.path.join(SCRIPT_FOLDER, "doc", "conf.py"), - os.path.join(SCRIPT_FOLDER, "pystencils", "opencl", "opencl.autoinit")] +collect_ignore = [os.path.join(SCRIPT_FOLDER, "doc", "conf.py")] add_path_to_ignore('pystencils_tests/benchmark') add_path_to_ignore('_local_tmp') diff --git a/pystencils/opencl/autoinit.py b/pystencils/opencl/autoinit.py index f37ddc1cb..3d20169b6 100644 --- a/pystencils/opencl/autoinit.py +++ b/pystencils/opencl/autoinit.py @@ -4,8 +4,13 @@ Automatically initializes OpenCL context using any device. Use `pystencils.opencl.{init_globally_with_context,init_globally}` if you want to use a specific device. """ -from pystencils.opencl import * # noqa -from pystencils.opencl.opencljit import * # noqa -from pystencils.opencl.opencljit import init_globally +from pystencils.opencl.opencljit import ( + clear_global_ctx, init_globally, init_globally_with_context, make_python_function) -init_globally() +__all__ = ['init_globally', 'init_globally_with_context', 'clear_global_ctx', 'make_python_function'] + +try: + init_globally() +except Exception as e: + import warnings + warnings.warn(str(e)) -- GitLab