Debian Codegraph @

libexec/pyenv-which

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 #
3 # Summary: Display the full path to an executable
4 #
5 # Usage: pyenv which <command> [--nosystem] [--skip-advice]
6 #
7 # Displays the full path to the executable that pyenv will invoke when
8 # you run the given command.
9 # Use --nosystem argument in case when you don't need to search command in the
10 # system environment.
11 # Internal switch --skip-advice used to skip printing an error message on a
12 # failed search.
13
14 set -e
15 [scip-shell system . . `[`. -n "$PYENV_DEBUG" ] && set -x
16
17 # Provide pyenv completions
18 if [scip-shell system . . `[`. "$1" = "--complete" ]; then
19 exec pyenv-shims --short
20 fi
21
22 system="system"
23 SKIP_ADVICE=""
24 PYENV_COMMAND="$1"
25
26 while [[ $# -gt 0 ]]
27 do
28 case "$1" in
29 --skip-advice)
30 SKIP_ADVICE=1
31 shift
32 ;;
33 --nosystem)
34 system=""
35 shift
36 ;;
37 *)
38 shift
39 ;;
40 esac
41 done
42
43
44 remove_from_pathscip-shell shell shell-project 0.0.0 remove_from_path().() {
45 local -a paths_to_remove
46 IFS=: paths_to_remove=($1)
47 local path_to_remove path_before
48 local result=":${PATH//\~/$HOME}:"
49 for path_to_remove in "${paths_to_remove[@]}"; do
50 while truescip-shell system . . true.; do
51 path_before="$result"
52 result="${result//:$path_to_remove:/:}"
53 if [[ ${#path_before} == "${#result}" ]]; then break; fi
54 done
55 done
56 result="${result:1:${#result}-2}"
57 echoscip-shell system . . echo. "$result"
58 }
59
60 if [scip-shell system . . `[`. -z "$PYENV_COMMAND" ]; then
61 pyenv-help --usage which >&2
62 exit 1
63 fi
64
65 OLDIFS="$IFS"
66 IFS=: versions=(${PYENV_VERSION:-$(pyenv-version-name -f)})
67 IFS="$OLDIFS"
68
69 declare -a nonexistent_versions
70
71 for version in "${versions[@]}" "$system"; do
72 if [scip-shell system . . `[`. "$version" = "system" ]; then
73 PROGRAM="$(echoscip-shell system . . echo. "$PYENV_COMMAND" | trscip-shell system . . tr. a-z- A-Z_ | sedscip-shell system . . sed. 's/[^A-Z0-9_]/_/g')"
74 NR_CUSTOM_SHIM_PATHS="_PYENV_SHIM_PATHS_$PROGRAM"
75 SEARCH_PATH="$(remove_from_pathscip-shell shell shell-project 0.0.0 remove_from_path(). "${PYENV_ROOT}/shims${!NR_CUSTOM_SHIM_PATHS:+:${!NR_CUSTOM_SHIM_PATHS}}")"
76 PYENV_COMMAND_PATH="$(PATH="$SEARCH_PATH" command -v "$PYENV_COMMAND" || truescip-shell system . . true.)"
77 else
78 # $version may be a prefix to be resolved by pyenv-latest
79 version_path="$(pyenv-prefix "${version}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" || \
80 { nonexistent_versions+=("$version"); continue; }
81 # resolve $version for hooks
82 version="$(basenamescip-shell system . . basename. "$version_path")"
83 PYENV_COMMAND_PATH="$version_path/bin/${PYENV_COMMAND}"
84 unset version_path
85 fi
86 if [scip-shell system . . `[`. -x "$PYENV_COMMAND_PATH" ]; then
87 break
88 fi
89 done
90
91 OLDIFS="$IFS"
92 IFS=$'\n' scripts=(`pyenv-hooks which`)
93 IFS="$OLDIFS"
94 for script in "${scripts[@]}"; do
95 source "$script"
96 done
97
98 if [scip-shell system . . `[`. -x "$PYENV_COMMAND_PATH" ]; then
99 echoscip-shell system . . echo. "$PYENV_COMMAND_PATH"
100 else
101 if (( ${#nonexistent_versions[@]} )); then
102 for version in "${nonexistent_versions[@]}"; do
103 echoscip-shell system . . echo. "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2
104 done
105 fi
106
107 echoscip-shell system . . echo. "pyenv: $PYENV_COMMAND: command not found" >&2
108 if [scip-shell system . . `[`. -z "$SKIP_ADVICE" ]; then
109 versions="$(pyenv-whence "$PYENV_COMMAND" || truescip-shell system . . true.)"
110 if [scip-shell system . . `[`. -n "$versions" ]; then
111 { echoscip-shell system . . echo.
112 echoscip-shell system . . echo. "The \`$PYENV_COMMAND' command exists in these Python versions:"
113 echoscip-shell system . . echo. "$versions" | sedscip-shell system . . sed. 's/^/ /g'
114 echoscip-shell system . . echo.
115 echoscip-shell system . . echo. "Note: See 'pyenv help global' for tips on allowing multiple"
116 echoscip-shell system . . echo. " Python versions to be found at the same time."
117 } >&2
118 fi
119 fi
120
121 exit 127
122 fi