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 <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Oct 1, 2024
1 parent cfd5d63 commit 102ff83
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/ruff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 102ff83

Please sign in to comment.