Blame autoconf/py-compile

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