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: distutils always ignores byte compilation errors
Type: behavior Stage: resolved
Components: Distutils Versions: Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: eric.araujo Nosy List: Oliver.Jeeves, dhduvall, dstufft, eric.araujo, lwcolton, tarek, vstinner
Priority: normal Keywords: easy

Created on 2010-02-12 17:29 by Oliver.Jeeves, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (11)
msg99273 - (view) Author: Oliver Jeeves (Oliver.Jeeves) Date: 2010-02-12 17:29
When trying to build a python package for distribution, compile errors are always ignored. The setup function will return successfully even if it was unable to compile some modules due to, for example, indentation errors.

The specific situation I'm trying to deal with, is a script that builds a large number of eggs, and trying to detect if something went wrong.

I see that this has been raised as a bug for setuptools:

But it's not considered an issue because it's how distutils works.

distutils.util.byte_compile calls py_compile.compile, but does not pass a doraise argument to it.

The only suggestion for how to get tools that use distutils.util.byte_compile (like setuptools.setup and distutils.core.setup) to exit on an error is to monkey patch py_compile.compile to change its default doraise argument to True. That suggestion came from here:

supressing compile errors when making a distribution seems like a bug to me, but just having the option to easily change this behaviour would be great.
msg213474 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-03-13 21:22
This may have been done on purpose, to allow nearly-valid Python files to be packaged.  In other bug reports we got some use cases: files used as templates; custom dialects converted by import hooks; 2.x and 3.x code in the same sdist.  In that light, I think distutils should not raise exceptions (to allow these use cases) but should log warnings (to help people catch legitimate errors).
msg213476 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-03-13 21:24
Another use case from #10530: deliberately broken modules for testing.
msg213477 - (view) Author: Donald Stufft (dstufft) * (Python committer) Date: 2014-03-13 21:25
It would also break some 2/3 compatible projects who have a python3 and a python2 file sitting next to each other and dynamically selected and imported based on Python version.
msg213938 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-03-18 02:52
We all agree Python files with invalid syntax should be allowed, but some error message should be logged.  From the py_compile docs, this is already what the compile function does if the doraise argument is false (default), so what’s needed here is a unit test that makes sure we get a warning and the bad file is included in the sdist.

(I think we should not be concerned by the direct print to stderr instead of using proper logging: distutils uses its own logging system which lets one control the verbosity but does not have flexible filters, handlers and configuration, so in effect it’s like print to stderr.)
msg226285 - (view) Author: Danek Duvall (dhduvall) Date: 2014-09-02 21:55
As a distribution maintainer of several Python modules, I've run into this bug twice in the past week.  In each case, the python file in question had a SyntaxError and failed to compile, but the error just scrolled past in a large log and was missed because no failure occurred until we attempted to package the result, and the .pyc files were missing.

While we managed to track the problem down fairly easily in both cases, if we only had folks working on the problem that didn't have lots of experience in tracking down build issues, this could have wasted a lot of otherwise valuable engineering time.

I understand the desire to be able to package files that fail to compile, but having that be the default seems to me like it fails basic expectations, even given how long this bug has been around.  I can't imagine that the number of deliberately-broken python files is particularly large compared to the number of python files that might get broken accidentally (or files that are "broken" for one version of python but not another) and so being required to maintain an exception list doesn't seem unreasonable.  (Neither does some amount of transition period -- one or two minor releases of Python? -- between the introduction of the mechanism and the change of the default.)

Would people be interested in a patch to that effect?
msg226287 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-09-02 22:16
Again, I think this behaviour was a deliberate decision, not a patch.  Developers should use tests to detect syntax errors in their code, not rely on distutils byte compilation.
msg226288 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-09-02 22:16
a deliberate decision, not a bug*
msg226289 - (view) Author: Danek Duvall (dhduvall) Date: 2014-09-02 22:47
Absolutely true that developers should have tests that would detect such bugs.  However, the sooner you detect a bug, the more time you save.  And by the time it reaches someone like me, who is just packaging up the module for distribution with an OS, it's just going to waste my time, too, with less benefit (because I'm still not going to have much of an incentive to write tests).

Imagine if your C compiler only warned about code that wouldn't compile, and failed to produce the corresponding .o file without erroring out, and the linker failed to error out when that .o file was missing, and that you only noticed the problem when you ran your tests (or, if you're just shipping someone else's code, when your customer calls you to complain).  Wouldn't you think that was stunningly broken?

Again, I get that there are use cases for having broken code pass through unscathed, but it seems very odd to me (as someone with a long unix background) that this would have been a conscious default.  Now that it is the default, I understand the need for caution, but caution needn't (and shouldn't) prevent bugs from getting fixed.
msg229400 - (view) Author: Colton Leekley-Winslow (lwcolton) * Date: 2014-10-15 03:34
Also agree setup allowing broken code an be annoying, but it is necessary to maintain the existing behavior.  Maybe we need an additional argument for setup that will in turn pass doraise to py_compile.compile, but retain the default behavior in all other cases?  As a work-around to your problem, try "pylint -E" before you build your package, we require it as a part of our build process.
msg348626 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-29 11:40
It seems like this issue is not a bug, I close it.
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52166
2019-07-29 11:40:02vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg348626

resolution: not a bug
stage: needs patch -> resolved
2014-10-15 03:34:51lwcoltonsetnosy: + lwcolton
messages: + msg229400
2014-09-02 22:47:26dhduvallsetmessages: + msg226289
2014-09-02 22:16:37eric.araujosetmessages: + msg226288
2014-09-02 22:16:20eric.araujosetmessages: + msg226287
2014-09-02 21:55:58dhduvallsetmessages: + msg226285
2014-09-02 21:37:41dhduvallsetnosy: + dhduvall
2014-03-18 02:52:36eric.araujosetmessages: + msg213938
2014-03-13 21:25:50dstufftsetnosy: + dstufft
messages: + msg213477
2014-03-13 21:24:24eric.araujosetmessages: + msg213476
2014-03-13 21:23:27eric.araujosetmessages: - msg122428
2014-03-13 21:22:36eric.araujosetassignee: tarek -> eric.araujo
components: + Distutils, - Distutils2
title: distutils always ignores compile errors -> distutils always ignores byte compilation errors
keywords: + easy
type: enhancement -> behavior
versions: + Python 2.7, Python 3.3, Python 3.4, - 3rd party
messages: + msg213474
2010-11-26 02:15:04eric.araujosetversions: + 3rd party, - Python 3.2
nosy: + eric.araujo

messages: + msg122428

components: + Distutils2, - Distutils
stage: needs patch
2010-07-10 23:29:27terry.reedysetversions: + Python 3.2, - Python 2.6
2010-02-12 17:29:06Oliver.Jeevescreate