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

- Use the correct python interpreter when called with -O.

    - Add options -l/--lazy, -O.
parent d72d9624
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,8 @@ 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.
- Use the correct python interpreter when called with -O.
- Add options -f/--force, -l/--lazy, -O.
- Copy stdout/stderr of py_compile processes in case of error.
- Propagate the exit value of the py_compile processes.
- Update manual page.
......
......@@ -3,6 +3,7 @@
# vim: et ts=4 sw=4
# Copyright © 2010 Piotr Ożarowski <piotr@debian.org>
# Copyright © 2010 Canonical Ltd
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
......@@ -165,10 +166,11 @@ def filter_files(files, e_patterns, compile_versions):
### COMPILE ####################################################
def py_compile(version, workers):
def py_compile(version, optimize, workers):
if not isinstance(version, basestring):
version = vrepr(version)
cmd = "python%s -m py_compile -" % version
cmd = "python%s%s -m py_compile -" \
% (version, (__debug__ or optimize) and '' or ' -O')
process = Popen(cmd, bufsize=1, shell=True,
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
workers[version] = process # keep the reference for .communicate()
......@@ -178,19 +180,21 @@ def py_compile(version, workers):
stdin.write(filename + '\n')
def compile(files, versions, force, e_patterns=None):
def compile(files, versions, force, lazy, optimize, e_patterns=None):
global STDINS, WORKERS
# start Python interpreters that will handle byte compilation
for version in versions:
if version not in STDINS:
coroutine = py_compile(version, WORKERS)
coroutine = py_compile(version, optimize, WORKERS)
coroutine.next()
STDINS[version] = coroutine
# byte compile files
for fn, versions_to_compile in filter_files(files, e_patterns, versions):
cfn = fn + ((__debug__ or optimize) and 'c' or 'o')
if lazy and exists(cfn):
continue
if not force:
cfn = fn + (__debug__ and 'c' or 'o')
ftime = os.stat(fn).st_mtime
try:
ctime = os.stat(cfn).st_mtime
......@@ -221,6 +225,10 @@ def main():
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('-l', '--lazy', action='store_true', dest='lazy',
default=False, help="don' t check if byte-code files are up-to-date")
parser.add_option('-O', action='store_true', dest='optimize',
default=False, help="byte-compile to .pyo files")
parser.add_option('-p', '--package',
help='specify Debian package name whose files should be bytecompiled')
parser.add_option('-V', type='version_range', dest='vrange',
......@@ -246,6 +254,10 @@ multiple times to build up a list of things to exclude.')
else:
log.setLevel(logging.WARN)
if options.force and options.lazy:
options.lazy = False
log.warn('--force is in effect, ignore --lazy')
if options.regexpr and not args:
parser.error('--exclude option works with private directories '
'only, please use /usr/share/python/bcep to specify '
......@@ -277,20 +289,23 @@ 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, options.force, e_patterns)
compile(files, compile_versions, options.force, options.lazy,
options.optimize, 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, options.force, e_patterns)
compile(files, versions,
options.force, options.lazy, options.optimize, 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, options.force, e_patterns)
compile(files, versions,
options.force, options.lazy, options.optimize, e_patterns)
else:
parser.print_usage()
exit(1)
......
......@@ -22,6 +22,13 @@ Show this help message and exit
\fB\-f\fR, \fB\-\-force\fR
Force rebuild of byte-code files even if timestamps are up-to-date.
.TP
\fB\-l\fR, \fB\-\-lazy\fR
Do not rebuild byte-code files even if timestamps are out-of-date (ignored when
\fB\-\-force\fR is in effect).
.TP
\fB\-O\fR
Byte-compile to .pyo files.
.TP
\fB\-q\fR, \fB\-\-quiet\fR
Be quiet.
.TP
......
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