Mercurial > hg
annotate hgext/highlight/__init__.py @ 17732:93d97a212559
exewrapper: adapt for legacy HackableMercurial
We give up using CPython's PythonXX.lib import libraries (and Python.h), and
now "manually" call the LoadLibrary() / GetProcAddress() Windows API's instead.
If there is a "hg-python" subdirectory (the canonical directory name for
HackableMercurial's private Python copy) next to the hg.exe, we load the
pythonXX.dll from there (feeding an absolute path to LoadLibrary) and we set
Py_SetPythonHome() to that directory, so that the Python libraries are used
from there as well.
If there is no "hg-python" subdir found next to the hg.exe, we do not feed an
absolute path to LoadLibrary. This continues to allow to find a globally
installed Python DLL, as before this change - that is, without having to edit,
delete, rename, or configure anything.
Note that the hg.exe built is still bound to a *specific* major version of the
pythonXX.dll (e.g. python27.dll). What version it is, is inferred from the
version of the python interpreter that was used when calling setup.py. For
example
C:\python27_x86\python.exe setup.py build_hgexe -i --compiler=mingw32
builds a hg.exe (using the mingw32 tool chain) bound to (x86) Python 2.7. And
C:\python27_x86\python.exe setup.py build_hgexe -i
builds the same using the Microsoft C compiler/linker. (Note that the Microsoft
toolchain combined with x64 CPython can be used to build an x64 hg.exe.)
setup.py is changed to write the name of the pythonlib into the generated header
file "mercurial/hgpythonlib.h", which is #included by exewrapper.c. For a Python
2.7 build, it for example contains:
#define HGPYTHONLIB "python27"
exewrapper.c then uses HGPYTHONLIB for the name of the Python dll to load.
We don't want to track mercurial/hgpythonlib.h, so we add it to .hgignore.
author | Adrian Buehlmann <adrian@cadifra.com> |
---|---|
date | Tue, 07 Aug 2012 11:04:41 +0200 |
parents | 38caf405d010 |
children | 681f7b9213a4 |
rev | line source |
---|---|
8251
7fc30044b514
highlight: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7216
diff
changeset
|
1 # highlight - syntax highlighting in hgweb, based on Pygments |
7fc30044b514
highlight: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7216
diff
changeset
|
2 # |
7fc30044b514
highlight: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7216
diff
changeset
|
3 # Copyright 2008, 2009 Patrick Mezard <pmezard@gmail.com> and others |
7fc30044b514
highlight: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7216
diff
changeset
|
4 # |
7fc30044b514
highlight: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7216
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
8251
7fc30044b514
highlight: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7216
diff
changeset
|
7 # |
7fc30044b514
highlight: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7216
diff
changeset
|
8 # The original module was split in an interface and an implementation |
7fc30044b514
highlight: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7216
diff
changeset
|
9 # file to defer pygments loading and speedup extension setup. |
7fc30044b514
highlight: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7216
diff
changeset
|
10 |
8932
f87884329419
extensions: fix up description lines some more
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8894
diff
changeset
|
11 """syntax highlighting for hgweb (requires Pygments) |
6938
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
12 |
9262
917e1d5674d6
highlight: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9210
diff
changeset
|
13 It depends on the Pygments syntax highlighting library: |
917e1d5674d6
highlight: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9210
diff
changeset
|
14 http://pygments.org/ |
6938
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
15 |
9210
2667ca525b59
highlight: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9064
diff
changeset
|
16 There is a single configuration option:: |
6938
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
17 |
9210
2667ca525b59
highlight: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9064
diff
changeset
|
18 [web] |
2667ca525b59
highlight: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9064
diff
changeset
|
19 pygments_style = <style> |
6938
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
20 |
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
21 The default is 'colorful'. |
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
22 """ |
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
23 |
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
24 import highlight |
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
25 from mercurial.hgweb import webcommands, webutil, common |
8874
74baf78202e8
highlight: was broken since 580a79dde2a3 (encoding)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8866
diff
changeset
|
26 from mercurial import extensions, encoding |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
16683
diff
changeset
|
27 testedwith = 'internal' |
6938
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
28 |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7127
diff
changeset
|
29 def filerevision_highlight(orig, web, tmpl, fctx): |
8874
74baf78202e8
highlight: was broken since 580a79dde2a3 (encoding)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8866
diff
changeset
|
30 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) |
6987
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
31 # only pygmentize for mimetype containing 'html' so we both match |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
32 # 'text/html' and possibly 'application/xhtml+xml' in the future |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
33 # so that we don't have to touch the extension when the mimetype |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
34 # for a template changes; also hgweb optimizes the case that a |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
35 # raw file is sent using rawfile() and doesn't call us, so we |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
36 # can't clash with the file's content-type here in case we |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
37 # pygmentize a html file |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
38 if 'html' in mt: |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
39 style = web.config('web', 'pygments_style', 'colorful') |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
40 highlight.pygmentize('fileline', fctx, style, tmpl) |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7127
diff
changeset
|
41 return orig(web, tmpl, fctx) |
6938
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
42 |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7127
diff
changeset
|
43 def annotate_highlight(orig, web, req, tmpl): |
8874
74baf78202e8
highlight: was broken since 580a79dde2a3 (encoding)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8866
diff
changeset
|
44 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) |
6987
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
45 if 'html' in mt: |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
46 fctx = webutil.filectx(web.repo, req) |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
47 style = web.config('web', 'pygments_style', 'colorful') |
d09e813b21e3
highlight: only pygmentize for HTML mimetypes
Rocco Rutte <pdmef@gmx.net>
parents:
6938
diff
changeset
|
48 highlight.pygmentize('annotateline', fctx, style, tmpl) |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7127
diff
changeset
|
49 return orig(web, req, tmpl) |
6938
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
50 |
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
51 def generate_css(web, req, tmpl): |
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
52 pg_style = web.config('web', 'pygments_style', 'colorful') |
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
53 fmter = highlight.HtmlFormatter(style = pg_style) |
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
54 req.respond(common.HTTP_OK, 'text/css') |
16683 | 55 return ['/* pygments_style = %s */\n\n' % pg_style, |
56 fmter.get_style_defs('')] | |
6938
ce94b3236ea4
highlight: split code to improve startup times
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
57 |
9409
57157a224037
highlight: move code from module top-level into extsetup
Martin Geisler <mg@lazybytes.net>
parents:
9262
diff
changeset
|
58 def extsetup(): |
57157a224037
highlight: move code from module top-level into extsetup
Martin Geisler <mg@lazybytes.net>
parents:
9262
diff
changeset
|
59 # monkeypatch in the new version |
16683 | 60 extensions.wrapfunction(webcommands, '_filerevision', |
61 filerevision_highlight) | |
9409
57157a224037
highlight: move code from module top-level into extsetup
Martin Geisler <mg@lazybytes.net>
parents:
9262
diff
changeset
|
62 extensions.wrapfunction(webcommands, 'annotate', annotate_highlight) |
57157a224037
highlight: move code from module top-level into extsetup
Martin Geisler <mg@lazybytes.net>
parents:
9262
diff
changeset
|
63 webcommands.highlightcss = generate_css |
57157a224037
highlight: move code from module top-level into extsetup
Martin Geisler <mg@lazybytes.net>
parents:
9262
diff
changeset
|
64 webcommands.__all__.append('highlightcss') |