From c68a3ba59f7231c076aa034685ef48481ac6138b Mon Sep 17 00:00:00 2001 From: "Rodney, Tiara" Date: Tue, 15 Apr 2025 15:22:30 +0200 Subject: [PATCH] refactor(languages/conda): adapt scripts path resolution Cygwin isn't the only edge-case for a differing bin/ path. In addition there also is MSYS2, which behaves differently than Cygwin. CPython compiled against Microsoft Visual C++ Runtime (MSVCRT) through MinGW, will correctly identify as an 'nt' platform, yet will prefer a POSIX path scheme. In order to avoid having to patch every edge-case, we can spy on the system configurations install paths through the `sysconfig` module and get the basename of the global scripts path, which will be returned in accordance with the preferred install path scheme of the system/platform. Fixes: https://github.com/pre-commit/pre-commit/issues/3448 --- pre_commit/languages/conda.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pre_commit/languages/conda.py b/pre_commit/languages/conda.py index d397ebeb..1531d383 100644 --- a/pre_commit/languages/conda.py +++ b/pre_commit/languages/conda.py @@ -12,6 +12,7 @@ from pre_commit.envcontext import PatchesT from pre_commit.envcontext import SubstitutionT from pre_commit.envcontext import UNSET from pre_commit.envcontext import Var +from pre_commit.languages.python import bin_dir from pre_commit.prefix import Prefix from pre_commit.util import cmd_output_b @@ -26,10 +27,9 @@ def get_env_patch(env: str) -> PatchesT: # they can be in $CONDA_PREFIX/bin, $CONDA_PREFIX/Library/bin, # $CONDA_PREFIX/Scripts and $CONDA_PREFIX. Whereas the latter only # seems to be used for python.exe. - path: SubstitutionT = (os.path.join(env, 'bin'), os.pathsep, Var('PATH')) + path: SubstitutionT = (str(bin_dir(env)), os.pathsep, Var('PATH')) if sys.platform == 'win32': # pragma: win32 cover path = (env, os.pathsep, *path) - path = (os.path.join(env, 'Scripts'), os.pathsep, *path) path = (os.path.join(env, 'Library', 'bin'), os.pathsep, *path) return (