From bd32c73f4a6b99705598bdf5fbd6b6701c543821 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:38:45 +0300 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#157) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/tox-dev/pyproject-fmt: 1.2.0 → 1.3.0](https://github.com/tox-dev/pyproject-fmt/compare/1.2.0...1.3.0) - [github.com/astral-sh/ruff-pre-commit: v0.1.1 → v0.1.3](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.1...v0.1.3) * fixed new `ruff` warnings Signed-off-by: Alexander Piskun --------- Signed-off-by: Alexander Piskun Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alexander Piskun --- .github/transform_to-pi_heif.py | 6 +++--- .pre-commit-config.yaml | 4 ++-- setup.py | 3 +-- tests/leaks_test.py | 9 +++------ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/transform_to-pi_heif.py b/.github/transform_to-pi_heif.py index 8a3f523a..e2dfc44f 100644 --- a/.github/transform_to-pi_heif.py +++ b/.github/transform_to-pi_heif.py @@ -1,6 +1,7 @@ """Script to transform the project to `pi-heif` in place. Should be used only with GA Actions.""" import os +import pathlib DEV_NAME_ADD = "" # This is only for debugging purposes of this script. @@ -22,9 +23,8 @@ files_list += [os.path.join(dir_name, x)] for file_name in files_list: - with open(file_name) as file: - data = file.read() - modified_data = data.replace("pillow_heif", "pi_heif") + data = pathlib.Path(file_name).read_text(encoding="utf-8") + modified_data = data.replace("pillow_heif", "pi_heif") if modified_data != data: with open(file_name + DEV_NAME_ADD, "w") as file: file.write(modified_data) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e796ca54..fb1f8eda 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,12 +24,12 @@ repos: - id: black - repo: https://github.com/tox-dev/pyproject-fmt - rev: 1.2.0 + rev: 1.3.0 hooks: - id: pyproject-fmt - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.1 + rev: v0.1.3 hooks: - id: ruff diff --git a/setup.py b/setup.py index 0df007be..157369c1 100644 --- a/setup.py +++ b/setup.py @@ -19,8 +19,7 @@ def get_version(): """Returns version of the project.""" version_file = "pillow_heif/_version.py" - with open(version_file, encoding="utf-8") as f: - exec(compile(f.read(), version_file, "exec")) # pylint: disable=exec-used + exec(compile(Path(version_file).read_text(encoding="utf-8"), version_file, "exec")) # pylint: disable=exec-used return locals()["__version__"] diff --git a/tests/leaks_test.py b/tests/leaks_test.py index 8d21d2c5..984a0f76 100644 --- a/tests/leaks_test.py +++ b/tests/leaks_test.py @@ -36,8 +36,7 @@ def perform_open_save(iterations, image_path): def test_open_save_objects_leaks(image): from pympler import summary, tracker - with open(image, mode="rb") as file: - image_file_data = BytesIO(file.read()) + image_file_data = BytesIO(Path(image).read_bytes()) perform_open_save(1, image_file_data) gc.collect() _summary1 = tracker.SummaryTracker().create_summary() @@ -68,8 +67,7 @@ def test_open_to_numpy_mem_leaks(): import numpy as np mem_limit = None - with open(Path("images/heif/L_10__29x100.heif"), mode="rb") as file: - image_file_data = BytesIO(file.read()) + image_file_data = BytesIO(Path("images/heif/L_10__29x100.heif").read_bytes()) for i in range(1000): heif_file = pillow_heif.open_heif(image_file_data, convert_hdr_to_8bit=False) _array = np.asarray(heif_file[0]) # noqa @@ -121,8 +119,7 @@ def test_metadata_leaks(): @pytest.mark.skipif(machine().find("x86_64") == -1, reason="run only on x86_64") def test_pillow_plugin_leaks(): mem_limit = None - with open(Path("images/heif/zPug_3.heic"), mode="rb") as file: - image_file_data = BytesIO(file.read()) + image_file_data = BytesIO(Path("images/heif/zPug_3.heic").read_bytes()) for i in range(1000): im = Image.open(image_file_data) for frame in ImageSequence.Iterator(im):