Repository: pre-commit/pre-commit
Pull request #2771 (2023-02-21 02:45:25)

resources_bytesio is only used by ruby


Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index ad8ffba..023f4f6 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -38,7 +38,7 @@ repos:
     hooks:
     -   id: flake8
 -   repo: https://github.com/pre-commit/mirrors-mypy
-    rev: v1.0.1
+    rev: v1.0.0
     hooks:
     -   id: mypy
         additional_dependencies: [types-all]
diff --git a/pre_commit/languages/ruby.py b/pre_commit/languages/ruby.py
index 0ee0a85..76631f2 100644
--- a/pre_commit/languages/ruby.py
+++ b/pre_commit/languages/ruby.py
@@ -2,10 +2,12 @@ from __future__ import annotations
 
 import contextlib
 import functools
+import importlib.resources
 import os.path
 import shutil
 import tarfile
 from typing import Generator
+from typing import IO
 from typing import Sequence
 
 import pre_commit.constants as C
@@ -16,13 +18,16 @@ from pre_commit.envcontext import UNSET
 from pre_commit.envcontext import Var
 from pre_commit.prefix import Prefix
 from pre_commit.util import CalledProcessError
-from pre_commit.util import resource_bytesio
 
 ENVIRONMENT_DIR = 'rbenv'
 health_check = lang_base.basic_health_check
 run_hook = lang_base.basic_run_hook
 
 
+def _resource_bytesio(filename: str) -> IO[bytes]:
+    return importlib.resources.open_binary('pre_commit.resources', filename)
+
+
 @functools.lru_cache(maxsize=1)
 def get_default_version() -> str:
     if all(lang_base.exe_exists(exe) for exe in ('ruby', 'gem')):
@@ -74,7 +79,7 @@ def in_env(prefix: Prefix, version: str) -> Generator[None, None, None]:
 
 
 def _extract_resource(filename: str, dest: str) -> None:
-    with resource_bytesio(filename) as bio:
+    with _resource_bytesio(filename) as bio:
         with tarfile.open(fileobj=bio) as tf:
             tf.extractall(dest)
 
diff --git a/pre_commit/util.py b/pre_commit/util.py
index 8ea4844..3d448e3 100644
--- a/pre_commit/util.py
+++ b/pre_commit/util.py
@@ -12,7 +12,6 @@ from types import TracebackType
 from typing import Any
 from typing import Callable
 from typing import Generator
-from typing import IO
 
 from pre_commit import parse_shebang
 
@@ -36,10 +35,6 @@ def clean_path_on_failure(path: str) -> Generator[None, None, None]:
         raise
 
 
-def resource_bytesio(filename: str) -> IO[bytes]:
-    return importlib.resources.open_binary('pre_commit.resources', filename)
-
-
 def resource_text(filename: str) -> str:
     return importlib.resources.read_text('pre_commit.resources', filename)
 


Test patch:
diff --git a/tests/languages/ruby_test.py b/tests/languages/ruby_test.py
index 9cfaad5..6397a43 100644
--- a/tests/languages/ruby_test.py
+++ b/tests/languages/ruby_test.py
@@ -9,8 +9,8 @@ import pre_commit.constants as C
 from pre_commit import parse_shebang
 from pre_commit.envcontext import envcontext
 from pre_commit.languages import ruby
+from pre_commit.languages.ruby import _resource_bytesio
 from pre_commit.store import _make_local_repo
-from pre_commit.util import resource_bytesio
 from testing.language_helpers import run_language
 from testing.util import cwd
 from testing.util import xfailif_windows
@@ -40,7 +40,7 @@ def test_uses_system_if_both_gem_and_ruby_are_available(find_exe_mck):
     ('rbenv.tar.gz', 'ruby-build.tar.gz', 'ruby-download.tar.gz'),
 )
 def test_archive_root_stat(filename):
-    with resource_bytesio(filename) as f:
+    with _resource_bytesio(filename) as f:
         with tarfile.open(fileobj=f) as tarf:
             root, _, _ = filename.partition('.')
             assert oct(tarf.getmember(root).mode) == '0o755'