Skip to content

Commit 948217d

Browse files
authored
more RUFF rules (#151)
Signed-off-by: Alexander Piskun <[email protected]>
1 parent c46fb7f commit 948217d

File tree

9 files changed

+20
-17
lines changed

9 files changed

+20
-17
lines changed

benchmarks/benchmark_decode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def measure_decode(image, n_iterations, op_type: int):
3535
cat_image_results = []
3636
pug_image_results = []
3737
large_image_results = []
38-
for _, v in enumerate(VERSIONS):
38+
for v in VERSIONS:
3939
run(f"{sys.executable} -m pip install pillow-heif=={v}".split(), check=True)
4040
cat_image_results.append(measure_decode(cat_image_path, N_ITER_SMALL, operation_type))
4141
pug_image_results.append(measure_decode(pug_image_path, N_ITER_SMALL, operation_type))

benchmarks/benchmark_encode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def measure_encode(image, n_iterations):
2424
la_image_results = []
2525
l_image_results = []
2626
pug_image_results = []
27-
for _, v in enumerate(VERSIONS):
27+
for v in VERSIONS:
2828
run(f"{sys.executable} -m pip install pillow-heif=={v}".split(), check=True)
2929
sleep(N_ITER)
3030
rgba_image_results.append(measure_encode("RGBA", N_ITER))

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def setup(app):
9898
# GitHub repo for sphinx-issues
9999
issues_github_path = "bigcat88/pillow_heif"
100100

101-
# 'short' Suppress the leading module names of the typehints (ex. io.StringIO -> StringIO)
101+
# 'short' - Suppress the leading module names of the typehints (ex. io.StringIO -> StringIO)
102102
autodoc_typehints_format = "short"
103103

104104
# Do not sort members by alphabet.

examples/heif_dump_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
print("\t\tType:", block["type"])
4949
print("\t\tcontent_type:", block["content_type"])
5050
print("\t\tData length:", len(block["data"]))
51-
print("")
51+
print()

examples/pillow_dump_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@
4242
print("\t\tType:", block["type"])
4343
print("\t\tcontent_type:", block["content_type"])
4444
print("\t\tData length:", len(block["data"]))
45-
print("")
45+
print()

libheif/linux_build_libs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def tool_check_version(name: str, min_version: str) -> bool:
7171
current_version = tuple(map(int, str(m_groups.groups()[0]).split(".")))
7272
min_version = tuple(map(int, min_version.split(".")))
7373
if current_version >= min_version:
74-
print(f"Tool {name} with version {str(m_groups.groups()[0])} satisfy requirements.", flush=True)
74+
print(f"Tool {name} with version {m_groups.groups()[0]} satisfy requirements.", flush=True)
7575
return True
7676
return False
7777

@@ -176,7 +176,7 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
176176
run_print_if_error("make -j4".split())
177177
run("mv libx265.a ../libx265_main10.a".split(), check=True)
178178
chdir("../12bit")
179-
run(["cmake"] + ["./../source", "-DMAIN12=ON"] + cmake_high_bits, check=True)
179+
run(["cmake", "./../source", "-DMAIN12=ON", *cmake_high_bits], check=True)
180180
run_print_if_error("make -j4".split())
181181
run("mv libx265.a ../libx265_main12.a".split(), check=True)
182182
chdir("..")
@@ -195,7 +195,7 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
195195
_hide_build_process = False
196196
if musl:
197197
cmake_args += [f"-DCMAKE_INSTALL_LIBDIR={INSTALL_DIR_LIBS}/lib"]
198-
run(["cmake"] + cmake_args, check=True)
198+
run(["cmake", *cmake_args], check=True)
199199
print(f"{name} configured. building...", flush=True)
200200
if _hide_build_process:
201201
run_print_if_error("make -j4".split())

pillow_heif/heif.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ def to_pillow(self) -> Image.Image:
9090
:returns: :external:py:class:`~PIL.Image.Image` class created from an image.
9191
"""
9292
self.load()
93-
image = Image.frombytes(
93+
return Image.frombytes(
9494
self.mode, # noqa
9595
self.size,
9696
bytes(self.data),
9797
"raw",
9898
self.mode,
9999
self.stride,
100100
)
101-
return image
102101

103102
def load(self) -> None:
104103
"""Method to decode image.

pyproject.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ preview = true
1111

1212
[tool.ruff]
1313
line-length = 120
14+
preview = true
1415
target-version = "py38"
15-
select = ["A", "B", "C", "D", "E", "F", "G", "I", "UP", "SIM", "Q", "W"]
16-
extend-ignore = ["D107", "D105", "D203", "D213", "D401", "I001"]
16+
select = ["A", "B", "C", "D", "E", "F", "FURB", "G", "I", "S", "SIM", "PERF", "PIE", "Q", "RET", "RUF", "UP" , "W"]
17+
extend-ignore = ["D107", "D105", "D203", "D213", "D401", "E203", "I001", "RUF100"]
1718

1819
[tool.ruff.per-file-ignores]
1920
"pillow_heif/__init__.py" = ["F401"]
21+
"setup.py" = ["S"]
2022

2123
[tool.ruff.extend-per-file-ignores]
22-
"benchmarks/**/*.py" = ["D"]
24+
"benchmarks/**/*.py" = ["D", "S603"]
2325
"docs/**/*.py" = ["D"]
24-
"examples/**/*.py" = ["D"]
25-
"libheif/**/*.py" = ["D"]
26-
"tests/**/*.py" = ["B009", "D", "E402", "UP"]
26+
"examples/**/*.py" = ["D", "PERF"]
27+
"libheif/**/*.py" = ["D", "PERF", "S"]
28+
"tests/**/*.py" = ["B009", "D", "E402", "PERF", "S", "UP"]
2729

2830
[tool.ruff.mccabe]
2931
max-complexity = 16

tests/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ def compare_images_fields(heif_image: Union[HeifImage], pillow_image: Image):
126126
compare_images_fields(heif, pillow)
127127

128128

129-
def create_heif(size: tuple = None, thumb_boxes: list = None, n_images=1, **kwargs) -> BytesIO:
129+
def create_heif(
130+
size: Union[tuple, None] = None, thumb_boxes: Union[list, None] = None, n_images=1, **kwargs
131+
) -> BytesIO:
130132
if size is None:
131133
size = (512, 512)
132134
if thumb_boxes is None:

0 commit comments

Comments
 (0)