Skip to content

Commit

Permalink
Support ruff discovery in pip build environments
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Oct 1, 2024
1 parent cfd5d63 commit ec80b9e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/ruff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ 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])
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)
if os.path.isfile(candidate):
return candidate

raise FileNotFoundError(scripts_path)


Expand Down

0 comments on commit ec80b9e

Please sign in to comment.