-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·71 lines (61 loc) · 2.28 KB
/
run.sh
File metadata and controls
executable file
·71 lines (61 loc) · 2.28 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -eu
set -o pipefail
python3=${PYTHON_COMMAND:-python3}
if $python3 -c 'import sys; exit(0 if sys.version_info < (3, 6, 1) else 1)'; then
echo 'This script is only for use with Python 3.6.1 or later' >&2
exit 1
fi
# Ensure required packages.
root_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
if [[ -f /.dockerenv ]] && [[ ! -v CI ]]; then
# Inside a Docker container (assumed to be created from the Dockerfile).
# The required packages have been installed via Poetry.
venv_python3=$python3
else
# Use a virtual environment.
venv_path=$root_path/.venv
venv_python3=$venv_path/bin/python3
if [[ ! -d $venv_path ]]; then
echo 'Initializing virtualenv...'
$python3 -m venv "$venv_path"
$venv_python3 -m pip install --upgrade pip
# Check Python version.
if $venv_python3 <<END
import sys
sys.exit(0 if sys.version_info >= (3, 7) else 1)
END
then
# Use Poetry for Python >= 3.7.
$venv_python3 -m pip install poetry
poetry_version=$($venv_python3 -m pip show poetry 2>/dev/null | awk '/Version:/ {print $2}')
poetry_major_version=$(echo "$poetry_version" | cut -d. -f1)
(
cd $root_path
$venv_python3 -m poetry config --local virtualenvs.in-project true
if [[ "$poetry_major_version" -ge 2 ]]; then
$venv_python3 -m poetry install --only main --no-interaction --no-root
else
$venv_python3 -m poetry install --no-dev --no-interaction --no-root
fi
)
else
# Poetry 1.1.15 (installed for Python 3.6) fails to read lock files
# generated by 1.3.1 or later.
# https://github.com/python-poetry/poetry/issues/7211
# Moreover, if we delete the lock file, then Poetry 1.1.15 (installed
# for Python 3.6) fails to resolve the dependencies.
# The workaround here is to convert the poetry.lock file to
# a requirements.txt file, and then pass it to pip.
$venv_python3 -m pip install toml packaging
(
cd $root_path
$venv_python3 $root_path/scripts/poetry2pip.py
)
$venv_python3 -m pip install -r $root_path/requirements.txt
fi
fi
fi
# Run the main script.
export PYTHONPATH=${PYTHONPATH:+${PYTHONPATH}:}$root_path
$venv_python3 -m polybench --build-dir "$root_path/build" "$@"