From cd06140d7c0f0700886bf6cc660d335cc0536368 Mon Sep 17 00:00:00 2001 From: Alexander Piskun Date: Sat, 7 Oct 2023 16:12:33 +0300 Subject: [PATCH] more RUFF rules Signed-off-by: Alexander Piskun --- benchmarks/benchmark_decode.py | 2 +- benchmarks/benchmark_encode.py | 2 +- docs/conf.py | 2 +- examples/heif_dump_info.py | 2 +- examples/pillow_dump_info.py | 2 +- libheif/linux_build_libs.py | 6 +++--- pillow_heif/heif.py | 3 +-- pyproject.toml | 14 ++++++++------ tests/helpers.py | 4 +++- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/benchmarks/benchmark_decode.py b/benchmarks/benchmark_decode.py index aa044021..86729215 100644 --- a/benchmarks/benchmark_decode.py +++ b/benchmarks/benchmark_decode.py @@ -35,7 +35,7 @@ def measure_decode(image, n_iterations, op_type: int): cat_image_results = [] pug_image_results = [] large_image_results = [] - for _, v in enumerate(VERSIONS): + for v in VERSIONS: run(f"{sys.executable} -m pip install pillow-heif=={v}".split(), check=True) cat_image_results.append(measure_decode(cat_image_path, N_ITER_SMALL, operation_type)) pug_image_results.append(measure_decode(pug_image_path, N_ITER_SMALL, operation_type)) diff --git a/benchmarks/benchmark_encode.py b/benchmarks/benchmark_encode.py index 74e1c12b..eb2e5993 100644 --- a/benchmarks/benchmark_encode.py +++ b/benchmarks/benchmark_encode.py @@ -24,7 +24,7 @@ def measure_encode(image, n_iterations): la_image_results = [] l_image_results = [] pug_image_results = [] - for _, v in enumerate(VERSIONS): + for v in VERSIONS: run(f"{sys.executable} -m pip install pillow-heif=={v}".split(), check=True) sleep(N_ITER) rgba_image_results.append(measure_encode("RGBA", N_ITER)) diff --git a/docs/conf.py b/docs/conf.py index 2286eede..64c25653 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -98,7 +98,7 @@ def setup(app): # GitHub repo for sphinx-issues issues_github_path = "bigcat88/pillow_heif" -# 'short' – Suppress the leading module names of the typehints (ex. io.StringIO -> StringIO) +# 'short' - Suppress the leading module names of the typehints (ex. io.StringIO -> StringIO) autodoc_typehints_format = "short" # Do not sort members by alphabet. diff --git a/examples/heif_dump_info.py b/examples/heif_dump_info.py index a394554c..7b92a0a4 100644 --- a/examples/heif_dump_info.py +++ b/examples/heif_dump_info.py @@ -48,4 +48,4 @@ print("\t\tType:", block["type"]) print("\t\tcontent_type:", block["content_type"]) print("\t\tData length:", len(block["data"])) - print("") + print() diff --git a/examples/pillow_dump_info.py b/examples/pillow_dump_info.py index 0bc839c5..7ccf95b3 100644 --- a/examples/pillow_dump_info.py +++ b/examples/pillow_dump_info.py @@ -42,4 +42,4 @@ print("\t\tType:", block["type"]) print("\t\tcontent_type:", block["content_type"]) print("\t\tData length:", len(block["data"])) - print("") + print() diff --git a/libheif/linux_build_libs.py b/libheif/linux_build_libs.py index 37596504..60569dd8 100644 --- a/libheif/linux_build_libs.py +++ b/libheif/linux_build_libs.py @@ -71,7 +71,7 @@ def tool_check_version(name: str, min_version: str) -> bool: current_version = tuple(map(int, str(m_groups.groups()[0]).split("."))) min_version = tuple(map(int, min_version.split("."))) if current_version >= min_version: - print(f"Tool {name} with version {str(m_groups.groups()[0])} satisfy requirements.", flush=True) + print(f"Tool {name} with version {m_groups.groups()[0]} satisfy requirements.", flush=True) return True return False @@ -176,7 +176,7 @@ def build_lib_linux(url: str, name: str, musl: bool = False): run_print_if_error("make -j4".split()) run("mv libx265.a ../libx265_main10.a".split(), check=True) chdir("../12bit") - run(["cmake"] + ["./../source", "-DMAIN12=ON"] + cmake_high_bits, check=True) + run(["cmake", "./../source", "-DMAIN12=ON", *cmake_high_bits], check=True) run_print_if_error("make -j4".split()) run("mv libx265.a ../libx265_main12.a".split(), check=True) chdir("..") @@ -195,7 +195,7 @@ def build_lib_linux(url: str, name: str, musl: bool = False): _hide_build_process = False if musl: cmake_args += [f"-DCMAKE_INSTALL_LIBDIR={INSTALL_DIR_LIBS}/lib"] - run(["cmake"] + cmake_args, check=True) + run(["cmake", *cmake_args], check=True) print(f"{name} configured. building...", flush=True) if _hide_build_process: run_print_if_error("make -j4".split()) diff --git a/pillow_heif/heif.py b/pillow_heif/heif.py index 42a05b21..1b2be457 100644 --- a/pillow_heif/heif.py +++ b/pillow_heif/heif.py @@ -90,7 +90,7 @@ def to_pillow(self) -> Image.Image: :returns: :external:py:class:`~PIL.Image.Image` class created from an image. """ self.load() - image = Image.frombytes( + return Image.frombytes( self.mode, # noqa self.size, bytes(self.data), @@ -98,7 +98,6 @@ def to_pillow(self) -> Image.Image: self.mode, self.stride, ) - return image def load(self) -> None: """Method to decode image. diff --git a/pyproject.toml b/pyproject.toml index 3f77def5..36d75ba1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,19 +11,21 @@ preview = true [tool.ruff] line-length = 120 +preview = true target-version = "py38" -select = ["A", "B", "C", "D", "E", "F", "G", "I", "UP", "SIM", "Q", "W"] -extend-ignore = ["D107", "D105", "D203", "D213", "D401", "I001"] +select = ["A", "B", "C", "D", "E", "F", "FURB", "G", "I", "S", "SIM", "PERF", "PIE", "Q", "RET", "RUF", "UP" , "W"] +extend-ignore = ["D107", "D105", "D203", "D213", "D401", "E203", "I001", "RUF100"] [tool.ruff.per-file-ignores] "pillow_heif/__init__.py" = ["F401"] +"setup.py" = ["S"] [tool.ruff.extend-per-file-ignores] -"benchmarks/**/*.py" = ["D"] +"benchmarks/**/*.py" = ["D", "S603"] "docs/**/*.py" = ["D"] -"examples/**/*.py" = ["D"] -"libheif/**/*.py" = ["D"] -"tests/**/*.py" = ["B009", "D", "E402", "UP"] +"examples/**/*.py" = ["D", "PERF"] +"libheif/**/*.py" = ["D", "PERF", "S"] +"tests/**/*.py" = ["B009", "D", "E402", "PERF", "S", "UP"] [tool.ruff.mccabe] max-complexity = 16 diff --git a/tests/helpers.py b/tests/helpers.py index 64952ec6..0a221d87 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -126,7 +126,9 @@ def compare_images_fields(heif_image: Union[HeifImage], pillow_image: Image): compare_images_fields(heif, pillow) -def create_heif(size: tuple = None, thumb_boxes: list = None, n_images=1, **kwargs) -> BytesIO: +def create_heif( + size: Union[tuple, None] = None, thumb_boxes: Union[list, None] = None, n_images=1, **kwargs +) -> BytesIO: if size is None: size = (512, 512) if thumb_boxes is None: