Blame autoconf/py-compile

Packit 679830
#!/bin/sh
Packit 679830
# py-compile - Compile a Python program
Packit 679830
Packit 679830
scriptversion=2011-06-08.12; # UTC
Packit 679830
Packit 679830
# Copyright (C) 2000-2014 Free Software Foundation, Inc.
Packit 679830
Packit 679830
# This program is free software; you can redistribute it and/or modify
Packit 679830
# it under the terms of the GNU General Public License as published by
Packit 679830
# the Free Software Foundation; either version 2, or (at your option)
Packit 679830
# any later version.
Packit 679830
Packit 679830
# This program is distributed in the hope that it will be useful,
Packit 679830
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 679830
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 679830
# GNU General Public License for more details.
Packit 679830
Packit 679830
# You should have received a copy of the GNU General Public License
Packit 679830
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 679830
Packit 679830
# As a special exception to the GNU General Public License, if you
Packit 679830
# distribute this file as part of a program that contains a
Packit 679830
# configuration script generated by Autoconf, you may include it under
Packit 679830
# the same distribution terms that you use for the rest of that program.
Packit 679830
Packit 679830
# This file is maintained in Automake, please report
Packit 679830
# bugs to <bug-automake@gnu.org> or send patches to
Packit 679830
# <automake-patches@gnu.org>.
Packit 679830
Packit 679830
if [ -z "$PYTHON" ]; then
Packit 679830
  PYTHON=python
Packit 679830
fi
Packit 679830
Packit 679830
me=py-compile
Packit 679830
Packit 679830
usage_error ()
Packit 679830
{
Packit 679830
  echo "$me: $*" >&2
Packit 679830
  echo "Try '$me --help' for more information." >&2
Packit 679830
  exit 1
Packit 679830
}
Packit 679830
Packit 679830
basedir=
Packit 679830
destdir=
Packit 679830
while test $# -ne 0; do
Packit 679830
  case "$1" in
Packit 679830
    --basedir)
Packit 679830
      if test $# -lt 2; then
Packit 679830
        usage_error "option '--basedir' requires an argument"
Packit 679830
      else
Packit 679830
        basedir=$2
Packit 679830
      fi
Packit 679830
      shift
Packit 679830
      ;;
Packit 679830
    --destdir)
Packit 679830
      if test $# -lt 2; then
Packit 679830
        usage_error "option '--destdir' requires an argument"
Packit 679830
      else
Packit 679830
        destdir=$2
Packit 679830
      fi
Packit 679830
      shift
Packit 679830
      ;;
Packit 679830
    -h|--help)
Packit 679830
      cat <<\EOF
Packit 679830
Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
Packit 679830
Packit 679830
Byte compile some python scripts FILES.  Use --destdir to specify any
Packit 679830
leading directory path to the FILES that you don't want to include in the
Packit 679830
byte compiled file.  Specify --basedir for any additional path information you
Packit 679830
do want to be shown in the byte compiled file.
Packit 679830
Packit 679830
Example:
Packit 679830
  py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
Packit 679830
Packit 679830
Report bugs to <bug-automake@gnu.org>.
Packit 679830
EOF
Packit 679830
      exit $?
Packit 679830
      ;;
Packit 679830
    -v|--version)
Packit 679830
      echo "$me $scriptversion"
Packit 679830
      exit $?
Packit 679830
      ;;
Packit 679830
    --)
Packit 679830
      shift
Packit 679830
      break
Packit 679830
      ;;
Packit 679830
    -*)
Packit 679830
      usage_error "unrecognized option '$1'"
Packit 679830
      ;;
Packit 679830
    *)
Packit 679830
      break
Packit 679830
      ;;
Packit 679830
  esac
Packit 679830
  shift
Packit 679830
done
Packit 679830
Packit 679830
files=$*
Packit 679830
if test -z "$files"; then
Packit 679830
    usage_error "no files given"
Packit 679830
fi
Packit 679830
Packit 679830
# if basedir was given, then it should be prepended to filenames before
Packit 679830
# byte compilation.
Packit 679830
if [ -z "$basedir" ]; then
Packit 679830
    pathtrans="path = file"
Packit 679830
else
Packit 679830
    pathtrans="path = os.path.join('$basedir', file)"
Packit 679830
fi
Packit 679830
Packit 679830
# if destdir was given, then it needs to be prepended to the filename to
Packit 679830
# byte compile but not go into the compiled file.
Packit 679830
if [ -z "$destdir" ]; then
Packit 679830
    filetrans="filepath = path"
Packit 679830
else
Packit 679830
    filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
Packit 679830
fi
Packit 679830
Packit 679830
$PYTHON -c "
Packit 679830
import sys, os, py_compile, imp
Packit 679830
Packit 679830
files = '''$files'''
Packit 679830
Packit 679830
sys.stdout.write('Byte-compiling python modules...\n')
Packit 679830
for file in files.split():
Packit 679830
    $pathtrans
Packit 679830
    $filetrans
Packit 679830
    if not os.path.exists(filepath) or not (len(filepath) >= 3
Packit 679830
                                            and filepath[-3:] == '.py'):
Packit 679830
	    continue
Packit 679830
    sys.stdout.write(file)
Packit 679830
    sys.stdout.flush()
Packit 679830
    if hasattr(imp, 'get_tag'):
Packit 679830
        py_compile.compile(filepath, imp.cache_from_source(filepath), path)
Packit 679830
    else:
Packit 679830
        py_compile.compile(filepath, filepath + 'c', path)
Packit 679830
sys.stdout.write('\n')" || exit $?
Packit 679830
Packit 679830
# this will fail for python < 1.5, but that doesn't matter ...
Packit 679830
$PYTHON -O -c "
Packit 679830
import sys, os, py_compile, imp
Packit 679830
Packit 679830
# pypy does not use .pyo optimization
Packit 679830
if hasattr(sys, 'pypy_translation_info'):
Packit 679830
    sys.exit(0)
Packit 679830
Packit 679830
files = '''$files'''
Packit 679830
sys.stdout.write('Byte-compiling python modules (optimized versions) ...\n')
Packit 679830
for file in files.split():
Packit 679830
    $pathtrans
Packit 679830
    $filetrans
Packit 679830
    if not os.path.exists(filepath) or not (len(filepath) >= 3
Packit 679830
                                            and filepath[-3:] == '.py'):
Packit 679830
	    continue
Packit 679830
    sys.stdout.write(file)
Packit 679830
    sys.stdout.flush()
Packit 679830
    if hasattr(imp, 'get_tag'):
Packit 679830
        py_compile.compile(filepath, imp.cache_from_source(filepath, False), path)
Packit 679830
    else:
Packit 679830
        py_compile.compile(filepath, filepath + 'o', path)
Packit 679830
sys.stdout.write('\n')" 2>/dev/null || :
Packit 679830
Packit 679830
# Local Variables:
Packit 679830
# mode: shell-script
Packit 679830
# sh-indentation: 2
Packit 679830
# eval: (add-hook 'write-file-hooks 'time-stamp)
Packit 679830
# time-stamp-start: "scriptversion="
Packit 679830
# time-stamp-format: "%:y-%02m-%02d.%02H"
Packit 679830
# time-stamp-time-zone: "UTC"
Packit 679830
# time-stamp-end: "; # UTC"
Packit 679830
# End: