Skip to content
Snippets Groups Projects
Commit d72d9624 authored by Matthias Klose's avatar Matthias Klose
Browse files

* pycompile:

    - Don't over-optimize, check the timestamps of byte-code files.
    - Use the correct name for byte-code files.
    - Add an option -f/--force.
    - Copy stdout/stderr of py_compile processes in case of error.
    - Propagate the exit value of the py_compile processes.
    - Update manual page.
  * Bump depends to require the fixed pycompile for dh_python2 based package
    builds.
  * Don't touch the standard python library in rtupdate scripts.
parent 4b234a49
No related branches found
No related tags found
No related merge requests found
python-defaults (2.6.6-7) experimental; urgency=high
* pycompile:
- Don't over-optimize, check the timestamps of byte-code files.
- Use the correct name for byte-code files.
- Add an option -f/--force.
- Copy stdout/stderr of py_compile processes in case of error.
- Propagate the exit value of the py_compile processes.
- Update manual page.
* Bump depends to require the fixed pycompile for dh_python2 based package
builds.
* Don't touch the standard python library in rtupdate scripts.
-- Matthias Klose <doko@debian.org> Sun, 12 Dec 2010 17:46:13 +0100
python-defaults (2.6.6-6) experimental; urgency=low
* dh_python2:
......
......@@ -24,7 +24,7 @@ from debpython.pydist import parse_pydep, guess_dependency
from debpython.version import SUPPORTED, DEFAULT, debsorted, vrepr, vrange_str
# minimum version required for pycompile/pyclean
MINPYCDEP = 'python (>= 2.6.5-11~)'
MINPYCDEP = 'python (>= 2.6.6.7~)'
log = logging.getLogger(__name__)
......
#! /usr/bin/python
# -*- coding: UTF-8 -*-
# -*- coding: utf-8 -*-
# vim: et ts=4 sw=4
# Copyright © 2010 Piotr Ożarowski <piotr@debian.org>
......@@ -25,10 +25,11 @@
from __future__ import with_statement
import logging
import optparse
import os
import sys
from os import environ, listdir, walk
from os.path import abspath, exists, isdir, isfile, join
from subprocess import PIPE, Popen
from subprocess import PIPE, STDOUT, Popen
sys.path.insert(1, '/usr/share/python/')
from debpython.version import SUPPORTED, debsorted, vrepr, \
get_requested_versions, parse_vrange, getver
......@@ -169,7 +170,7 @@ def py_compile(version, workers):
version = vrepr(version)
cmd = "python%s -m py_compile -" % version
process = Popen(cmd, bufsize=1, shell=True,
stdin=PIPE, close_fds=True)
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
workers[version] = process # keep the reference for .communicate()
stdin = process.stdin
while True:
......@@ -177,7 +178,7 @@ def py_compile(version, workers):
stdin.write(filename + '\n')
def compile(files, versions, e_patterns=None):
def compile(files, versions, force, e_patterns=None):
global STDINS, WORKERS
# start Python interpreters that will handle byte compilation
for version in versions:
......@@ -188,8 +189,15 @@ def compile(files, versions, e_patterns=None):
# byte compile files
for fn, versions_to_compile in filter_files(files, e_patterns, versions):
if exists("%sc" % fn):
continue
if not force:
cfn = fn + (__debug__ and 'c' or 'o')
ftime = os.stat(fn).st_mtime
try:
ctime = os.stat(cfn).st_mtime
except os.error:
ctime = 0
if (ctime > ftime):
continue
for version in versions_to_compile:
try:
pipe = STDINS[version]
......@@ -211,6 +219,8 @@ def main():
help='turn verbose mode on')
parser.add_option('-q', '--quiet', action='store_false', dest='verbose',
default=False, help='be quiet')
parser.add_option('-f', '--force', action='store_true', dest='force',
default=False, help='force rebuild even if timestamps are up-to-date')
parser.add_option('-p', '--package',
help='specify Debian package name whose files should be bytecompiled')
parser.add_option('-V', type='version_range', dest='vrange',
......@@ -267,27 +277,33 @@ multiple times to build up a list of things to exclude.')
log.debug('byte compiling %s using Python %s',
item, compile_versions)
files = get_private_files(pkg_files, item)
compile(files, compile_versions, e_patterns)
compile(files, compile_versions, options.force, e_patterns)
elif options.package: # package's public modules
# no need to limit versions here, it's either pyr mode or version is
# hardcoded in path / via -V option
e_patterns = get_exclude_patterns()
files = get_package_files(options.package)
files = get_public_files(files, versions)
compile(files, versions, e_patterns)
compile(files, versions, options.force, e_patterns)
elif args: # other directories/files (public ones mostly)
versions = debsorted(versions)[:1]
for item in args:
e_patterns = get_exclude_patterns(item, options.regexpr, versions)
files = get_directory_files(item)
compile(files, versions, e_patterns)
compile(files, versions, options.force, e_patterns)
else:
parser.print_usage()
exit(1)
# wait for all processes to finish
rv = 0
for process in WORKERS.itervalues():
process.communicate()
(child_output, child_unused) = process.communicate()
if process.returncode not in (None, 0):
# FIXME: find out the package the file belongs to
sys.stderr.write(child_output)
rv = process.returncode
sys.exit(rv)
if __name__ == '__main__':
main()
.TH PYCOMPILE "1" "August 2010" "pycompile 0.9" "User Commands"
.SH NAME
pycompile \- byte compiles Python source files
pycompile \- byte compile Python source files
.SH SYNOPSIS
.B pycompile
[\fI-V \fR[\fIX.Y\fR][\fI-\fR][\fIA.B\fR]] \fIDIR_OR_FILE \fR[\fI-X REGEXPR\fR]
.P
.B pycompile
\fB\-p\fR PACKAGE
.SH DESCRIPTION
.IP
pycompile \fB\-p\fR PACKAGE
Wrapper around
.B py_compile
to byte-compile python files.
.SH OPTIONS
.TP
\fB\-\-version\fR
show program's version number and exit
Show program's version number and exit.
.TP
\fB\-h\fR, \fB\-\-help\fR
show this help message and exit
Show this help message and exit
.TP
\fB\-v\fR, \fB\-\-verbose\fR
turn verbose mode on
\fB\-f\fR, \fB\-\-force\fR
Force rebuild of byte-code files even if timestamps are up-to-date.
.TP
\fB\-q\fR, \fB\-\-quiet\fR
be quiet
Be quiet.
.TP
\fB\-v\fR, \fB\-\-verbose\fR
Turn verbose mode on.
.TP
\fB\-p\fR PACKAGE, \fB\-\-package\fR=\fIPACKAGE\fR
specify Debian package name whose files should be
bytecompiled
Specify Debian package name whose files should be
bytecompiled.
.TP
\fB\-V\fR VRANGE
force private modules to be bytecompiled with Python
Force private modules to be bytecompiled with Python
version from given range, regardless of the default
Python version in the system. If there are no other
options, bytecompile all public modules for installed
Python versions that match given range. VERSION_RANGE
examples: '2.5' (version 2.5 only), '2.5\-' (version
2.5 or newer), '2.5\-2.7' (version 2.5 or 2.6), '\-3.0'
(all supported 2.X versions)
(all supported 2.X versions).
.TP
\fB\-X\fR REGEXPR, \fB\-\-exclude\fR=\fIREGEXPR\fR
exclude items that match given REGEXPR. You may use
......
......@@ -2,8 +2,15 @@
set -e
VERSION=${2#python}
case "$VERSION" in
2.[45])
sitedir=/usr/lib/python$VERSION/site-packages;;
*)
sitedir=/usr/lib/python$VERSION/dist-packages
esac
if which python >/dev/null 2>&1 && which pycompile >/dev/null 2>&1; then
pycompile -V $VERSION /usr/lib/python$VERSION/
pycompile -V $VERSION $sitedir
else
echo >&2 "python or pycompile not found in $(basename $0) hook."
exit 1
......
......@@ -2,8 +2,15 @@
set -e
VERSION=${2#python}
case "$VERSION" in
2.[45])
sitedir=/usr/lib/python$VERSION/site-packages;;
*)
sitedir=/usr/lib/python$VERSION/dist-packages
esac
if which python >/dev/null 2>&1 && which pyclean >/dev/null 2>&1; then
pyclean /usr/lib/python$VERSION/
pyclean $sitedir
else
find /usr/lib/python$VERSION/ -name '*.py[co]' -delete
find $sitedir -name '*.py[co]' -delete
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment