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

Locate ruff executable in 'bin' directory as installed by 'pip install --target'. #11450

Merged
merged 2 commits into from
May 16, 2024
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
22 changes: 15 additions & 7 deletions python/ruff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def find_ruff_bin() -> str:

ruff_exe = "ruff" + sysconfig.get_config_var("EXE")

path = os.path.join(sysconfig.get_path("scripts"), ruff_exe)
if os.path.isfile(path):
return path
scripts_path = os.path.join(sysconfig.get_path("scripts"), ruff_exe)
if os.path.isfile(scripts_path):
return scripts_path

if sys.version_info >= (3, 10):
user_scheme = sysconfig.get_preferred_scheme("user")
Expand All @@ -21,11 +21,19 @@ def find_ruff_bin() -> str:
else:
user_scheme = "posix_user"

path = os.path.join(sysconfig.get_path("scripts", scheme=user_scheme), ruff_exe)
if os.path.isfile(path):
return path
user_path = os.path.join(
sysconfig.get_path("scripts", scheme=user_scheme), ruff_exe
)
if os.path.isfile(user_path):
return user_path

raise FileNotFoundError(path)
# Search in `bin` adjacent to package root (as created by `pip install --target`).
pkg_root = os.path.dirname(os.path.dirname(__file__))
target_path = os.path.join(pkg_root, "bin", ruff_exe)
if os.path.isfile(target_path):
return target_path

raise FileNotFoundError(scripts_path)


if __name__ == "__main__":
Expand Down
Loading