Skip to content

Commit

Permalink
Support python 3.8-3.12, and pypy (#418)
Browse files Browse the repository at this point in the history
* Support py 3.8-3.12

* Try to fix tests for pypy

* fix another test for pypy

* mm

* I'm now just springkling gc.collects :/

* try harder?
  • Loading branch information
almarklein authored Nov 16, 2023
1 parent a63be1c commit 202b526
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 14 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ jobs:
fail-fast: false
matrix:
include:
- name: Test Linux py37
os: ubuntu-latest
pyversion: '3.7'
- name: Test Linux py38
os: ubuntu-latest
pyversion: '3.8'
Expand All @@ -177,10 +174,12 @@ jobs:
- name: Test Linux py311
os: ubuntu-latest
pyversion: '3.11'
# Pypy3 fails on installing a 3d party dependency
#- name: Test Linux pypy3
# os: ubuntu-latest
# pyversion: 'pypy3'
- name: Test Linux py312
os: ubuntu-latest
pyversion: '3.12'
- name: Test Linux pypy3
os: ubuntu-latest
pyversion: 'pypy3.9'
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.pyversion }}
Expand Down
2 changes: 1 addition & 1 deletion docs/start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Install with pip
----------------

You can install ``wgpu-py`` via pip.
Python 3.7 or higher is required. Pypy is supported. Only depends on ``cffi`` (installed automatically by pip).
Python 3.8 or higher is required. Pypy is supported. Only depends on ``cffi`` (installed automatically by pip).

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def finalize_options(self):
exclude=["codegen", "codegen.*", "tests", "tests.*", "examples", "examples.*"]
),
package_data={f"{NAME}.resources": resources_globs},
python_requires=">=3.7.0",
python_requires=">=3.8.0",
install_requires=runtime_deps,
extras_require=extra_deps,
license="BSD 2-Clause",
Expand Down
5 changes: 4 additions & 1 deletion tests/test_gui_auto_offscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"""

import os
import gc
import weakref

import wgpu
from pytest import fixture, skip
from testutils import can_use_wgpu_lib
from testutils import can_use_wgpu_lib, is_pypy


if not can_use_wgpu_lib:
Expand Down Expand Up @@ -60,4 +61,6 @@ def test_offscreen_canvas_del():

assert ref() is not None
del canvas
if is_pypy:
gc.collect()
assert ref() is None
8 changes: 5 additions & 3 deletions tests/test_gui_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
Test the canvas basics.
"""

import gc

import numpy as np
import wgpu.gui # noqa
from testutils import run_tests, can_use_wgpu_lib
from testutils import run_tests, can_use_wgpu_lib, is_pypy
from pytest import mark


Expand Down Expand Up @@ -193,8 +195,8 @@ def bar(self):
del f1
del f2

# May be needed (on pypy?) to force a collection
# gc.collect()
if is_pypy:
gc.collect()

assert len(xx) == 2
b1()
Expand Down
1 change: 1 addition & 0 deletions tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@ def find_examples(query=None, negative_query=None, return_stems=False):
can_use_wgpu_lib = _determine_can_use_wgpu_lib()
can_use_glfw = _determine_can_use_glfw()
is_ci = bool(os.getenv("CI", None))
is_pypy = "__pypy__" in sys.builtin_module_names
wgpu_backend = get_wgpu_backend()
is_lavapipe = wgpu_backend.lower() == "cpu vulkan"
15 changes: 14 additions & 1 deletion tests_mem/test_gui_offscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Test creation of offscreen canvas windows.
"""

import gc
import weakref

import wgpu
import pytest
import testutils # noqa
from testutils import can_use_wgpu_lib, create_and_release
from testutils import can_use_wgpu_lib, create_and_release, is_pypy


if not can_use_wgpu_lib:
Expand Down Expand Up @@ -62,12 +65,22 @@ def test_release_canvas_context(n):
},
}

canvases = weakref.WeakSet()
for i in range(n):
c = WgpuCanvas()
canvases.add(c)
c.request_draw(make_draw_func_for_canvas(c))
c.draw()
yield c.get_context()

del c
gc.collect()
if is_pypy:
gc.collect() # Need a bit more on pypy :)

# Check that the canvas objects are really deleted
assert not canvases


TEST_FUNCS = [test_release_canvas_context]

Expand Down
3 changes: 3 additions & 0 deletions tests_mem/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _determine_can_use_pyside6():
can_use_glfw = _determine_can_use_glfw()
can_use_pyside6 = _determine_can_use_pyside6()
is_ci = bool(os.getenv("CI", None))
is_pypy = "__pypy__" in sys.builtin_module_names

TEST_ITERS = None

Expand All @@ -75,6 +76,8 @@ def clear_mem():
gc.collect()
time.sleep(0.001)
gc.collect()
if is_pypy:
gc.collect()


def get_counts():
Expand Down

0 comments on commit 202b526

Please sign in to comment.