-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep Python script limited to
sysconfig
usage
- Loading branch information
1 parent
b654da6
commit 63a63a0
Showing
6 changed files
with
179 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import sys | ||
import sysconfig | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
RUFF_EXE = "ruff.exe" if sys.platform == "win32" else "ruff" | ||
|
||
|
||
def find_ruff_binary_path() -> Optional[Path]: | ||
"""Return the ruff binary path, `None` if unable to find.""" | ||
bin_path = Path(sysconfig.get_path("scripts")) / RUFF_EXE | ||
if bin_path.is_file(): | ||
return bin_path | ||
|
||
if sys.version_info >= (3, 10): | ||
user_scheme = sysconfig.get_preferred_scheme("user") | ||
elif os.name == "nt": | ||
user_scheme = "nt_user" | ||
elif sys.platform == "darwin" and sys._framework: | ||
user_scheme = "osx_framework_user" | ||
else: | ||
user_scheme = "posix_user" | ||
|
||
scripts_path = Path(sysconfig.get_path("scripts", scheme=user_scheme)) / RUFF_EXE | ||
if scripts_path.is_file(): | ||
return scripts_path | ||
|
||
return None | ||
|
||
|
||
if __name__ == "__main__": | ||
ruff_binary_path = find_ruff_binary_path() | ||
if ruff_binary_path: | ||
print(os.fsdecode(str(ruff_binary_path)), flush=True) |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.