Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set PYOPENGL_PLATFORM before opengl imports #149

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some distinction in how this sets the environment (like, not to parent process) that I think works in our favor. So, good!


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