diff --git a/python/ruff/__main__.py b/python/ruff/__main__.py index 9db95031bc8df..8c312572d0bcd 100644 --- a/python/ruff/__main__.py +++ b/python/ruff/__main__.py @@ -33,6 +33,24 @@ def find_ruff_bin() -> str: if os.path.isfile(target_path): return target_path + # Might be a pip build environment + paths = os.environ.get("PATH", "").split(os.pathsep) + if len(paths) >= 2: + # https://github.com/pypa/pip/blob/main/src/pip/_internal/build_env.py#L87 + first, second = os.path.split(paths[0]), os.path.split(paths[1]) + # we need an overlay and normal folder within pip-build-env-{random} folders + if ( + len(first) >= 3 + and len(second) >= 3 + and first[-3].startswith("pip-build-env-") + and first[-2] == "overlay" + and second[-3].startswith("pip-build-env-") + and second[-2] == "normal" + ): + candidate = os.path.join(first, ruff_exe) # the overlay contains ruff + if os.path.isfile(candidate): + return candidate + raise FileNotFoundError(scripts_path)