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

Switch to ruff #12

Merged
merged 4 commits into from
Jan 10, 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
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ jobs:
- name: Install dev dependencies
run: |
python -m pip install --upgrade pip
pip install -U black flake8 flake8-black pep8-naming
- name: Flake8
pip install -U ruff
- name: Ruff
run: |
flake8 .
set -ex
ruff format --check .
ruff .

lint-wheel:
name: Check Wheel
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ This code is distributed under the 2-clause BSD license.
* Clone the repo.
* Create a virtual environment using `python -m venv .venv`
* Install using `.venv/bin/pip install -e .[dev]`
* Use `.venv/bin/black .` to apply autoformatting.
* Use `.venv/bin/flake8 .` to check for flake errors.
* Use `.venv/bin/ruff format .` to apply autoformatting.
* Use `.venv/bin/ruff --fix .` to run the linter.
* Use `.venv/bin/pytest .` to run the tests.
* Use `.venv/bin/pip wheel -w dist --no-deps .` to build a wheel.

Expand Down
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy as np
import pytest


# Enable importing testutils from all test scripts
sys.path.insert(0, os.path.abspath(os.path.join(__file__, "..", "tests")))

Expand Down
2 changes: 1 addition & 1 deletion examples/shadertoy_glsl_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
Z(i.x / 100)
}

""" # noqa
"""
shader = Shadertoy(shader_code)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/shadertoy_glsl_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@



""" # noqa
"""
shader = Shadertoy(shader_code)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/shadertoy_glsl_fuji.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@

}

""" # noqa
"""
shader = Shadertoy(shader_code)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/shadertoy_glsl_inercia.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
}


""" # noqa
"""
shader = Shadertoy(shader_code)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/shadertoy_glsl_mouse_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
fragColor = vec4( col, 1.0 );
}

""" # noqa
"""
shader = Shadertoy(shader_code)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/shadertoy_glsl_sdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@
}


""" # noqa
"""
shader = Shadertoy(shader_code)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/shadertoy_glsl_sea.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
fragColor = vec4(col, 1.0);
}

""" # noqa
"""
shader = Shadertoy(shader_code)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/shadertoy_glsl_stone.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
fragColor = vec4(color,1.0);
}

""" # noqa
"""
shader = Shadertoy(shader_code)

if __name__ == "__main__":
Expand Down
12 changes: 5 additions & 7 deletions examples/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Test that the examples run without error.
"""

import os
import importlib
import os
import runpy
import sys
import time
Expand All @@ -13,18 +13,16 @@
import numpy as np
import pytest


from tests.testutils import (
ROOT,
can_use_wgpu_lib,
wgpu_backend,
is_lavapipe,
diffs_dir,
find_examples,
ROOT,
is_lavapipe,
screenshots_dir,
diffs_dir,
wgpu_backend,
)


if not can_use_wgpu_lib:
pytest.skip("Skipping tests that need the wgpu lib", allow_module_level=True)

Expand Down
25 changes: 19 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ Repository = "https://github.com/pygfx/shadertoy"

[project.optional-dependencies]
dev = [
"requests",
"numpy",
"pytest",
"black",
"flake8",
"flake8-black",
"pep8-naming",
"sphinx",
"ruff",
"imageio",
"wheel",
"setuptools",
Expand All @@ -41,3 +36,21 @@ dev = [
[tool.setuptools.dynamic]
version = {attr = "wgpu_shadertoy.__version__"}
readme = {file = ["README.md"]}

[tool.ruff.lint]
select = [
"E4",
"E5",
"E7",
"E9",
"F", # Pyflakes (default)
"I", # isort imports
"N", # pep8-naming
"RUF", # ruff
]
extend-ignore = [
"E501", # line too long
]

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
30 changes: 0 additions & 30 deletions setup.cfg

This file was deleted.

4 changes: 2 additions & 2 deletions tests/renderutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@


import ctypes
import numpy as np

import wgpu.backends.wgpu_native # noqa
import numpy as np
import wgpu.backends.wgpu_native


def upload_to_texture(device, texture, data, nx, ny, nz):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_textures.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from pytest import skip
from testutils import can_use_wgpu_lib


if not can_use_wgpu_lib:
skip("Skipping tests that need the wgpu lib", allow_module_level=True)


def test_textures_wgsl():
# Import here, because it imports the wgpu.gui.auto
from wgpu_shadertoy import Shadertoy, ShadertoyChannel # noqa
from wgpu_shadertoy import Shadertoy, ShadertoyChannel

shader_code_wgsl = """
fn shader_main(frag_coord: vec2<f32>) -> vec4<f32>{
Expand Down Expand Up @@ -46,7 +45,7 @@ def test_textures_wgsl():

def test_textures_glsl():
# Import here, because it imports the wgpu.gui.auto
from wgpu_shadertoy import Shadertoy, ShadertoyChannel # noqa
from wgpu_shadertoy import Shadertoy, ShadertoyChannel

shader_code = """
void mainImage( out vec4 fragColor, in vec2 fragCoord )
Expand Down
9 changes: 4 additions & 5 deletions tests/test_util_shadertoy.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from pytest import skip
from testutils import can_use_wgpu_lib


if not can_use_wgpu_lib:
skip("Skipping tests that need the wgpu lib", allow_module_level=True)


def test_shadertoy_wgsl():
# Import here, because it imports the wgpu.gui.auto
from wgpu_shadertoy import Shadertoy # noqa
from wgpu_shadertoy import Shadertoy

shader_code = """
fn shader_main(frag_coord: vec2<f32>) -> vec4<f32> {
Expand All @@ -33,7 +32,7 @@ def test_shadertoy_wgsl():

def test_shadertoy_glsl():
# Import here, because it imports the wgpu.gui.auto
from wgpu_shadertoy import Shadertoy # noqa
from wgpu_shadertoy import Shadertoy

shader_code = """
void shader_main(out vec4 fragColor, vec2 frag_coord) {
Expand All @@ -58,7 +57,7 @@ def test_shadertoy_glsl():

def test_shadertoy_offscreen():
# Import here, because it imports the wgpu.gui.auto
from wgpu_shadertoy import Shadertoy # noqa
from wgpu_shadertoy import Shadertoy

shader_code = """
void shader_main(out vec4 fragColor, vec2 frag_coord) {
Expand All @@ -82,7 +81,7 @@ def test_shadertoy_offscreen():

def test_shadertoy_snapshot():
# Import here, because it imports the wgpu.gui.auto
from wgpu_shadertoy import Shadertoy # noqa
from wgpu_shadertoy import Shadertoy

shader_code = """
void shader_main(out vec4 fragColor, vec2 frag_coord) {
Expand Down
5 changes: 2 additions & 3 deletions tests/testutils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import logging
import os
import re
import sys
import logging
import subprocess
import sys
from io import StringIO
from pathlib import Path

from wgpu.utils import get_default_device # noqa


ROOT = Path(__file__).parent.parent # repo root
examples_dir = ROOT / "examples"
screenshots_dir = examples_dir / "screenshots"
Expand Down
1 change: 0 additions & 1 deletion wgpu_shadertoy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .shadertoy import Shadertoy, ShadertoyChannel


__version__ = "0.1.0"
version_info = tuple(map(int, __version__.split(".")))
11 changes: 6 additions & 5 deletions wgpu_shadertoy/shadertoy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import time
import ctypes
import collections
import ctypes
import os
import time

import wgpu
from wgpu.gui.auto import WgpuCanvas, run
from wgpu.gui.offscreen import WgpuCanvas as OffscreenCanvas, run as run_offscreen
from wgpu.gui.offscreen import WgpuCanvas as OffscreenCanvas
from wgpu.gui.offscreen import run as run_offscreen

vertex_code_glsl = """#version 450 core

Expand Down Expand Up @@ -355,7 +356,7 @@ def __init__(
)

self._shader_code = shader_code
self._uniform_data["resolution"] = resolution + (1,)
self._uniform_data["resolution"] = (*resolution, 1)

# if no explicit offscreen option was given
# inherit wgpu-py force offscreen option
Expand Down Expand Up @@ -395,7 +396,7 @@ def shader_type(self):
raise ValueError("Invalid shader code.")

def _prepare_render(self):
import wgpu.backends.auto # noqa
import wgpu.backends.auto

if self._offscreen:
self._canvas = OffscreenCanvas(
Expand Down
Loading