Skip to content

Commit

Permalink
more RUFF rules (#151)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed Oct 7, 2023
1 parent c46fb7f commit 948217d
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion benchmarks/benchmark_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmark_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/heif_dump_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion examples/pillow_dump_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions libheif/linux_build_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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("..")
Expand All @@ -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())
Expand Down
3 changes: 1 addition & 2 deletions pillow_heif/heif.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ 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),
"raw",
self.mode,
self.stride,
)
return image

def load(self) -> None:
"""Method to decode image.
Expand Down
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 948217d

Please sign in to comment.