Skip to content

Commit

Permalink
CyOpenGL compilation: compile CyOpenGL even if there is no Tk as we c…
Browse files Browse the repository at this point in the history
…an still compile it, even though we cannot import it later. Raise an exception if CyOpenGL headers cannot be found if SNAPPY_ALWAYS_BUILD_CYOPENGL is set.
  • Loading branch information
unhyperbolic committed Jul 20, 2024
1 parent 497f233 commit 812e90e
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,22 @@ def add(self, source_file, dependency_mod_time=0.0):
language='c++'
)

CyOpenGL_has_headers = False
if sys.platform == 'win32':
# We use glew, so we do not need GL headers from somewhere
# else
CyOpenGL_has_headers = True
else:
header = 'gl.h'
CyOpenGL_has_headers = any(
exists(os.path.join(path, header))
for path in CyOpenGL_includes)
if not CyOpenGL_has_headers:
print("***WARNING***: Not building CyOpenGL so many graphics "
"features will not be available.")
print("This is because the OpenGL header %s was not found." % header)
print("The following directories were searched: %s." % (
', '.join(CyOpenGL_includes)))

# Twister

Expand Down Expand Up @@ -536,29 +552,12 @@ def add(self, source_file, dependency_mod_time=0.0):
else:
install_requires.append('ipython>=1.0')

# Determine whether we will be able to activate the GUI code

try:
import tkinter as Tk
except ImportError:
Tk = None

if sys.platform == 'win32':
if CyOpenGL_has_headers:
ext_modules.append(CyOpenGL)
elif Tk is not None:
missing = {}
for header in ['gl.h']:
results = [exists(os.path.join(path, header))
for path in CyOpenGL_includes]
missing[header] = (True in results)
if False in missing.values():
print("***WARNING***: OpenGL headers not found, "
"not building CyOpenGL, "
"will disable some graphics features.")
else:
ext_modules.append(CyOpenGL)
else:
print("***WARNING**: Tkinter not installed, GUI won't work")
elif (os.environ.get('SNAPPY_ALWAYS_BUILD_CYOPENGL', 'False')
not in ['0', 'false', 'False']):
raise RuntimeError('Could not find CyOpenGL requirements but '
'SNAPPY_ALWAYS_BUILD_CYOPENGL is set.')

# Get version number:
exec(open('python/version.py').read())
Expand Down

0 comments on commit 812e90e

Please sign in to comment.