blob: 152d5f96eea4a0852bc01efb718df09b51d3e028 [file] [log] [blame]
Ali Afshar90af4912012-08-23 15:31:36 -07001#!/bin/bash
2#
Craig Citro0e5b9bf2014-10-15 10:26:14 -07003# Copyright 2014 Google Inc. All Rights Reserved.
Ali Afshar90af4912012-08-23 15:31:36 -07004#
5# Generates a zip of the google api python client and dependencies.
6#
7# Author: afshar@google.com (Ali Afshar)
8
9# Exit on failure.
10set -e
11
12# Where to build the zip.
13ROOT_PATH=$(pwd)/build/gae
14BUILD_PATH=${ROOT_PATH}/build
15LIB_PATH=${ROOT_PATH}/lib
16ENV_PATH=${ROOT_PATH}/ve
17LOG_PATH=${ROOT_PATH}/gae_zip_build.log
18
19# The api client version
20APICLIENT_VERSION=$(python -c "import apiclient; print apiclient.__version__")
21
22# Where to create the zip.
23DIST_PATH=$(pwd)/dist/gae
24ZIP_NAME=google-api-python-client-gae-${APICLIENT_VERSION}.zip
25ZIP_PATH=${DIST_PATH}/${ZIP_NAME}
26
27# Make sure we are all clean.
28echo "Cleaning build env"
29rm -rf ${ROOT_PATH}
30mkdir -p ${ROOT_PATH}
31
32# We must not use the system pip, since that exposes a bug uninstalling httplib2
33# instead, install the dev version of pip.
34echo "Creating virtualenv and installing pip==dev"
35virtualenv --no-site-packages ${ENV_PATH} >> ${LOG_PATH}
36${ENV_PATH}/bin/pip install --upgrade pip==dev >> ${LOG_PATH}
37
38# Install the library with dependencies.
39echo "Building google-api-python client"
40${ENV_PATH}/bin/pip install -b ${BUILD_PATH} -t ${LIB_PATH} . >> ${LOG_PATH}
41
42# Prune the things we don't want.
43echo "Pruning target library"
Ali Afshardcc96972012-08-29 07:36:17 -070044find ${LIB_PATH} -name "*.pyc" -exec rm {} \; >> ${LOG_PATH}
45rm -rf ${LIB_PATH}/*.egg-info >> ${LOG_PATH}
Ali Afshar90af4912012-08-23 15:31:36 -070046
47# Create the zip.
48echo "Creating zip"
49mkdir -p ${DIST_PATH}
50pushd ${LIB_PATH} >> ${LOG_PATH}
51zip -r ${ZIP_PATH} * >> ${LOG_PATH}
52popd >> ${LOG_PATH}
53
54# We are done.
55echo "Built zip in ${ZIP_PATH}"
56
57# Sanity test the zip.
58# TODO (afshar): Run the complete test suite.
59echo "Sanity testing the zip:"
Joe Gregorio79daca02013-03-29 16:25:52 -040060export SANITY_MODS="httplib2 apiclient uritemplate oauth2client"
Ali Afshar90af4912012-08-23 15:31:36 -070061export SANITY_ZIP=${ZIP_PATH}
62export PYTHONPATH=${ZIP_PATH}
63${ENV_PATH}/bin/python -c "import sys, os
64sys.path.pop(0) # remove the pwd
65for name in os.getenv('SANITY_MODS').split():
66 mod = __import__(name)
67 assert os.getenv('SANITY_ZIP') in mod.__file__
68 print ' ', os.path.relpath(mod.__file__)"