[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Python postinstall scripts and compileall.py



  Hello all,

  Today I was looking at a bug report and while reviewing it I noticed
  that my postinstall script was wrong.
  
  The package installs 3 files in '/usr/lib/python$PV/site-packages',
  but after installation I wasn't compiling them.
  
  I looked at other python packages and I noticed that when the package
  puts files on that directory the 'postinstall' scripts I've looked at
  use the 'compileall.py' script over the
  '/usr/lib/python$PV/site-packages' directory.

  While that works O.K., it compiles everything under this directory and
  recurses until a depth of 10 subdirectories by default.

  In general it compiles nothing but the package files (each package
  should have compiled its sources), but I feel that this is not the
  right thing to do, IMHO every package should only take care of it's
  own files and don't touch others (unless it's really needed).

  I'm writting to the list to know what do you think about it.
  
  By the way, in my package I've modified the postinstall to compile
  only my files, the script is:

--*-- BEG: postinst --*--
#! /bin/sh -e
#
# postinst script for Debian python packages.
# Written 1998 by Gregor Hoffleit <flight@debian.org>.
# Modified 2001 by Matthias Klose <doko@debian.org>
# Modified 2003 by Sergio Talens-Oliag <sto@debian.org> for the
# python-htmltmpl package (only compile our .py files).

PACKAGE=`basename $0 .postinst`
PV=`dpkg --listfiles $PACKAGE | sed -n -e '/^\/usr\/lib\/python.*\//{
  s,/usr/lib/python\([0-9][0-9.]*\)/.*,\1,p
  q
}'`
PYTHON=python$PV
FILELIST=`dpkg --listfiles $PACKAGE | grep "^/usr/lib/python.*/site-packages/.*.py$"`

case "$1" in
  configure|abort-upgrade|abort-remove|abort-deconfigure)
    for i in $FILELIST; do
      /usr/bin/$PYTHON -O -c "import py_compile; py_compile.compile('$i')"
      /usr/bin/$PYTHON -c "import py_compile; py_compile.compile('$i')"
    done
  ;;

  *)
    echo "postinst called with unknown argument \`$1'" >&2
    exit 1
  ;;
esac

#DEBHELPER#

exit 0
--*-- END: postinst --*--
 
-- 
Sergio Talens-Oliag <sto@debian.org>   <http://people.debian.org/~sto/>
Key fingerprint = 29DF 544F  1BD9 548C  8F15 86EF  6770 052B  B8C1 FA69

Attachment: pgpddKSfcufUw.pgp
Description: PGP signature


Reply to: