File: sage-system-python

package info (click to toggle)
sagemath 9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 126,716 kB
  • sloc: python: 1,070,573; cpp: 5,380; ansic: 4,064; sh: 3,976; objc: 1,407; makefile: 1,089; javascript: 292; lisp: 5
file content (51 lines) | stat: -rwxr-xr-x 1,966 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh

# Run the system python.
#
# This is primarily for use by the build toolchain so that it can continue
# using the system Python rather than Sage's Python, preventing conflicts
# that might otherwise occur, particularly in parallel builds.
#
# See https://trac.sagemath.org/ticket/18438

if [ -z "$SAGE_ORIG_PATH" ]; then
    # If not we're running from within sage-env just set the existing path
    SAGE_ORIG_PATH="$PATH"
fi

# In particular, it is invoked by "bootstrap -d" for sage-download-file,
# i.e., before a configure run, and by "sage-spkg", also for sage-download-file.
# So it needs to find a python that has the urllib module.
# For example, on Debian buster, the python3-minimal package does NOT provide it.
#
# See https://trac.sagemath.org/ticket/29090

# Trac #29890: Our first choice is "python", not "python3". This is to avoid
# a defect of sage_bootstrap on macOS regarding SSL URLs.

# Trac #30177: Also check for hashlib.sha1 to guard against broken python2
# from old homebrew installations.  Also check whether the current directory
# is accessible by this python; this is to guard on Cygwin against Pythons
# installed somewhere else in Windows.

# Trac #30008: Make it work even if the environment tries to sabotage UTF-8
# operation in Python 3.0.x-3.6.x by setting LC_ALL=C or similar.

if [ "$LC_ALL" = "C" -o "$LANG" = "C" -o "$LC_CTYPE" = "C" ]; then
    LC_ALL=$(locale -a | grep -E -i '^(c|en_us)[-.]utf-?8$' | head -n 1)
    LANG=$LC_ALL
    export LC_ALL
    export LANG
fi

PYTHONS="python python3 python3.8 python3.7 python2.7 python3.6 python2"
for PY in $PYTHONS; do
    PYTHON="$(PATH="$SAGE_ORIG_PATH" command -v $PY)"
    if [ -n "$PYTHON" ]; then
        if "$PYTHON" -c "import urllib; from hashlib import sha1; from os import listdir; listdir(\"$(pwd)\");" 2>/dev/null; then
            exec "$PYTHON" "$@"
        fi
    fi
done
echo >&2 "$0: error: none of $PYTHONS is a suitable Python with urllib"
exit 1