Skip to content
Snippets Groups Projects
Commit 592eb6da authored by Piotr Ożarowski's avatar Piotr Ożarowski
Browse files

pycompile: do not exit before all background byte compilation is finished

(closes: 590224)
parent 13a07ea7
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,8 @@ python-defaults (2.6.5-10) UNRELEASED; urgency=low
- add --depend command line option (use it if requires.txt
doesn't contain dependency that package needs)
- add {/usr,}/sbin to the list of directories with checked shebangs
* pycompile: do not exit before all background byte compilation is finished
(closes: 590224)
-- Piotr Ożarowski <piotr@debian.org> Wed, 21 Jul 2010 21:10:19 +0200
......
......@@ -119,7 +119,7 @@ class Dependencies(object):
# make sure pycompile binary is available
if stats['compile']:
self.depend("python (>= 2.6.5-9~)")
self.depend("python (>= 2.6.5-10~)")
for interpreter, version in stats['shebangs']:
self.depend(interpreter)
......
......@@ -33,7 +33,7 @@ from subprocess import Popen, PIPE
# initialize script
logging.basicConfig(format='%(levelname).1s: %(module)s:%(lineno)d: '
'%(message)s')
log = logging.getLogger('pyclean')
log = logging.getLogger(__name__)
"""TODO: move it to manpage
Examples:
......@@ -43,12 +43,7 @@ Examples:
def destroyer(): # ;-)
"""Removes every .py[co] file associated to received .py file.
:param magic_tags: if True, removes __pycache__ directories,
if None, removes .py[co] files (PEP 3147 mode turned off),
otherwise removes set of magic tags from __pycache__ directory
"""
"""Removes every .py[co] file associated to received .py file."""
def find_files_to_remove(pyfile):
for filename in ("%sc" % pyfile, "%so" % pyfile):
......@@ -61,14 +56,14 @@ def destroyer(): # ;-)
pyfile = (yield)
for filename in find_files_to_remove(pyfile):
try:
log.debug('removing %s', filename)
remove(filename)
counter += 1
except (IOError, OSError), e:
log.error('cannot remove %s', filename)
log.debug(e)
except GeneratorExit:
if counter:
log.info("removed files: %s", counter)
log.info("removed files: %s", counter)
def get_files(items):
......@@ -108,16 +103,13 @@ def main():
(options, args) = parser.parse_args()
if options.verbose:
log.setLevel(logging.INFO)
else:
log.setLevel(logging.WARNING)
if environ.get('PYCLEAN_DEBUG') == '1':
if options.verbose or environ.get('PYCLEAN_DEBUG') == '1':
log.setLevel(logging.DEBUG)
log.debug('argv: %s', sys.argv)
log.debug('options: %s', options)
log.debug('args: %s', args)
else:
log.setLevel(logging.WARNING)
d = destroyer()
d.next() # initialize coroutine
......
......@@ -38,8 +38,9 @@ from debpython.tools import memoize
# initialize script
logging.basicConfig(format='%(levelname).1s: %(module)s:%(lineno)d: '
'%(message)s')
log = logging.getLogger('pycompile')
log = logging.getLogger(__name__)
STDINS = {}
WORKERS = {}
"""TODO: move it to manpage
Examples:
......@@ -158,22 +159,24 @@ def filter_files(files, e_patterns, compile_versions):
### COMPILE ####################################################
def py_compile(version):
def py_compile(version, workers):
if not isinstance(version, basestring):
version = vrepr(version)
cmd = "python%s -m py_compile -" % version
stdin = Popen(cmd, bufsize=1, shell=True, stdin=PIPE).stdin
process = Popen(cmd, bufsize=1, shell=True, stdin=PIPE)
workers[version] = process # keep the reference for .communicate()
stdin = process.stdin
while True:
filename = (yield)
stdin.write(filename + '\n')
def compile(files, versions, e_patterns=None):
global STDINS
global STDINS, WORKERS
# start Python interpreters that will handle byte compilation
for version in versions:
if version not in STDINS:
coroutine = py_compile(version)
coroutine = py_compile(version, WORKERS)
coroutine.next()
STDINS[version] = coroutine
......@@ -213,15 +216,13 @@ multiple times to build up a list of things to exclude.')
(options, args) = parser.parse_args()
if options.verbose:
log.setLevel(logging.INFO)
else:
log.setLevel(logging.WARN)
if environ.get('PYCOMPILE_DEBUG') == '1':
if options.verbose or environ.get('PYCOMPILE_DEBUG') == '1':
log.setLevel(logging.DEBUG)
log.debug('argv: %s', sys.argv)
log.debug('options: %s', options)
log.debug('args: %s', args)
else:
log.setLevel(logging.WARN)
if options.regexpr and not args:
parser.error('--exclude option works with private directories '
......@@ -266,5 +267,9 @@ multiple times to build up a list of things to exclude.')
parser.print_usage()
exit(1)
# wait for all processes to finish
for process in WORKERS.itervalues():
process.communicate()
if __name__ == '__main__':
main()
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