Skip to content
Snippets Groups Projects
Unverified Commit 53b715ec authored by Andreas Klöckner's avatar Andreas Klöckner Committed by GitHub
Browse files

Merge pull request #316 from cgohlke/patch-1

Fix slow import of pyopencl
parents 7b9ec9c5 2f450630
No related branches found
No related tags found
No related merge requests found
......@@ -255,23 +255,20 @@ def compiler_output(text):
# {{{ find pyopencl shipped source code
def _find_pyopencl_include_path():
from pkg_resources import Requirement, resource_filename, DistributionNotFound
from os.path import join, abspath, dirname, exists
try:
# Try to find the include path in the same directory as this file
include_path = join(abspath(dirname(__file__)), "cl")
if not exists(include_path):
raise IOError("unable to find pyopencl include path")
except Exception:
# Try to find the resource with pkg_resources (the recommended
# setuptools approach)
# setuptools approach). This is very slow.
from pkg_resources import Requirement, resource_filename
include_path = resource_filename(
Requirement.parse("pyopencl"), "pyopencl/cl")
except DistributionNotFound:
# If pkg_resources can't find it (e.g. if the module is part of a
# frozen application), try to find the include path in the same
# directory as this file
from os.path import join, abspath, dirname, exists
include_path = join(abspath(dirname(__file__)), "cl")
# If that doesn't exist, just re-raise the exception caught from
# resource_filename.
if not exists(include_path):
raise
raise IOError("unable to find pyopencl include path")
# Quote the path if it contains a space and is not quoted already.
# See https://github.com/inducer/pyopencl/issues/250 for discussion.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment