Home | History | Annotate | Download | only in tools
      1 #!/bin/bash
      2 #
      3 # Copyright 2014 Google Inc. All Rights Reserved.
      4 #
      5 # Generates a zip of the google api python client and dependencies.
      6 #
      7 # Author: afshar (at] google.com (Ali Afshar)
      8 
      9 # Exit on failure.
     10 set -e
     11 
     12 # Where to build the zip.
     13 ROOT_PATH=$(pwd)/build/gae
     14 BUILD_PATH=${ROOT_PATH}/build
     15 LIB_PATH=${ROOT_PATH}/lib
     16 ENV_PATH=${ROOT_PATH}/ve
     17 LOG_PATH=${ROOT_PATH}/gae_zip_build.log
     18 
     19 # The api client version
     20 APICLIENT_VERSION=$(python -c "import apiclient; print apiclient.__version__")
     21 
     22 # Where to create the zip.
     23 DIST_PATH=$(pwd)/dist/gae
     24 ZIP_NAME=google-api-python-client-gae-${APICLIENT_VERSION}.zip
     25 ZIP_PATH=${DIST_PATH}/${ZIP_NAME}
     26 
     27 # Make sure we are all clean.
     28 echo "Cleaning build env"
     29 rm -rf ${ROOT_PATH}
     30 mkdir -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.
     34 echo "Creating virtualenv and installing pip==dev"
     35 virtualenv --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.
     39 echo "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.
     43 echo "Pruning target library"
     44 find ${LIB_PATH} -name "*.pyc" -exec rm {} \; >> ${LOG_PATH}
     45 rm -rf ${LIB_PATH}/*.egg-info >> ${LOG_PATH}
     46 
     47 # Create the zip.
     48 echo "Creating zip"
     49 mkdir -p ${DIST_PATH}
     50 pushd ${LIB_PATH} >> ${LOG_PATH}
     51 zip -r ${ZIP_PATH} * >> ${LOG_PATH}
     52 popd >> ${LOG_PATH}
     53 
     54 # We are done.
     55 echo "Built zip in ${ZIP_PATH}"
     56 
     57 # Sanity test the zip.
     58 # TODO (afshar): Run the complete test suite.
     59 echo "Sanity testing the zip:"
     60 export SANITY_MODS="httplib2 apiclient uritemplate oauth2client"
     61 export SANITY_ZIP=${ZIP_PATH}
     62 export PYTHONPATH=${ZIP_PATH}
     63 ${ENV_PATH}/bin/python -c "import sys, os
     64 sys.path.pop(0) # remove the pwd
     65 for 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__)"
     69