From f527bc440d4473701f59b6f08ed48df5754ecad4 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sat, 14 Oct 2023 19:33:59 +0200 Subject: [PATCH] Bump pillow + minor code cleanup --- moderngl_window/context/base/keys.py | 178 ++++++++++++------------ moderngl_window/context/base/window.py | 22 +-- moderngl_window/loaders/base.py | 3 +- moderngl_window/loaders/scene/gltf2.py | 8 +- moderngl_window/loaders/texture/cube.py | 2 +- moderngl_window/meta/base.py | 4 +- pyproject.toml | 8 +- setup.cfg | 7 + 8 files changed, 120 insertions(+), 112 deletions(-) create mode 100644 setup.cfg diff --git a/moderngl_window/context/base/keys.py b/moderngl_window/context/base/keys.py index 6baff8f4..8fad555d 100644 --- a/moderngl_window/context/base/keys.py +++ b/moderngl_window/context/base/keys.py @@ -1,12 +1,12 @@ # flake8: noqa E741 - +from typing import Any class KeyModifiers: """Namespace for storing key modifiers""" - shift = False - ctrl = False - alt = False + shift: Any = False + ctrl: Any = False + alt: Any = False def __repr__(self): return str(self) @@ -24,94 +24,94 @@ class BaseKeys: """ # Fallback press/release action when window libraries don't have this - ACTION_PRESS = "ACTION_PRESS" - ACTION_RELEASE = "ACTION_RELEASE" + ACTION_PRESS: Any = "ACTION_PRESS" + ACTION_RELEASE: Any = "ACTION_RELEASE" - ESCAPE = None - SPACE = None - ENTER = None - PAGE_UP = None - PAGE_DOWN = None - LEFT = None - RIGHT = None - UP = None - DOWN = None + ESCAPE: Any = "undefined" + SPACE: Any = "undefined" + ENTER: Any = "undefined" + PAGE_UP: Any = "undefined" + PAGE_DOWN: Any = "undefined" + LEFT: Any = "undefined" + RIGHT: Any = "undefined" + UP: Any = "undefined" + DOWN: Any = "undefined" - TAB = None - COMMA = None - MINUS = None - PERIOD = None - SLASH = None - SEMICOLON = None - EQUAL = None - LEFT_BRACKET = None - RIGHT_BRACKET = None - BACKSLASH = None - BACKSPACE = None - INSERT = None - DELETE = None - HOME = None - END = None - CAPS_LOCK = None + TAB: Any = "undefined" + COMMA: Any = "undefined" + MINUS: Any = "undefined" + PERIOD: Any = "undefined" + SLASH: Any = "undefined" + SEMICOLON: Any = "undefined" + EQUAL: Any = "undefined" + LEFT_BRACKET: Any = "undefined" + RIGHT_BRACKET: Any = "undefined" + BACKSLASH: Any = "undefined" + BACKSPACE: Any = "undefined" + INSERT: Any = "undefined" + DELETE: Any = "undefined" + HOME: Any = "undefined" + END: Any = "undefined" + CAPS_LOCK: Any = "undefined" - F1 = None - F2 = None - F3 = None - F4 = None - F5 = None - F6 = None - F7 = None - F8 = None - F9 = None - F10 = None - F11 = None - F12 = None + F1: Any = "undefined" + F2: Any = "undefined" + F3: Any = "undefined" + F4: Any = "undefined" + F5: Any = "undefined" + F6: Any = "undefined" + F7: Any = "undefined" + F8: Any = "undefined" + F9: Any = "undefined" + F10: Any = "undefined" + F11: Any = "undefined" + F12: Any = "undefined" - NUMBER_0 = None - NUMBER_1 = None - NUMBER_2 = None - NUMBER_3 = None - NUMBER_4 = None - NUMBER_5 = None - NUMBER_6 = None - NUMBER_7 = None - NUMBER_8 = None - NUMBER_9 = None + NUMBER_0: Any = "undefined" + NUMBER_1: Any = "undefined" + NUMBER_2: Any = "undefined" + NUMBER_3: Any = "undefined" + NUMBER_4: Any = "undefined" + NUMBER_5: Any = "undefined" + NUMBER_6: Any = "undefined" + NUMBER_7: Any = "undefined" + NUMBER_8: Any = "undefined" + NUMBER_9: Any = "undefined" - NUMPAD_0 = None - NUMPAD_1 = None - NUMPAD_2 = None - NUMPAD_3 = None - NUMPAD_4 = None - NUMPAD_5 = None - NUMPAD_6 = None - NUMPAD_7 = None - NUMPAD_8 = None - NUMPAD_9 = None + NUMPAD_0: Any = "undefined" + NUMPAD_1: Any = "undefined" + NUMPAD_2: Any = "undefined" + NUMPAD_3: Any = "undefined" + NUMPAD_4: Any = "undefined" + NUMPAD_5: Any = "undefined" + NUMPAD_6: Any = "undefined" + NUMPAD_7: Any = "undefined" + NUMPAD_8: Any = "undefined" + NUMPAD_9: Any = "undefined" - A = None - B = None - C = None - D = None - E = None - F = None - G = None - H = None - I = None - J = None - K = None - L = None - M = None - N = None - O = None - P = None - Q = None - R = None - S = None - T = None - U = None - V = None - W = None - X = None - Y = None - Z = None + A: Any = "undefined" + B: Any = "undefined" + C: Any = "undefined" + D: Any = "undefined" + E: Any = "undefined" + F: Any = "undefined" + G: Any = "undefined" + H: Any = "undefined" + I: Any = "undefined" + J: Any = "undefined" + K: Any = "undefined" + L: Any = "undefined" + M: Any = "undefined" + N: Any = "undefined" + O: Any = "undefined" + P: Any = "undefined" + Q: Any = "undefined" + R: Any = "undefined" + S: Any = "undefined" + T: Any = "undefined" + U: Any = "undefined" + V: Any = "undefined" + W: Any = "undefined" + X: Any = "undefined" + Y: Any = "undefined" + Z: Any = "undefined" diff --git a/moderngl_window/context/base/window.py b/moderngl_window/context/base/window.py index cf158a97..49ace314 100644 --- a/moderngl_window/context/base/window.py +++ b/moderngl_window/context/base/window.py @@ -70,7 +70,7 @@ class BaseWindow: """ #: Name of the window. For example ``pyglet``, ``glfw`` - name = None + name = "base" #: Window specific key constants keys = BaseKeys #: Mouse button enum @@ -1218,7 +1218,7 @@ def load_texture_2d( flip_x=False, flip_y=True, mipmap=False, - mipmap_levels: Tuple[int, int] = None, + mipmap_levels: Optional[Tuple[int, int]] = None, anisotropy=1.0, **kwargs ) -> moderngl.Texture: @@ -1262,7 +1262,7 @@ def load_texture_array( layers: int = 0, flip=True, mipmap=False, - mipmap_levels: Tuple[int, int] = None, + mipmap_levels: Optional[Tuple[int, int]] = None, anisotropy=1.0, **kwargs ) -> moderngl.TextureArray: @@ -1307,17 +1307,17 @@ def load_texture_array( def load_texture_cube( self, - pos_x: str = None, - pos_y: str = None, - pos_z: str = None, - neg_x: str = None, - neg_y: str = None, - neg_z: str = None, + pos_x: str = "", + pos_y: str = "", + pos_z: str = "", + neg_x: str = "", + neg_y: str = "", + neg_z: str = "", flip=False, flip_x=False, flip_y=False, mipmap=False, - mipmap_levels: Tuple[int, int] = None, + mipmap_levels: Optional[Tuple[int, int]] = None, anisotropy=1.0, **kwargs ) -> moderngl.TextureCube: @@ -1373,7 +1373,7 @@ def load_program( fragment_shader=None, tess_control_shader=None, tess_evaluation_shader=None, - defines: dict = None, + defines: Optional[dict] = None, varyings: Optional[List[str]] = None, ) -> moderngl.Program: """Loads a shader program. diff --git a/moderngl_window/loaders/base.py b/moderngl_window/loaders/base.py index e1e5142b..7ab49e63 100644 --- a/moderngl_window/loaders/base.py +++ b/moderngl_window/loaders/base.py @@ -11,8 +11,7 @@ class BaseLoader: """Base loader class for all resources""" - - kind = None + kind = "unknown" """ The kind of resource this loaded supports. This can be used when file extensions is not enough diff --git a/moderngl_window/loaders/scene/gltf2.py b/moderngl_window/loaders/scene/gltf2.py index 8dc65494..9e1f39e2 100644 --- a/moderngl_window/loaders/scene/gltf2.py +++ b/moderngl_window/loaders/scene/gltf2.py @@ -387,9 +387,7 @@ def version(self): def check_version(self, required="2.0"): if not self.version == required: - msg = "GLTF Format version is not 2.0. Version states '{}' in file {}".format( - self.version, self.path, - ) + msg = f"GLTF Format version is not 2.0. Version states '{self.version}' in file {self.path}" raise ValueError(msg) def check_extensions(self, supported): @@ -400,12 +398,12 @@ def check_extensions(self, supported): if self.data.get("extensionsRequired"): for ext in self.data.get("extensionsRequired"): if ext not in supported: - raise ValueError("Extension {} not supported".format(ext)) + raise ValueError(f"Extension {ext} not supported") if self.data.get("extensionsUsed"): for ext in self.data.get("extensionsUsed"): if ext not in supported: - raise ValueError("Extension {} not supported".format(ext)) + raise ValueError("Extension {ext} not supported") def buffers_exist(self): """Checks if the bin files referenced exist""" diff --git a/moderngl_window/loaders/texture/cube.py b/moderngl_window/loaders/texture/cube.py index 2c1b0fc0..715079af 100644 --- a/moderngl_window/loaders/texture/cube.py +++ b/moderngl_window/loaders/texture/cube.py @@ -55,7 +55,7 @@ def _load_face(self, path: str, face_name: str = None): Tuple[int, bytes]: number of components, byte data """ if not path: - raise ImproperlyConfigured("{} texture face not supplied".format(face_name)) + raise ImproperlyConfigured(f"{face_name} texture face not supplied") image = self._load_texture(path) components, data = image_data(image) diff --git a/moderngl_window/meta/base.py b/moderngl_window/meta/base.py index a05f433d..3a43502d 100644 --- a/moderngl_window/meta/base.py +++ b/moderngl_window/meta/base.py @@ -8,9 +8,9 @@ class ResourceDescription: This class can be extended to add more specific properties. """ - default_kind = None # The default kind of loader + default_kind = "" # The default kind of loader """str: The default kind for this resource type""" - resource_type = None # What resource type is described + resource_type = "" # What resource type is described """str: A unique identifier for the resource type""" def __init__(self, **kwargs): diff --git a/pyproject.toml b/pyproject.toml index 9e222eb4..ce1a5f33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ dependencies = [ "pyglet~=2.0.0", "numpy>=1.16,<2", "pyrr>=0.10.3,<1", - "Pillow>=9,<10", + "Pillow~=10.0.1", ] [tool.setuptools.packages.find] @@ -77,8 +77,8 @@ ignore = [ "W503", "C901", ] -max-complexity = 10 max-line-length = 120 +max-complexity = 10 exclude = [ "tests/", "docs/", @@ -131,3 +131,7 @@ ignore_missing_imports = true [[tool.mypy.overrides]] module = "pyrr.*" ignore_missing_imports = true + +[[tool.mypy.overrides]] +module = "trimesh.*" +ignore_missing_imports = true diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..96e05fc4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,7 @@ +# All values are merged into pyproject.toml, but +# as of flake8 6.1 it still doesn't read config +# from the tool.flake8 namespace in pyproject.toml + +[flake8] +max-line-length = 120 +max-complexity = 10