Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ruff discovery in pip build environments #13591

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions python/ruff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ def find_ruff_bin() -> str:
if os.path.isfile(target_path):
return target_path

# Search for pip-specific build environments.
#
# See: https://github.com/pypa/pip/blob/102d8187a1f5a4cd5de7a549fd8a9af34e89a54f/src/pip/_internal/build_env.py#L87
paths = os.environ.get("PATH", "").split(os.pathsep)
if len(paths) >= 2:
first, second = os.path.split(paths[0]), os.path.split(paths[1])
# Search for both an `overlay` and `normal` folder within a `pip-build-env-{random}` folder. (The final segment
# of the path is the `bin` directory.)
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"
):
# The overlay must contain the ruff binary.
candidate = os.path.join(first, ruff_exe)
if os.path.isfile(candidate):
return candidate

raise FileNotFoundError(scripts_path)


Expand Down
Loading