mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #2771 from pre-commit/ruby-is-the-only-bytesio
resources_bytesio is only used by ruby
This commit is contained in:
commit
51b14c2b37
3 changed files with 9 additions and 9 deletions
|
|
@ -2,10 +2,12 @@ from __future__ import annotations
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import functools
|
import functools
|
||||||
|
import importlib.resources
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
import tarfile
|
import tarfile
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
from typing import IO
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
|
|
||||||
import pre_commit.constants as C
|
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.envcontext import Var
|
||||||
from pre_commit.prefix import Prefix
|
from pre_commit.prefix import Prefix
|
||||||
from pre_commit.util import CalledProcessError
|
from pre_commit.util import CalledProcessError
|
||||||
from pre_commit.util import resource_bytesio
|
|
||||||
|
|
||||||
ENVIRONMENT_DIR = 'rbenv'
|
ENVIRONMENT_DIR = 'rbenv'
|
||||||
health_check = lang_base.basic_health_check
|
health_check = lang_base.basic_health_check
|
||||||
run_hook = lang_base.basic_run_hook
|
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)
|
@functools.lru_cache(maxsize=1)
|
||||||
def get_default_version() -> str:
|
def get_default_version() -> str:
|
||||||
if all(lang_base.exe_exists(exe) for exe in ('ruby', 'gem')):
|
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:
|
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:
|
with tarfile.open(fileobj=bio) as tf:
|
||||||
tf.extractall(dest)
|
tf.extractall(dest)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ from types import TracebackType
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
from typing import IO
|
|
||||||
|
|
||||||
from pre_commit import parse_shebang
|
from pre_commit import parse_shebang
|
||||||
|
|
||||||
|
|
@ -36,10 +35,6 @@ def clean_path_on_failure(path: str) -> Generator[None, None, None]:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def resource_bytesio(filename: str) -> IO[bytes]:
|
|
||||||
return importlib.resources.open_binary('pre_commit.resources', filename)
|
|
||||||
|
|
||||||
|
|
||||||
def resource_text(filename: str) -> str:
|
def resource_text(filename: str) -> str:
|
||||||
return importlib.resources.read_text('pre_commit.resources', filename)
|
return importlib.resources.read_text('pre_commit.resources', filename)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import pre_commit.constants as C
|
||||||
from pre_commit import parse_shebang
|
from pre_commit import parse_shebang
|
||||||
from pre_commit.envcontext import envcontext
|
from pre_commit.envcontext import envcontext
|
||||||
from pre_commit.languages import ruby
|
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.store import _make_local_repo
|
||||||
from pre_commit.util import resource_bytesio
|
|
||||||
from testing.language_helpers import run_language
|
from testing.language_helpers import run_language
|
||||||
from testing.util import cwd
|
from testing.util import cwd
|
||||||
from testing.util import xfailif_windows
|
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'),
|
('rbenv.tar.gz', 'ruby-build.tar.gz', 'ruby-download.tar.gz'),
|
||||||
)
|
)
|
||||||
def test_archive_root_stat(filename):
|
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:
|
with tarfile.open(fileobj=f) as tarf:
|
||||||
root, _, _ = filename.partition('.')
|
root, _, _ = filename.partition('.')
|
||||||
assert oct(tarf.getmember(root).mode) == '0o755'
|
assert oct(tarf.getmember(root).mode) == '0o755'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue