Bug 3413 - Importing filemerge will crash when Mercurial is distributed as a byte-compiled package
Summary: Importing filemerge will crash when Mercurial is distributed as a byte-compil...
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-30 15:36 UTC by Hao Lian
Modified: 2012-05-13 05:07 UTC (History)
2 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hao Lian 2012-04-30 15:36 UTC
Hi! Python will crash with a None dereference error on this line:

  http://selenic.com/hg/file/038b389d80f5/mercurial/filemerge.py#l28

It assumes __doc__ is always non-None, which is not true when byte-
compilation strips function docstrings out. Our use case is that we run 
py2exe on our product, which uses Mercurial. (We ship the source code 
separately in a ZIP per GPL.) When it imports Mercurial's modules, which 
cause an import to filemerge, Python crashes on that line because py2exe 
byte-compiles all the source files.

It'd be awesome a patch for this could be accepted for 2.2; I'll submit a 
patch tomorrow if nobody else does (I have to head home now).
Comment 1 Matt Mackall 2012-04-30 15:46 UTC
Stripping out doc strings will almost certainly break most of the built-in
help support?

We know that there's more to this than py2exe as TortoiseHG also uses py2exe
without hitting this.

More likely, this is related to Python's -OO option:

-O     : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO    : remove doc-strings in addition to the -O optimizations

And those optimizations are basically negligible. So, yes, we could fix
this, but it seems easier to just turn off "optimization" which results in
fewer surprises for developers.
Comment 2 Hao Lian 2012-05-01 09:14 UTC
Noted, thanks.
Comment 3 Bugzilla 2012-05-12 09:30 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:30 EDT  ---

This bug was previously known as _bug_ 3412 at http://mercurial.selenic.com/bts/issue3412