2025-09-29 09:30:35 +02:00
|
|
|
# localization: skip(private)
|
2019-03-09 17:57:49 +01:00
|
|
|
function __fish_anypython
|
2025-11-18 09:02:47 +01:00
|
|
|
if set -l path (command -s python3)
|
|
|
|
|
# Do not consider the stub /usr/bin/python3 that comes installed on Darwin to be Python
|
|
|
|
|
# unless Xcode reports a real directory path.
|
|
|
|
|
and not begin
|
|
|
|
|
string match -q Darwin -- "$(uname)"
|
|
|
|
|
and string match -q /usr/bin/python3 -- $path
|
|
|
|
|
and type -q xcode-select
|
|
|
|
|
and not xcode-select --print-path &>/dev/null
|
2022-12-26 13:40:13 -08:00
|
|
|
end
|
2025-11-18 09:02:47 +01:00
|
|
|
echo $path
|
|
|
|
|
return 0
|
|
|
|
|
end
|
|
|
|
|
set -l best_path
|
|
|
|
|
set -l best_minor_version
|
|
|
|
|
set -l minor_version
|
|
|
|
|
for path in (path filter -fx -- $PATH/python3.*)
|
|
|
|
|
string match -rq -- '.*/python3\.(?<minor_version>\d+)$' $path
|
2025-11-19 07:40:12 +01:00
|
|
|
and test $minor_version -ge 5 # Python 3.5+
|
2025-11-18 09:02:47 +01:00
|
|
|
or continue
|
|
|
|
|
and begin
|
|
|
|
|
not set -q best_path[1]
|
|
|
|
|
or test $minor_version -gt $best_minor_version
|
|
|
|
|
end
|
|
|
|
|
set best_path $path
|
|
|
|
|
set best_minor_version $minor_version
|
|
|
|
|
end
|
|
|
|
|
if set -q best_path[1]
|
|
|
|
|
echo $best_path
|
|
|
|
|
return 0
|
2019-03-09 17:57:49 +01:00
|
|
|
end
|
|
|
|
|
# We have no python.
|
|
|
|
|
return 1
|
|
|
|
|
end
|