summaryrefslogtreecommitdiffstats
path: root/pre_commit/languages/python.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:19 +0000
commit02d5100afa71d1343de4066b812cd4cdc774d812 (patch)
tree6bccae957398fab29aaa226fb0bd65f0c258a36a /pre_commit/languages/python.py
parentAdding upstream version 2.21.0. (diff)
downloadpre-commit-02d5100afa71d1343de4066b812cd4cdc774d812.tar.xz
pre-commit-02d5100afa71d1343de4066b812cd4cdc774d812.zip
Adding upstream version 3.0.2.upstream/3.0.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/languages/python.py')
-rw-r--r--pre_commit/languages/python.py32
1 files changed, 8 insertions, 24 deletions
diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py
index 19fa247..c373646 100644
--- a/pre_commit/languages/python.py
+++ b/pre_commit/languages/python.py
@@ -12,17 +12,16 @@ from pre_commit.envcontext import envcontext
from pre_commit.envcontext import PatchesT
from pre_commit.envcontext import UNSET
from pre_commit.envcontext import Var
-from pre_commit.hook import Hook
from pre_commit.languages import helpers
from pre_commit.parse_shebang import find_executable
from pre_commit.prefix import Prefix
from pre_commit.util import CalledProcessError
-from pre_commit.util import clean_path_on_failure
from pre_commit.util import cmd_output
from pre_commit.util import cmd_output_b
from pre_commit.util import win_exe
ENVIRONMENT_DIR = 'py_env'
+run_hook = helpers.basic_run_hook
@functools.lru_cache(maxsize=None)
@@ -153,19 +152,14 @@ def norm_version(version: str) -> str | None:
@contextlib.contextmanager
-def in_env(
- prefix: Prefix,
- language_version: str,
-) -> Generator[None, None, None]:
- directory = helpers.environment_dir(ENVIRONMENT_DIR, language_version)
- envdir = prefix.path(directory)
+def in_env(prefix: Prefix, version: str) -> Generator[None, None, None]:
+ envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, version)
with envcontext(get_env_patch(envdir)):
yield
def health_check(prefix: Prefix, language_version: str) -> str | None:
- directory = helpers.environment_dir(ENVIRONMENT_DIR, language_version)
- envdir = prefix.path(directory)
+ envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, language_version)
pyvenv_cfg = os.path.join(envdir, 'pyvenv.cfg')
# created with "old" virtualenv
@@ -208,23 +202,13 @@ def install_environment(
version: str,
additional_dependencies: Sequence[str],
) -> None:
- envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version))
+ envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, version)
venv_cmd = [sys.executable, '-mvirtualenv', envdir]
python = norm_version(version)
if python is not None:
venv_cmd.extend(('-p', python))
install_cmd = ('python', '-mpip', 'install', '.', *additional_dependencies)
- with clean_path_on_failure(envdir):
- cmd_output_b(*venv_cmd, cwd='/')
- with in_env(prefix, version):
- helpers.run_setup_cmd(prefix, install_cmd)
-
-
-def run_hook(
- hook: Hook,
- file_args: Sequence[str],
- color: bool,
-) -> tuple[int, bytes]:
- with in_env(hook.prefix, hook.language_version):
- return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
+ cmd_output_b(*venv_cmd, cwd='/')
+ with in_env(prefix, version):
+ helpers.run_setup_cmd(prefix, install_cmd)