File: ci.sh

package info (click to toggle)
px 1.0.21-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,556 kB
  • sloc: python: 3,152; sh: 176; makefile: 4
file content (130 lines) | stat: -rwxr-xr-x 3,588 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash

set -o pipefail
set -e
set -x

MYDIR=$(cd "$(dirname "$0")" ; pwd)

if [ "$VIRTUAL_ENV" ] ; then
  echo 'ERROR: Already in a virtualenv, do "deactivate" first and try again'
  exit 1
fi

# Don't produce a binary if something goes wrong
trap "rm -f px.pex" ERR

if [ $# != 1 ] ; then
  if command -v shellcheck &> /dev/null ; then
    shellcheck ./*.sh ./*/*.sh
  fi

  source ./tests/installtest.sh

  # Run this script with two different Python interpreters
  . ./scripts/set-other-python.sh
  "${MYDIR}/scripts/parallelize.py" "$0 $OTHER_PYTHON" "$0 python"
  cp .python-env/px.pex "${MYDIR}"

  if ! head -n1 px.pex | grep -w python ; then
    echo
    echo "ERROR: px.pex should use \"python\" as its interpreter:"
    file px.pex
    false
    exit 1
  fi

  echo
  echo "All tests passed!"
  echo
  exit
fi

PYTHONBIN="$1"

# Prepare for making a virtualenv
ENVDIR="${MYDIR}/.${PYTHONBIN}-env"
for DEP in "$(command -v virtualenv)" "${PYTHON}" requirements*.txt ; do
  if [ "$DEP" -nt "${ENVDIR}" ] ; then
    # Drop our virtualenv, it's older than one of its dependencies
    rm -rf "$ENVDIR"
  fi
done

if [ ! -d "${ENVDIR}" ]; then
  # No virtualenv, set it up
  virtualenv --python="${PYTHONBIN}" "${ENVDIR}"
  # shellcheck source=/dev/null
  . "${ENVDIR}"/bin/activate

  pip install -r requirements.txt

  # Fix tools versions
  pip install -r requirements-dev.txt

  if python --version 2>&1 | grep " 3" ; then
    pip install -r requirements-dev-py3.txt
  fi
else
  # Just activate the existing virtualenv
  # shellcheck source=/dev/null
  . "${ENVDIR}"/bin/activate
fi

# Call setup.py here to ensure version.py has been generated before we do anything
# else.
./setup.py check

if python --version 2>&1 | grep " 3" ; then
  # Verson of "python" binary is 3, do static type analysis. Mypy requires
  # Python 3, that's why we do this only on Python 3.
  mypy ./*.py ./*/*.py
  mypy ./*.py ./*/*.py --python-version=2.7
fi

flake8 px tests scripts setup.py

# We're getting DeprecationWarnings from pytest 4.2.0, which is the latest
# version at the time of writing this comment.
# FIXME: Go for just -Werror as soon as possible
python -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning ./setup.py test

# Create px wheel...
rm -rf dist "${ENVDIR}"/pxpx-*.whl build/lib/px
./setup.py bdist_wheel --universal --dist-dir="${ENVDIR}"

# ... and package everything in px.pex
#
# Note that we have to --disable-cache here since otherwise changing the code
# without changing the "git describe" output won't change the resulting binary.
# And since that happens all the time during development we can't have that.
#
# Also note that we need to specify the --python-shebang to get "python" as an
# interpreter. Just passing --python (or nothing) defaults to following the
# "python" symlink and putting "2.7" here.
PX_PEX="${ENVDIR}/px.pex"
rm -f "${PX_PEX}"
pex --python-shebang="#!/usr/bin/env $1" --disable-cache -r requirements.txt "${ENVDIR}"/pxpx-*.whl -m px.px -o "${PX_PEX}"

echo
if unzip -qq -l "${PX_PEX}" '*.so' ; then
  cat << EOF
  ERROR: There are natively compiled dependencies in the .pex, this makes
         distribution a lot harder. Please fix your dependencies.
EOF
  exit 1
fi

echo
python -Werror -Wdefault:'the imp module' "${PX_PEX}"

echo
test "$("${PX_PEX}" --version)" = "$(git describe --dirty)"

if pip list | grep '^pxpx ' > /dev/null ; then
  # Uninstall px before doing install testing
  pip uninstall --yes pxpx
fi
pip install "${ENVDIR}"/pxpx-*.whl
px bash
test "$(px --version)" = "$(git describe --dirty)"