Skip to content

Commit

Permalink
fix: make python 3.9 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
beatreichenbach committed Jun 2, 2023
1 parent 68df2a8 commit d188d9e
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies = [
"sentry-sdk",
"python-slugify[unidecode]"
]
requires-python = ">=3.10"
requires-python = ">=3.9"
license = {text = "MIT"}
readme = "README.md"

Expand Down
4 changes: 2 additions & 2 deletions realflare/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from realflare.gui import app as gui_app


def argument_parser():
def argument_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog='Realflare',
description='Physically-Based Lens Flares',
Expand Down Expand Up @@ -62,7 +62,7 @@ def argument_parser():
return parser


def main():
def main() -> None:
sentry.init()

parser = argument_parser()
Expand Down
7 changes: 4 additions & 3 deletions realflare/api/engine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import logging
import os
from collections import OrderedDict
Expand Down Expand Up @@ -54,7 +55,7 @@ def __init__(self, device: str = '', parent: QtCore.QObject | None = None) -> No
self._init_renderers()
self._init_tasks()

def _init_renderers(self):
def _init_renderers(self) -> None:
self.renderers: dict[RenderElement, Callable] = OrderedDict()
self.renderers[STARBURST_APERTURE] = self.starburst_aperture
self.renderers[GHOST_APERTURE] = self.ghost_aperture
Expand All @@ -63,7 +64,7 @@ def _init_renderers(self):
self.renderers[FLARE] = self.flare
self.renderers[DIAGRAM] = self.diagram

def _init_tasks(self):
def _init_tasks(self) -> None:
self.aperture_task = ApertureTask(self.queue)
self.ghost_task = GhostTask(self.queue)
self.starburst_task = StarburstTask(self.queue)
Expand Down Expand Up @@ -256,5 +257,5 @@ def colorspace_processor(self, colorspace: str) -> OCIO.CPUProcessor | None:
return cpu_processor


def clear_cache():
def clear_cache() -> None:
cl.tools.clear_first_arg_caches()
1 change: 1 addition & 0 deletions realflare/api/glass.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import os
import yaml

Expand Down
3 changes: 2 additions & 1 deletion realflare/api/tasks/aperture.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import logging
from functools import lru_cache

Expand All @@ -23,7 +24,7 @@ def __init__(self, queue: cl.CommandQueue) -> None:
self.kernel = None
self.build()

def build(self, *args, **kwargs):
def build(self, *args, **kwargs) -> None:
self.source = self.read_source_file('aperture.cl')
super().build()
self.kernel = cl.Kernel(self.program, 'aperture')
Expand Down
10 changes: 6 additions & 4 deletions realflare/api/tasks/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@


class DiagramTask(OpenCL):
def __init__(self, queue):
def __init__(self, queue) -> None:
super().__init__(queue)
self.raytracing_task = RaytracingTask(queue)
self.kernels = {}
self.scale = 1
self.build()

def build(self, *args, **kwargs):
def build(self, *args, **kwargs) -> None:
self.source = ''
self.register_dtype('Ray', ray_dtype)
self.register_dtype('LensElement', lens_element_dtype)
Expand Down Expand Up @@ -90,7 +90,9 @@ def lenses(self, image: Image, lens: Flare.Lens) -> None:
)

@timer
def intersections(self, image: Image, intersections: Buffer, column_offset: int):
def intersections(
self, image: Image, intersections: Buffer, column_offset: int
) -> None:
# rebuild kernel
if self.rebuild:
self.build()
Expand Down Expand Up @@ -137,7 +139,7 @@ def intersections(self, image: Image, intersections: Buffer, column_offset: int)
region=(w, h),
)

def run(self, project: Project, intersections: Buffer):
def run(self, project: Project, intersections: Buffer) -> Image:
# lenses
resolution = project.render.diagram.resolution
image = self.update_image(resolution, flags=cl.mem_flags.READ_WRITE)
Expand Down
2 changes: 2 additions & 0 deletions realflare/api/tasks/opencl.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from importlib.resources import files
import os
import typing
Expand Down
7 changes: 4 additions & 3 deletions realflare/api/tasks/rasterizing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from collections.abc import Iterable
from functools import lru_cache

Expand All @@ -22,7 +23,7 @@
BATCH_PRIMITIVE_COUNT = 255


def triangle_vertexes(n):
def triangle_vertexes(n) -> list[tuple[int, int, int]]:
# returns a list of tuples (vertex indexes per triangle)
# n is the amount of rows of the vertex grid
# v1, v2, v3 are the vertexes making up a triangle
Expand Down Expand Up @@ -58,12 +59,12 @@ def quad_vertexes(n: int) -> list[tuple[int, int, int, int]]:
class RasterizingTask(OpenCL):
bin_size = 32

def __init__(self, queue):
def __init__(self, queue) -> None:
super().__init__(queue)
self.kernels = {}
self.build()

def build(self, *args, **kwargs):
def build(self, *args, **kwargs) -> None:
self.source = ''
self.register_dtype('Ray', ray_dtype)
self.register_dtype('Vertex', vertex_dtype)
Expand Down
8 changes: 3 additions & 5 deletions realflare/api/tasks/raytracing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import logging
from functools import lru_cache

Expand Down Expand Up @@ -41,7 +42,7 @@ def __init__(self, queue: cl.CommandQueue) -> None:
self.kernel = None
self.build()

def build(self, *args, **kwargs):
def build(self, *args, **kwargs) -> None:
self.source = ''
self.register_dtype('Ray', ray_dtype)
self.register_dtype('LensElement', lens_element_dtype)
Expand Down Expand Up @@ -101,7 +102,6 @@ def update_lens_elements(
array = np.zeros(len(lens_elements), dtype)
offset = 0
for i, lens_element in enumerate(lens_elements):

array[i]['radius'] = lens_element.radius
array[i]['distance'] = lens_element.distance
array[i]['ior'] = lens_element.refractive_index
Expand Down Expand Up @@ -227,7 +227,6 @@ def raytrace(
wavelength_count: int,
path_indexes: tuple[int] | None = None,
) -> Buffer | None:

# rebuild kernel
if self.rebuild:
self.build()
Expand Down Expand Up @@ -305,7 +304,7 @@ def __init__(self, queue: cl.CommandQueue) -> None:
self.kernel = None
self.build()

def build(self, *args, **kwargs):
def build(self, *args, **kwargs) -> None:
self.source = ''
self.register_dtype('Ray', ray_dtype)
self.register_dtype('LensElement', lens_element_dtype)
Expand All @@ -328,7 +327,6 @@ def raytrace(
wavelength_count: int,
path_indexes: tuple[int] | None = None,
) -> Buffer | None:

# rebuild kernel
if self.rebuild:
self.build()
Expand Down
2 changes: 1 addition & 1 deletion realflare/api/tasks/starburst.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, queue: cl.CommandQueue) -> None:
self.kernel = None
self.build()

def build(self, *args, **kwargs):
def build(self, *args, **kwargs) -> None:
self.source = f'__constant int LAMBDA_MIN = {LAMBDA_MIN};\n'
self.source += f'__constant int LAMBDA_MAX = {LAMBDA_MAX};\n'
self.source += f'__constant int LAMBDA_MID = {LAMBDA_MID};\n'
Expand Down
3 changes: 2 additions & 1 deletion realflare/cli/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import dataclasses
import json
import logging
Expand Down Expand Up @@ -72,7 +73,7 @@ def update_project(project: Project, kwargs: dict, frame_time: float):
return project


def exec_(parser: ArgumentParser):
def exec_(parser: ArgumentParser) -> None:
args = parser.parse_args(sys.argv[1:])

logging.basicConfig(level=args.log)
Expand Down
2 changes: 2 additions & 0 deletions realflare/gui/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import copy
import inspect
import logging
Expand Down
3 changes: 2 additions & 1 deletion realflare/gui/lensmodeleditor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import dataclasses
import logging
import os
Expand Down Expand Up @@ -94,7 +95,7 @@ def __init__(self, parent: QtWidgets.QWidget | None = None) -> None:

self._init_editor()

def _init_editor(self):
def _init_editor(self) -> None:
# lens model
model_group = self.add_group('model', style=CollapsibleBox.Style.SIMPLE)
model_group.create_hierarchy = False
Expand Down
16 changes: 8 additions & 8 deletions realflare/gui/parameters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging
from __future__ import annotations
import os
import random
from functools import partial
Expand Down Expand Up @@ -58,7 +58,7 @@ def _init_tabs(self) -> None:
)
self.tabs = tab_widget.tabs

def _init_output_group(self):
def _init_output_group(self) -> None:
output_group = self.add_group(
'output', collapsible=True, style=CollapsibleBox.Style.SIMPLE
)
Expand Down Expand Up @@ -89,7 +89,7 @@ def _init_output_group(self):
parm.tooltip = 'Colorspace from the OCIO config.\nFor example: ACES - ACEScg'
output_group.add_parameter(parm)

def _init_flare_group(self):
def _init_flare_group(self) -> None:
self.tabs['lens_flare'].create_hierarchy = False

resource_dir = storage.decode_path('$RES')
Expand Down Expand Up @@ -429,7 +429,7 @@ def _init_flare_group(self):
)
ghost_group.add_parameter(parm)

def _init_rendering_group(self):
def _init_rendering_group(self) -> None:
# renderer
renderer_group = self.tabs['render'].add_group(
'renderer', collapsible=True, style=CollapsibleBox.Style.BUTTON
Expand Down Expand Up @@ -554,7 +554,7 @@ def _init_rendering_group(self):
parm.menu = opencl.devices()
system_group.add_parameter(parm)

def _init_diagram_group(self):
def _init_diagram_group(self) -> None:
diagram_renderer_group = self.tabs['diagram'].add_group(
'renderer', collapsible=True, style=CollapsibleBox.Style.BUTTON
)
Expand Down Expand Up @@ -592,7 +592,7 @@ def _init_diagram_group(self):
parm.slider_max = 20
diagram_rays_group.add_parameter(parm)

def _init_debug_group(self):
def _init_debug_group(self) -> None:
flare_group = self.tabs['debug'].add_group(
'flare', collapsible=True, style=CollapsibleBox.Style.BUTTON
)
Expand Down Expand Up @@ -676,7 +676,7 @@ def _init_actions(self) -> None:
#
# self.update_editor(new_config)

def project(self):
def project(self) -> Project:
values = self.values()

values['render']['grid_count'] = values['render']['grid_subdivisions'] + 1
Expand All @@ -686,7 +686,7 @@ def project(self):

return project

def randomize_coatings(self):
def randomize_coatings(self) -> None:
project = self.project()

# TODO: clean up...
Expand Down
1 change: 1 addition & 0 deletions realflare/gui/presetbrowser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import dataclasses
import logging
import sys
Expand Down
5 changes: 3 additions & 2 deletions realflare/gui/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import logging

from PySide2 import QtWidgets, QtGui, QtCore
Expand Down Expand Up @@ -82,14 +83,14 @@ def set_settings(self, settings: Settings, attr: str = 'value') -> None:


class SettingsDialog(QtWidgets.QDialog):
def __init__(self, parent: QtWidgets.QWidget | None = None):
def __init__(self, parent: QtWidgets.QWidget | None = None) -> None:
super().__init__(parent)

self._init_ui()
self.setWindowTitle('Settings')
self.resize(QtCore.QSize(800, 600))

def _init_ui(self):
def _init_ui(self) -> None:
self.setLayout(QtWidgets.QVBoxLayout())

# editor
Expand Down
3 changes: 2 additions & 1 deletion realflare/gui/viewer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations
import logging

import numpy as np
from PySide2 import QtWidgets, QtCore
import PyOpenColorIO as OCIO
from PySide2 import QtWidgets, QtCore

from realflare.api.data import RenderElement

Expand Down
2 changes: 1 addition & 1 deletion realflare/sentry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from realflare.storage import Storage


def init():
def init() -> None:
storage = Storage()

if storage.settings.sentry:
Expand Down
6 changes: 4 additions & 2 deletions realflare/storage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import annotations

import json
import logging
import os
import re
import shutil
from dataclasses import dataclass, field
from importlib.resources import files
from typing import Any
from typing import Any, Union

from qt_extensions.typeutils import cast, cast_basic

Expand Down Expand Up @@ -43,7 +45,7 @@ def write_data(self, data: Any, path: str) -> None:

@dataclass()
class Settings:
sentry: bool | None = None
sentry: Union[bool, None] = None
ocio: str = ''
clear_log_on_render: bool = True

Expand Down
4 changes: 2 additions & 2 deletions realflare/update.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import logging
import sys

Expand All @@ -10,7 +11,6 @@

class UpdateProcess(Process):
def run(self) -> None:

args = [
sys.executable,
'-m',
Expand Down Expand Up @@ -89,7 +89,7 @@ def start(self) -> None:
def update_log(self, record: logging.LogRecord) -> None:
self.add_record(record)

def exec_(self):
def exec_(self) -> None:
self.setWindowModality(QtGui.Qt.ApplicationModal)
self.show()

Expand Down
Loading

0 comments on commit d188d9e

Please sign in to comment.