Skip to content

Commit

Permalink
Merge pull request #149 from chrishavlin/env_var_handling
Browse files Browse the repository at this point in the history
set PYOPENGL_PLATFORM before opengl imports
  • Loading branch information
chrishavlin authored Oct 28, 2024
2 parents d84a8e8 + aa65341 commit 20e5388
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
11 changes: 7 additions & 4 deletions yt_idv/rendering_contexts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os

import OpenGL.error


def render_context(engine="pyglet", **kwargs):
"""
Expand All @@ -18,6 +16,13 @@ def render_context(engine="pyglet", **kwargs):
RenderingContext
"""

# PYOPENGL_PLATFORM must be set before any opengl imports
if engine in ("osmesa", "egl"):
os.environ["PYOPENGL_PLATFORM"] = engine

import OpenGL.error

if engine == "pyglet":
from .pyglet_context import PygletRenderingContext

Expand All @@ -35,12 +40,10 @@ def render_context(engine="pyglet", **kwargs):
raise Exception(extramsg) from oee
raise oee
elif engine == "osmesa":
os.environ["PYOPENGL_PLATFORM"] = "osmesa"
from .osmesa_context import OSMesaRenderingContext

return OSMesaRenderingContext(**kwargs)
elif engine == "egl":
os.environ["PYOPENGL_PLATFORM"] = "egl"
from .egl_context import EGLRenderingContext

return EGLRenderingContext(**kwargs)
Expand Down
7 changes: 7 additions & 0 deletions yt_idv/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os


def pytest_configure(config):
# this will get run before all tests, before collection and
# any opengl imports that happen within test files.
os.environ["PYOPENGL_PLATFORM"] = "osmesa"
5 changes: 0 additions & 5 deletions yt_idv/tests/test_yt_idv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
from yt_idv.scene_data.curve import CurveCollection, CurveData


@pytest.fixture(autouse=True)
def pyopengl_setup(monkeypatch):
monkeypatch.setenv("PYOPENGL_PLATFORM", "osmesa")


@pytest.fixture()
def osmesa_fake_amr():
"""Return an OSMesa context that has a "fake" AMR dataset added, with "radius"
Expand Down

0 comments on commit 20e5388

Please sign in to comment.