This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Silent mode for compileall
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: berker.peksag Nosy List: berker.peksag, eric.araujo, ezio.melotti, python-dev, r.david.murray, steven.daprano, takluyver
Priority: normal Keywords: easy, patch

Created on 2014-04-23 23:29 by takluyver, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
compileall_silent.patch takluyver, 2014-04-24 01:28 review
issue21338.diff berker.peksag, 2014-10-05 03:24 review
Messages (12)
msg217100 - (view) Author: Thomas Kluyver (takluyver) * Date: 2014-04-23 23:29
The compileall module's command line interface has a -q (quiet) flag which suppresses most of the output, but it still prints error messages. I'd like an entirely silent mode with no output.

My use case is byte-compiling Python files as part of a graphical installer. I do this by running:

py -${PY_QUALIFIER} -m compileall -q "$INSTDIR\pkgs"

I'd like to be able to use pyw so a terminal doesn't pop up, but if I do that, it exits early. I think this is due to the issue with stdout/stderr buffers filling up on pythonw.
msg217102 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2014-04-23 23:36
This seems a reasonable request.  Do you want to propose a patch?
msg217106 - (view) Author: Thomas Kluyver (takluyver) * Date: 2014-04-24 01:14
Patch attached.

This works by making the -q flag countable, so you pass -qq to suppress all output. In the Python API, the quiet parameter has become an integer, so passing 2 is equivalent to -qq. This should be fully backwards compatible with passing True and False, which are equivalent to 1 and 0.
msg217107 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2014-04-24 01:15
Can't you just re-direct stdout or stderr? I'm sure that works even on Windows. E.g.

py -${PY_QUALIFIER} -m compileall -q "$INSTDIR\pkgs" 2> null

Is there a reason you cannot do this? I think that adding functionality to compileall to duplicate what your OS already provides should be a last resort.

I also don't understand what you mean by "it exits early". What exits early? Surely python doesn't exit until compileall finishes running. If it does, that's a bug.
msg217108 - (view) Author: Thomas Kluyver (takluyver) * Date: 2014-04-24 01:26
Sorry, I somehow attached an old version of the patch. This one should be correct.

Steven: Redirection relies on a shell - the native 'run a process' interface that the installer uses can't do that. There are ways to work around this, but I think this approach makes sense.

It exits early because stdout and stderr don't go anywhere, so once either of them has filled up a fairly small buffer, attempts to write to it throw an error. I'd love to see that fixed, but it's been known about for years (see issue 706263), and it seems unlikely to change any time soon.
msg217109 - (view) Author: Thomas Kluyver (takluyver) * Date: 2014-04-24 01:28
Gah, still wrong. Trying again.
msg217111 - (view) Author: Thomas Kluyver (takluyver) * Date: 2014-04-24 02:12
In fact, I will probably end up working around this anyway, because I'll have to support versions of Python without this fix for some time. So I don't feel strongly that it needs to go in, but I will do any revisions or changes requested if people think it would be useful.
msg217167 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-04-25 19:26
Patch looks to me comprehensive and backward-compatible.  Thanks Thomas!
msg227800 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-09-29 14:34
Berker: I had some review comments pending on the docs, but reitveld isn't letting me publish them for some reason (it says the patch set doesn't exist).

The comments are: the method docs should probably say "``False`` or ``0`` (the default)" (and all the numbers should be marked up as code), and the versionchanged I think should say that the option was changed to a multilevel value.

Otherwise the patch looks good to me, too.
msg228534 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-10-05 03:24
Here's an updated patch. Thanks David.
msg229406 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-15 08:10
New changeset 34436ae65523 by Berker Peksag in branch 'default':
Issue #21338: Add silent mode for compileall.
msg229407 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-10-15 08:11
Thanks for the patch, Thomas.
Date User Action Args
2022-04-11 14:58:02adminsetgithub: 65537
2014-10-15 08:11:56berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg229407

stage: commit review -> resolved
2014-10-15 08:10:24python-devsetnosy: + python-dev
messages: + msg229406
2014-10-05 03:24:36berker.peksagsetfiles: + issue21338.diff

messages: + msg228534
2014-09-29 14:34:33r.david.murraysetmessages: + msg227800
2014-08-22 13:02:22berker.peksagsetassignee: berker.peksag

nosy: + berker.peksag
2014-05-14 13:46:57r.david.murraysetnosy: + r.david.murray
2014-04-25 19:26:39eric.araujosetnosy: + eric.araujo
messages: + msg217167

type: enhancement
stage: needs patch -> commit review
2014-04-24 02:12:45takluyversetmessages: + msg217111
2014-04-24 01:28:47takluyversetfiles: + compileall_silent.patch

messages: + msg217109
2014-04-24 01:28:27takluyversetfiles: - compileall_silent.patch
2014-04-24 01:26:54takluyversetfiles: + compileall_silent.patch

messages: + msg217108
2014-04-24 01:15:38steven.dapranosetnosy: + steven.daprano
messages: + msg217107
2014-04-24 01:15:26takluyversetfiles: - compileall_silent.patch
2014-04-24 01:14:22takluyversetfiles: + compileall_silent.patch
type: enhancement -> (no value)
messages: + msg217106

keywords: + patch
2014-04-23 23:36:44ezio.melottisettype: enhancement
versions: + Python 3.5
keywords: + easy
nosy: + ezio.melotti

messages: + msg217102
stage: needs patch
2014-04-23 23:29:32takluyvercreate