pygments.rb 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +40 -0
- data/README.md +3 -0
- data/lexers +0 -0
- data/lib/pygments/popen.rb +3 -2
- data/lib/pygments/version.rb +1 -1
- data/pygments.rb.gemspec +2 -1
- data/vendor/pygments-main/AUTHORS +20 -1
- data/vendor/pygments-main/CHANGES +55 -3
- data/vendor/pygments-main/LICENSE +1 -1
- data/vendor/pygments-main/MANIFEST.in +1 -1
- data/vendor/pygments-main/Makefile +5 -8
- data/vendor/pygments-main/REVISION +1 -1
- data/vendor/pygments-main/doc/Makefile +153 -0
- data/vendor/pygments-main/doc/_static/favicon.ico +0 -0
- data/vendor/pygments-main/doc/_static/logo_new.png +0 -0
- data/vendor/pygments-main/doc/_static/logo_only.png +0 -0
- data/vendor/pygments-main/doc/_templates/docssidebar.html +3 -0
- data/vendor/pygments-main/doc/_templates/indexsidebar.html +25 -0
- data/vendor/pygments-main/doc/_themes/pygments14/layout.html +98 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/bodybg.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/docbg.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/listitem.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/logo.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/pocoo.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/pygments14.css_t +401 -0
- data/vendor/pygments-main/doc/_themes/pygments14/theme.conf +15 -0
- data/vendor/pygments-main/doc/conf.py +249 -0
- data/vendor/pygments-main/doc/docs/api.rst +316 -0
- data/vendor/pygments-main/doc/docs/authors.rst +4 -0
- data/vendor/pygments-main/doc/docs/changelog.rst +1 -0
- data/vendor/pygments-main/{docs/src/cmdline.txt → doc/docs/cmdline.rst} +9 -11
- data/vendor/pygments-main/{docs/src/filterdevelopment.txt → doc/docs/filterdevelopment.rst} +1 -1
- data/vendor/pygments-main/{docs/src/filters.txt → doc/docs/filters.rst} +4 -5
- data/vendor/pygments-main/{docs/src/formatterdevelopment.txt → doc/docs/formatterdevelopment.rst} +1 -1
- data/vendor/pygments-main/{docs/src/formatters.txt → doc/docs/formatters.rst} +6 -6
- data/vendor/pygments-main/doc/docs/index.rst +66 -0
- data/vendor/pygments-main/{docs/src/integrate.txt → doc/docs/integrate.rst} +3 -7
- data/vendor/pygments-main/{docs/src/java.txt → doc/docs/java.rst} +0 -0
- data/vendor/pygments-main/{docs/src/lexerdevelopment.txt → doc/docs/lexerdevelopment.rst} +13 -14
- data/vendor/pygments-main/{docs/src/lexers.txt → doc/docs/lexers.rst} +7 -5
- data/vendor/pygments-main/{docs/src/moinmoin.txt → doc/docs/moinmoin.rst} +0 -0
- data/vendor/pygments-main/{docs/src/plugins.txt → doc/docs/plugins.rst} +0 -0
- data/vendor/pygments-main/{docs/src/quickstart.txt → doc/docs/quickstart.rst} +22 -19
- data/vendor/pygments-main/{docs/src/rstdirective.txt → doc/docs/rstdirective.rst} +0 -0
- data/vendor/pygments-main/{docs/src/styles.txt → doc/docs/styles.rst} +2 -2
- data/vendor/pygments-main/{docs/src/tokens.txt → doc/docs/tokens.rst} +10 -7
- data/vendor/pygments-main/{docs/src/unicode.txt → doc/docs/unicode.rst} +8 -7
- data/vendor/pygments-main/doc/download.rst +41 -0
- data/vendor/pygments-main/doc/faq.rst +143 -0
- data/vendor/pygments-main/doc/index.rst +53 -0
- data/vendor/pygments-main/doc/languages.rst +151 -0
- data/vendor/pygments-main/doc/make.bat +190 -0
- data/vendor/pygments-main/{docs → doc}/pygmentize.1 +0 -0
- data/vendor/pygments-main/external/autopygmentize +65 -48
- data/vendor/pygments-main/external/markdown-processor.py +15 -15
- data/vendor/pygments-main/external/moin-parser.py +1 -1
- data/vendor/pygments-main/external/rst-directive.py +2 -3
- data/vendor/pygments-main/ez_setup.py +340 -234
- data/vendor/pygments-main/pygments/__init__.py +4 -4
- data/vendor/pygments-main/pygments/cmdline.py +81 -68
- data/vendor/pygments-main/pygments/console.py +1 -1
- data/vendor/pygments-main/pygments/filter.py +1 -1
- data/vendor/pygments-main/pygments/filters/__init__.py +11 -9
- data/vendor/pygments-main/pygments/formatter.py +3 -3
- data/vendor/pygments-main/pygments/formatters/__init__.py +5 -3
- data/vendor/pygments-main/pygments/formatters/_mapping.py +16 -5
- data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
- data/vendor/pygments-main/pygments/formatters/html.py +44 -26
- data/vendor/pygments-main/pygments/formatters/img.py +21 -14
- data/vendor/pygments-main/pygments/formatters/latex.py +104 -12
- data/vendor/pygments-main/pygments/formatters/other.py +53 -6
- data/vendor/pygments-main/pygments/formatters/rtf.py +30 -16
- data/vendor/pygments-main/pygments/formatters/svg.py +2 -2
- data/vendor/pygments-main/pygments/formatters/terminal.py +41 -1
- data/vendor/pygments-main/pygments/formatters/terminal256.py +2 -2
- data/vendor/pygments-main/pygments/lexer.py +59 -39
- data/vendor/pygments-main/pygments/lexers/__init__.py +38 -15
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +15 -15
- data/vendor/pygments-main/pygments/lexers/_cocoabuiltins.py +73 -0
- data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +11 -1
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +14 -8
- data/vendor/pygments-main/pygments/lexers/_mapping.py +81 -30
- data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1067 -95
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +7 -7
- data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +5 -4
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +12 -7
- data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +112 -18
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/agile.py +644 -382
- data/vendor/pygments-main/pygments/lexers/asm.py +66 -29
- data/vendor/pygments-main/pygments/lexers/compiled.py +1643 -174
- data/vendor/pygments-main/pygments/lexers/dalvik.py +27 -6
- data/vendor/pygments-main/pygments/lexers/dotnet.py +45 -33
- data/vendor/pygments-main/pygments/lexers/foxpro.py +3 -3
- data/vendor/pygments-main/pygments/lexers/functional.py +1510 -570
- data/vendor/pygments-main/pygments/lexers/graph.py +81 -0
- data/vendor/pygments-main/pygments/lexers/hdl.py +29 -30
- data/vendor/pygments-main/pygments/lexers/inferno.py +96 -0
- data/vendor/pygments-main/pygments/lexers/jvm.py +622 -207
- data/vendor/pygments-main/pygments/lexers/math.py +438 -70
- data/vendor/pygments-main/pygments/lexers/other.py +885 -171
- data/vendor/pygments-main/pygments/lexers/parsers.py +24 -24
- data/vendor/pygments-main/pygments/lexers/qbasic.py +157 -0
- data/vendor/pygments-main/pygments/lexers/rdf.py +99 -0
- data/vendor/pygments-main/pygments/lexers/shell.py +28 -25
- data/vendor/pygments-main/pygments/lexers/special.py +7 -8
- data/vendor/pygments-main/pygments/lexers/sql.py +56 -23
- data/vendor/pygments-main/pygments/lexers/templates.py +377 -59
- data/vendor/pygments-main/pygments/lexers/text.py +208 -46
- data/vendor/pygments-main/pygments/lexers/web.py +729 -264
- data/vendor/pygments-main/pygments/modeline.py +1 -1
- data/vendor/pygments-main/pygments/plugin.py +1 -1
- data/vendor/pygments-main/pygments/scanner.py +1 -1
- data/vendor/pygments-main/pygments/sphinxext.py +153 -0
- data/vendor/pygments-main/pygments/style.py +3 -2
- data/vendor/pygments-main/pygments/styles/__init__.py +5 -1
- data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
- data/vendor/pygments-main/pygments/styles/borland.py +1 -1
- data/vendor/pygments-main/pygments/styles/bw.py +1 -1
- data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
- data/vendor/pygments-main/pygments/styles/default.py +1 -1
- data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
- data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
- data/vendor/pygments-main/pygments/styles/fruity.py +1 -1
- data/vendor/pygments-main/pygments/styles/igor.py +29 -0
- data/vendor/pygments-main/pygments/styles/manni.py +1 -1
- data/vendor/pygments-main/pygments/styles/monokai.py +4 -4
- data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
- data/vendor/pygments-main/pygments/styles/native.py +1 -1
- data/vendor/pygments-main/pygments/styles/paraiso_dark.py +125 -0
- data/vendor/pygments-main/pygments/styles/paraiso_light.py +125 -0
- data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
- data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
- data/vendor/pygments-main/pygments/styles/rrt.py +1 -1
- data/vendor/pygments-main/pygments/styles/tango.py +1 -1
- data/vendor/pygments-main/pygments/styles/trac.py +1 -1
- data/vendor/pygments-main/pygments/styles/vim.py +1 -1
- data/vendor/pygments-main/pygments/styles/vs.py +1 -1
- data/vendor/pygments-main/pygments/styles/xcode.py +51 -0
- data/vendor/pygments-main/pygments/token.py +4 -1
- data/vendor/pygments-main/pygments/unistring.py +6 -5
- data/vendor/pygments-main/pygments/util.py +35 -21
- data/vendor/pygments-main/scripts/check_sources.py +28 -44
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +5 -4
- data/vendor/pygments-main/scripts/find_codetags.py +27 -19
- data/vendor/pygments-main/scripts/find_error.py +16 -13
- data/vendor/pygments-main/scripts/get_vimkw.py +3 -3
- data/vendor/pygments-main/scripts/vim2pygments.py +9 -7
- data/vendor/pygments-main/setup.py +19 -19
- data/vendor/pygments-main/tests/examplefiles/99_bottles_of_beer.chpl +118 -0
- data/vendor/pygments-main/tests/examplefiles/Error.pmod +38 -0
- data/vendor/pygments-main/tests/examplefiles/FakeFile.pike +360 -0
- data/vendor/pygments-main/tests/examplefiles/{ANTLRv3.g → antlr_ANTLRv3.g} +0 -0
- data/vendor/pygments-main/tests/examplefiles/clojure-weird-keywords.clj +5 -0
- data/vendor/pygments-main/tests/examplefiles/core.cljs +52 -0
- data/vendor/pygments-main/tests/examplefiles/demo.cfm +13 -1
- data/vendor/pygments-main/tests/examplefiles/demo.hbs +12 -0
- data/vendor/pygments-main/tests/examplefiles/ember.handlebars +33 -0
- data/vendor/pygments-main/tests/examplefiles/example.als +217 -0
- data/vendor/pygments-main/tests/examplefiles/example.c +1 -1
- data/vendor/pygments-main/tests/examplefiles/example.chai +6 -0
- data/vendor/pygments-main/tests/examplefiles/example.coffee +27 -0
- data/vendor/pygments-main/tests/examplefiles/example.e +124 -0
- data/vendor/pygments-main/tests/examplefiles/example.f90 +8 -0
- data/vendor/pygments-main/tests/examplefiles/example.feature +16 -0
- data/vendor/pygments-main/tests/examplefiles/example.gd +23 -0
- data/vendor/pygments-main/tests/examplefiles/example.gi +64 -0
- data/vendor/pygments-main/tests/examplefiles/example.groovy +2 -0
- data/vendor/pygments-main/tests/examplefiles/example.hs +27 -0
- data/vendor/pygments-main/tests/examplefiles/example.hx +44 -1
- data/vendor/pygments-main/tests/examplefiles/example.i6t +32 -0
- data/vendor/pygments-main/tests/examplefiles/example.i7x +45 -0
- data/vendor/pygments-main/tests/examplefiles/example.inf +374 -0
- data/vendor/pygments-main/tests/examplefiles/example.j +564 -0
- data/vendor/pygments-main/tests/examplefiles/example.java +16 -0
- data/vendor/pygments-main/tests/examplefiles/example.kal +75 -0
- data/vendor/pygments-main/tests/examplefiles/example.liquid +42 -0
- data/vendor/pygments-main/tests/examplefiles/example.ma +8 -0
- data/vendor/pygments-main/tests/examplefiles/example.mq4 +187 -0
- data/vendor/pygments-main/tests/examplefiles/example.mqh +123 -0
- data/vendor/pygments-main/tests/examplefiles/example.ni +57 -0
- data/vendor/pygments-main/tests/examplefiles/example.nix +80 -0
- data/vendor/pygments-main/tests/examplefiles/example.pp +8 -0
- data/vendor/pygments-main/tests/examplefiles/example.red +257 -0
- data/vendor/pygments-main/tests/examplefiles/example.reds +150 -0
- data/vendor/pygments-main/tests/examplefiles/example.rkt +677 -29
- data/vendor/pygments-main/tests/examplefiles/example.sh +22 -0
- data/vendor/pygments-main/tests/examplefiles/example.slim +31 -0
- data/vendor/pygments-main/tests/examplefiles/example.sls +51 -0
- data/vendor/pygments-main/tests/examplefiles/example.stan +2 -0
- data/vendor/pygments-main/tests/examplefiles/example.todotxt +9 -0
- data/vendor/pygments-main/tests/examplefiles/exampleScript.cfc +241 -0
- data/vendor/pygments-main/tests/examplefiles/exampleTag.cfc +18 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +192 -350
- data/vendor/pygments-main/tests/examplefiles/hash_syntax.rb +5 -0
- data/vendor/pygments-main/tests/examplefiles/hello.at +6 -0
- data/vendor/pygments-main/tests/examplefiles/hello.golo +5 -0
- data/vendor/pygments-main/tests/examplefiles/hello.lsl +12 -0
- data/vendor/pygments-main/tests/examplefiles/{File.hy → hybris_File.hy} +0 -0
- data/vendor/pygments-main/tests/examplefiles/{mg_sample.pro → idl_sample.pro} +0 -0
- data/vendor/pygments-main/tests/examplefiles/iex_example +23 -0
- data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +24 -24
- data/vendor/pygments-main/tests/examplefiles/language.hy +165 -0
- data/vendor/pygments-main/tests/examplefiles/limbo.b +456 -0
- data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +3 -1
- data/vendor/pygments-main/tests/examplefiles/main.cmake +2 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +163 -16
- data/vendor/pygments-main/tests/examplefiles/{example.p → openedge_example} +0 -0
- data/vendor/pygments-main/tests/examplefiles/pawn_example +25 -0
- data/vendor/pygments-main/tests/examplefiles/qbasic_example +2 -0
- data/vendor/pygments-main/tests/examplefiles/r6rs-comments.scm +23 -0
- data/vendor/pygments-main/tests/examplefiles/{robotframework.txt → robotframework_test.txt} +0 -0
- data/vendor/pygments-main/tests/examplefiles/rql-queries.rql +34 -0
- data/vendor/pygments-main/tests/examplefiles/scope.cirru +43 -0
- data/vendor/pygments-main/tests/examplefiles/sparql.rq +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +37 -5
- data/vendor/pygments-main/tests/examplefiles/test.apl +26 -0
- data/vendor/pygments-main/tests/examplefiles/test.cyp +123 -0
- data/vendor/pygments-main/tests/examplefiles/test.idr +93 -0
- data/vendor/pygments-main/tests/examplefiles/test.mask +41 -0
- data/vendor/pygments-main/tests/examplefiles/test.pan +54 -0
- data/vendor/pygments-main/tests/examplefiles/test.php +3 -1
- data/vendor/pygments-main/tests/examplefiles/test.pig +148 -0
- data/vendor/pygments-main/tests/examplefiles/test.pwn +253 -0
- data/vendor/pygments-main/tests/examplefiles/test.r3 +27 -7
- data/vendor/pygments-main/tests/examplefiles/test.rsl +111 -0
- data/vendor/pygments-main/tests/examplefiles/test.swift +65 -0
- data/vendor/pygments-main/tests/examplefiles/test.zep +33 -0
- data/vendor/pygments-main/tests/examplefiles/unicode.go +10 -0
- data/vendor/pygments-main/tests/examplefiles/{test.bas → vbnet_test.bas} +0 -0
- data/vendor/pygments-main/tests/examplefiles/vctreestatus_hg +4 -0
- data/vendor/pygments-main/tests/examplefiles/vimrc +21 -0
- data/vendor/pygments-main/tests/run.py +14 -19
- data/vendor/pygments-main/tests/string_asserts.py +22 -0
- data/vendor/pygments-main/tests/test_basic_api.py +28 -14
- data/vendor/pygments-main/tests/test_cfm.py +46 -0
- data/vendor/pygments-main/tests/test_clexer.py +208 -3
- data/vendor/pygments-main/tests/test_cmdline.py +6 -5
- data/vendor/pygments-main/tests/test_examplefiles.py +30 -19
- data/vendor/pygments-main/tests/test_html_formatter.py +15 -13
- data/vendor/pygments-main/tests/test_latex_formatter.py +4 -2
- data/vendor/pygments-main/tests/test_lexers_other.py +11 -11
- data/vendor/pygments-main/tests/test_objectiveclexer.py +81 -0
- data/vendor/pygments-main/tests/test_perllexer.py +1 -1
- data/vendor/pygments-main/tests/test_qbasiclexer.py +43 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +8 -1
- data/vendor/pygments-main/tests/test_rtf_formatter.py +109 -0
- data/vendor/pygments-main/tests/test_string_asserts.py +39 -0
- data/vendor/pygments-main/tests/test_token.py +3 -3
- data/vendor/pygments-main/tests/test_using_api.py +1 -1
- data/vendor/pygments-main/tests/test_util.py +1 -1
- metadata +138 -51
- data/vendor/pygments-main/docs/generate.py +0 -472
- data/vendor/pygments-main/docs/src/api.txt +0 -270
- data/vendor/pygments-main/docs/src/authors.txt +0 -5
- data/vendor/pygments-main/docs/src/changelog.txt +0 -5
- data/vendor/pygments-main/docs/src/index.txt +0 -69
- data/vendor/pygments-main/docs/src/installation.txt +0 -71
- data/vendor/pygments-main/external/rst-directive-old.py +0 -77
- data/vendor/pygments-main/scripts/reindent.py +0 -291
- data/vendor/pygments-main/tests/examplefiles/import.hs +0 -4
- data/vendor/pygments-main/tests/examplefiles/objc_example2.m +0 -24
- data/vendor/pygments-main/tests/old_run.py +0 -138
|
File without changes
|
|
@@ -1,64 +1,81 @@
|
|
|
1
|
-
#!/bin/
|
|
1
|
+
#!/bin/bash
|
|
2
2
|
# Best effort auto-pygmentization with transparent decompression
|
|
3
3
|
# (c) Reuben Thomas 2012-2013
|
|
4
4
|
# This program is in the public domain.
|
|
5
5
|
|
|
6
6
|
# Strategy: first see if pygmentize can find a lexer; if not, ask file; if that finds nothing, fail
|
|
7
|
-
# Set the environment variable PYGMENTIZE_OPTS to configure pygments.
|
|
7
|
+
# Set the environment variable PYGMENTIZE_OPTS or pass options before the file path to configure pygments.
|
|
8
8
|
|
|
9
9
|
# This program can be used as a .lessfilter for the less pager to auto-color less's output
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
file_common_opts="--brief --dereference --uncompress"
|
|
11
|
+
file="${!#}" # last argument
|
|
12
|
+
options=${@:1:$(($#-1))} # handle others args as options to pass to pygmentize
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
14
|
+
file_common_opts="--brief --dereference"
|
|
15
|
+
|
|
16
|
+
lexer=$(pygmentize -N "$file")
|
|
17
|
+
if [[ "$lexer" == text ]]; then
|
|
18
|
+
unset lexer
|
|
19
|
+
case $(file --mime-type --uncompress $file_common_opts "$file") in
|
|
20
|
+
application/xml|image/svg+xml) lexer=xml;;
|
|
21
|
+
text/html) lexer=html;;
|
|
22
|
+
text/troff) lexer=nroff;;
|
|
23
|
+
text/x-asm) lexer=nasm;;
|
|
24
|
+
text/x-awk) lexer=awk;;
|
|
25
|
+
text/x-c) lexer=c;;
|
|
26
|
+
text/x-c++) lexer=cpp;;
|
|
27
|
+
text/x-diff) lexer=diff;;
|
|
28
|
+
text/x-fortran) lexer=fortran;;
|
|
29
|
+
text/x-gawk) lexer=gawk;;
|
|
30
|
+
text/x-java) lexer=java;;
|
|
31
|
+
text/x-lisp) lexer=common-lisp;;
|
|
32
|
+
text/x-lua) lexer=lua;;
|
|
33
|
+
text/x-makefile) lexer=make;;
|
|
34
|
+
text/x-msdos-batch) lexer=bat;;
|
|
35
|
+
text/x-nawk) lexer=nawk;;
|
|
36
|
+
text/x-pascal) lexer=pascal;;
|
|
37
|
+
text/x-perl) lexer=perl;;
|
|
38
|
+
text/x-php) lexer=php;;
|
|
39
|
+
text/x-po) lexer=po;;
|
|
40
|
+
text/x-python) lexer=python;;
|
|
41
|
+
text/x-ruby) lexer=ruby;;
|
|
42
|
+
text/x-shellscript) lexer=sh;;
|
|
43
|
+
text/x-tcl) lexer=tcl;;
|
|
44
|
+
text/x-tex|text/x-texinfo) lexer=latex;; # FIXME: texinfo really needs its own lexer
|
|
45
|
+
|
|
46
|
+
# Types that file outputs which pygmentize didn't support as of file 5.11, pygments 1.6rc1
|
|
47
|
+
# text/calendar
|
|
48
|
+
# text/PGP
|
|
49
|
+
# text/rtf
|
|
50
|
+
# text/texmacs
|
|
51
|
+
# text/x-bcpl
|
|
52
|
+
# text/x-info
|
|
53
|
+
# text/x-m4
|
|
54
|
+
# text/x-vcard
|
|
55
|
+
# text/x-xmcd
|
|
56
|
+
|
|
57
|
+
text/plain) # special filenames. TODO: insert more
|
|
58
|
+
case $(basename "$file") in
|
|
59
|
+
.zshrc) lexer=sh;;
|
|
60
|
+
esac
|
|
61
|
+
;;
|
|
62
|
+
esac
|
|
54
63
|
fi
|
|
55
64
|
|
|
56
|
-
encoding
|
|
65
|
+
encoding=$(file --mime-encoding --uncompress $file_common_opts "$file")
|
|
66
|
+
if [[ $encoding == "us-asciibinarybinary" ]]; then
|
|
67
|
+
encoding="us-ascii"
|
|
68
|
+
fi
|
|
57
69
|
|
|
58
|
-
if [ -n "$lexer" ]; then
|
|
70
|
+
if [[ -n "$lexer" ]]; then
|
|
71
|
+
concat=cat
|
|
72
|
+
case $(file $file_common_opts --mime-type "$file") in
|
|
73
|
+
application/x-gzip) concat=zcat;;
|
|
74
|
+
application/x-bzip2) concat=bzcat;;
|
|
75
|
+
application/x-xz) concat=xzcat;;
|
|
76
|
+
esac
|
|
59
77
|
# FIXME: Specify input encoding rather than output encoding https://bitbucket.org/birkenfeld/pygments-main/issue/800
|
|
60
|
-
|
|
61
|
-
exit 0
|
|
78
|
+
exec $concat "$file" | pygmentize -f terminal256 -O style=native,encoding=$encoding,outencoding=UTF-8 $PYGMENTIZE_OPTS $options -l $lexer
|
|
62
79
|
fi
|
|
63
80
|
|
|
64
81
|
exit 1
|
|
@@ -6,14 +6,9 @@
|
|
|
6
6
|
This fragment is a Markdown_ preprocessor that renders source code
|
|
7
7
|
to HTML via Pygments. To use it, invoke Markdown like so::
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
import markdown
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
md.textPreprocessors.insert(0, CodeBlockPreprocessor())
|
|
13
|
-
html = md.convert(someText)
|
|
14
|
-
|
|
15
|
-
markdown is then a callable that can be passed to the context of
|
|
16
|
-
a template and used in that template, for example.
|
|
11
|
+
html = markdown.markdown(someText, extensions=[CodeBlockExtension()])
|
|
17
12
|
|
|
18
13
|
This uses CSS classes by default, so use
|
|
19
14
|
``pygmentize -S <some style> -f html > pygments.css``
|
|
@@ -25,9 +20,9 @@
|
|
|
25
20
|
some code
|
|
26
21
|
[/sourcecode]
|
|
27
22
|
|
|
28
|
-
.. _Markdown:
|
|
23
|
+
.. _Markdown: https://pypi.python.org/pypi/Markdown
|
|
29
24
|
|
|
30
|
-
:copyright: Copyright 2006-
|
|
25
|
+
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
|
|
31
26
|
:license: BSD, see LICENSE for details.
|
|
32
27
|
"""
|
|
33
28
|
|
|
@@ -40,17 +35,17 @@ INLINESTYLES = False
|
|
|
40
35
|
|
|
41
36
|
import re
|
|
42
37
|
|
|
43
|
-
from markdown import
|
|
38
|
+
from markdown.preprocessors import Preprocessor
|
|
39
|
+
from markdown.extensions import Extension
|
|
44
40
|
|
|
45
41
|
from pygments import highlight
|
|
46
42
|
from pygments.formatters import HtmlFormatter
|
|
47
43
|
from pygments.lexers import get_lexer_by_name, TextLexer
|
|
48
44
|
|
|
49
45
|
|
|
50
|
-
class CodeBlockPreprocessor(
|
|
46
|
+
class CodeBlockPreprocessor(Preprocessor):
|
|
51
47
|
|
|
52
|
-
pattern = re.compile(
|
|
53
|
-
r'\[sourcecode:(.+?)\](.+?)\[/sourcecode\]', re.S)
|
|
48
|
+
pattern = re.compile(r'\[sourcecode:(.+?)\](.+?)\[/sourcecode\]', re.S)
|
|
54
49
|
|
|
55
50
|
formatter = HtmlFormatter(noclasses=INLINESTYLES)
|
|
56
51
|
|
|
@@ -63,5 +58,10 @@ class CodeBlockPreprocessor(TextPreprocessor):
|
|
|
63
58
|
code = highlight(m.group(2), lexer, self.formatter)
|
|
64
59
|
code = code.replace('\n\n', '\n \n').replace('\n', '<br />')
|
|
65
60
|
return '\n\n<div class="code">%s</div>\n\n' % code
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
joined_lines = "\n".join(lines)
|
|
62
|
+
joined_lines = self.pattern.sub(repl, joined_lines)
|
|
63
|
+
return joined_lines.split("\n")
|
|
64
|
+
|
|
65
|
+
class CodeBlockExtension(Extension):
|
|
66
|
+
def extendMarkdown(self, md, md_globals):
|
|
67
|
+
md.preprocessors.add('CodeBlockPreprocessor', CodeBlockPreprocessor(), '_begin')
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
If you do not want to do that and are willing to accept larger HTML
|
|
32
32
|
output, you can set the INLINESTYLES option below to True.
|
|
33
33
|
|
|
34
|
-
:copyright: Copyright 2006-
|
|
34
|
+
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
|
|
35
35
|
:license: BSD, see LICENSE for details.
|
|
36
36
|
"""
|
|
37
37
|
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
.. _directive documentation:
|
|
32
32
|
http://docutils.sourceforge.net/docs/howto/rst-directives.html
|
|
33
33
|
|
|
34
|
-
:copyright: Copyright 2006-
|
|
34
|
+
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
|
|
35
35
|
:license: BSD, see LICENSE for details.
|
|
36
36
|
"""
|
|
37
37
|
|
|
@@ -75,9 +75,8 @@ class Pygments(Directive):
|
|
|
75
75
|
# no lexer found - use the text one instead of an exception
|
|
76
76
|
lexer = TextLexer()
|
|
77
77
|
# take an arbitrary option if more than one is given
|
|
78
|
-
formatter = self.options and VARIANTS[self.options
|
|
78
|
+
formatter = self.options and VARIANTS[list(self.options)[0]] or DEFAULT
|
|
79
79
|
parsed = highlight(u'\n'.join(self.content), lexer, formatter)
|
|
80
80
|
return [nodes.raw('', parsed, format='html')]
|
|
81
81
|
|
|
82
82
|
directives.register_directive('sourcecode', Pygments)
|
|
83
|
-
|
|
@@ -13,264 +13,370 @@ the appropriate options to ``use_setuptools()``.
|
|
|
13
13
|
|
|
14
14
|
This file can also be run as a script to install or upgrade setuptools.
|
|
15
15
|
"""
|
|
16
|
+
import os
|
|
17
|
+
import shutil
|
|
16
18
|
import sys
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
19
|
+
import tempfile
|
|
20
|
+
import tarfile
|
|
21
|
+
import optparse
|
|
22
|
+
import subprocess
|
|
23
|
+
import platform
|
|
24
|
+
|
|
25
|
+
from distutils import log
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
from site import USER_SITE
|
|
29
|
+
except ImportError:
|
|
30
|
+
USER_SITE = None
|
|
31
|
+
|
|
32
|
+
DEFAULT_VERSION = "1.4.2"
|
|
33
|
+
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
|
|
34
|
+
|
|
35
|
+
def _python_cmd(*args):
|
|
36
|
+
args = (sys.executable,) + args
|
|
37
|
+
return subprocess.call(args) == 0
|
|
38
|
+
|
|
39
|
+
def _check_call_py24(cmd, *args, **kwargs):
|
|
40
|
+
res = subprocess.call(cmd, *args, **kwargs)
|
|
41
|
+
class CalledProcessError(Exception):
|
|
42
|
+
pass
|
|
43
|
+
if not res == 0:
|
|
44
|
+
msg = "Command '%s' return non-zero exit status %d" % (cmd, res)
|
|
45
|
+
raise CalledProcessError(msg)
|
|
46
|
+
vars(subprocess).setdefault('check_call', _check_call_py24)
|
|
47
|
+
|
|
48
|
+
def _install(tarball, install_args=()):
|
|
49
|
+
# extracting the tarball
|
|
50
|
+
tmpdir = tempfile.mkdtemp()
|
|
51
|
+
log.warn('Extracting in %s', tmpdir)
|
|
52
|
+
old_wd = os.getcwd()
|
|
53
|
+
try:
|
|
54
|
+
os.chdir(tmpdir)
|
|
55
|
+
tar = tarfile.open(tarball)
|
|
56
|
+
_extractall(tar)
|
|
57
|
+
tar.close()
|
|
58
|
+
|
|
59
|
+
# going in the directory
|
|
60
|
+
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
|
|
61
|
+
os.chdir(subdir)
|
|
62
|
+
log.warn('Now working in %s', subdir)
|
|
63
|
+
|
|
64
|
+
# installing
|
|
65
|
+
log.warn('Installing Setuptools')
|
|
66
|
+
if not _python_cmd('setup.py', 'install', *install_args):
|
|
67
|
+
log.warn('Something went wrong during the installation.')
|
|
68
|
+
log.warn('See the error message above.')
|
|
69
|
+
# exitcode will be 2
|
|
70
|
+
return 2
|
|
71
|
+
finally:
|
|
72
|
+
os.chdir(old_wd)
|
|
73
|
+
shutil.rmtree(tmpdir)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _build_egg(egg, tarball, to_dir):
|
|
77
|
+
# extracting the tarball
|
|
78
|
+
tmpdir = tempfile.mkdtemp()
|
|
79
|
+
log.warn('Extracting in %s', tmpdir)
|
|
80
|
+
old_wd = os.getcwd()
|
|
81
|
+
try:
|
|
82
|
+
os.chdir(tmpdir)
|
|
83
|
+
tar = tarfile.open(tarball)
|
|
84
|
+
_extractall(tar)
|
|
85
|
+
tar.close()
|
|
86
|
+
|
|
87
|
+
# going in the directory
|
|
88
|
+
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
|
|
89
|
+
os.chdir(subdir)
|
|
90
|
+
log.warn('Now working in %s', subdir)
|
|
91
|
+
|
|
92
|
+
# building an egg
|
|
93
|
+
log.warn('Building a Setuptools egg in %s', to_dir)
|
|
94
|
+
_python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
|
|
95
|
+
|
|
96
|
+
finally:
|
|
97
|
+
os.chdir(old_wd)
|
|
98
|
+
shutil.rmtree(tmpdir)
|
|
99
|
+
# returning the result
|
|
100
|
+
log.warn(egg)
|
|
101
|
+
if not os.path.exists(egg):
|
|
102
|
+
raise IOError('Could not build the egg.')
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _do_download(version, download_base, to_dir, download_delay):
|
|
106
|
+
egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'
|
|
107
|
+
% (version, sys.version_info[0], sys.version_info[1]))
|
|
108
|
+
if not os.path.exists(egg):
|
|
109
|
+
tarball = download_setuptools(version, download_base,
|
|
110
|
+
to_dir, download_delay)
|
|
111
|
+
_build_egg(egg, tarball, to_dir)
|
|
112
|
+
sys.path.insert(0, egg)
|
|
113
|
+
|
|
114
|
+
# Remove previously-imported pkg_resources if present (see
|
|
115
|
+
# https://bitbucket.org/pypa/setuptools/pull-request/7/ for details).
|
|
116
|
+
if 'pkg_resources' in sys.modules:
|
|
117
|
+
del sys.modules['pkg_resources']
|
|
118
|
+
|
|
119
|
+
import setuptools
|
|
120
|
+
setuptools.bootstrap_install_from = egg
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
|
|
124
|
+
to_dir=os.curdir, download_delay=15):
|
|
125
|
+
# making sure we use the absolute path
|
|
126
|
+
to_dir = os.path.abspath(to_dir)
|
|
127
|
+
was_imported = 'pkg_resources' in sys.modules or \
|
|
128
|
+
'setuptools' in sys.modules
|
|
92
129
|
try:
|
|
93
130
|
import pkg_resources
|
|
94
131
|
except ImportError:
|
|
95
|
-
return
|
|
132
|
+
return _do_download(version, download_base, to_dir, download_delay)
|
|
96
133
|
try:
|
|
97
|
-
pkg_resources.require("setuptools>="+version)
|
|
98
|
-
|
|
134
|
+
pkg_resources.require("setuptools>=" + version)
|
|
135
|
+
return
|
|
136
|
+
except pkg_resources.VersionConflict:
|
|
137
|
+
e = sys.exc_info()[1]
|
|
99
138
|
if was_imported:
|
|
100
|
-
|
|
101
|
-
"The required version of setuptools (>=%s) is not available
|
|
102
|
-
"can't be installed while this script is running. Please
|
|
103
|
-
" a more recent version first, using
|
|
104
|
-
"
|
|
105
|
-
) % (version, e.args[0])
|
|
139
|
+
sys.stderr.write(
|
|
140
|
+
"The required version of setuptools (>=%s) is not available,\n"
|
|
141
|
+
"and can't be installed while this script is running. Please\n"
|
|
142
|
+
"install a more recent version first, using\n"
|
|
143
|
+
"'easy_install -U setuptools'."
|
|
144
|
+
"\n\n(Currently using %r)\n" % (version, e.args[0]))
|
|
106
145
|
sys.exit(2)
|
|
107
146
|
else:
|
|
108
147
|
del pkg_resources, sys.modules['pkg_resources'] # reload ok
|
|
109
|
-
return
|
|
148
|
+
return _do_download(version, download_base, to_dir,
|
|
149
|
+
download_delay)
|
|
110
150
|
except pkg_resources.DistributionNotFound:
|
|
111
|
-
return
|
|
151
|
+
return _do_download(version, download_base, to_dir,
|
|
152
|
+
download_delay)
|
|
112
153
|
|
|
113
|
-
def
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"""
|
|
154
|
+
def _clean_check(cmd, target):
|
|
155
|
+
"""
|
|
156
|
+
Run the command to download target. If the command fails, clean up before
|
|
157
|
+
re-raising the error.
|
|
158
|
+
"""
|
|
159
|
+
try:
|
|
160
|
+
subprocess.check_call(cmd)
|
|
161
|
+
except subprocess.CalledProcessError:
|
|
162
|
+
if os.access(target, os.F_OK):
|
|
163
|
+
os.unlink(target)
|
|
164
|
+
raise
|
|
118
165
|
|
|
119
|
-
|
|
120
|
-
as an egg for download under the `download_base` URL (which should end
|
|
121
|
-
with a '/'). `to_dir` is the directory where the egg will be downloaded.
|
|
122
|
-
`delay` is the number of seconds to pause before an actual download attempt.
|
|
166
|
+
def download_file_powershell(url, target):
|
|
123
167
|
"""
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
168
|
+
Download the file at url to target using Powershell (which will validate
|
|
169
|
+
trust). Raise an exception if the command cannot complete.
|
|
170
|
+
"""
|
|
171
|
+
target = os.path.abspath(target)
|
|
172
|
+
cmd = [
|
|
173
|
+
'powershell',
|
|
174
|
+
'-Command',
|
|
175
|
+
"(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" % vars(),
|
|
176
|
+
]
|
|
177
|
+
_clean_check(cmd, target)
|
|
178
|
+
|
|
179
|
+
def has_powershell():
|
|
180
|
+
if platform.system() != 'Windows':
|
|
181
|
+
return False
|
|
182
|
+
cmd = ['powershell', '-Command', 'echo test']
|
|
183
|
+
devnull = open(os.path.devnull, 'wb')
|
|
184
|
+
try:
|
|
130
185
|
try:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
version, download_base, delay, url
|
|
148
|
-
); from time import sleep; sleep(delay)
|
|
149
|
-
log.warn("Downloading %s", url)
|
|
150
|
-
src = urllib2.urlopen(url)
|
|
151
|
-
# Read/write all in one block, so we don't create a corrupt file
|
|
152
|
-
# if the download is interrupted.
|
|
153
|
-
data = _validate_md5(egg_name, src.read())
|
|
154
|
-
dst = open(saveto,"wb"); dst.write(data)
|
|
155
|
-
finally:
|
|
156
|
-
if src: src.close()
|
|
157
|
-
if dst: dst.close()
|
|
158
|
-
return os.path.realpath(saveto)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
def main(argv, version=DEFAULT_VERSION):
|
|
196
|
-
"""Install or upgrade setuptools and EasyInstall"""
|
|
186
|
+
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
|
|
187
|
+
except:
|
|
188
|
+
return False
|
|
189
|
+
finally:
|
|
190
|
+
devnull.close()
|
|
191
|
+
return True
|
|
192
|
+
|
|
193
|
+
download_file_powershell.viable = has_powershell
|
|
194
|
+
|
|
195
|
+
def download_file_curl(url, target):
|
|
196
|
+
cmd = ['curl', url, '--silent', '--output', target]
|
|
197
|
+
_clean_check(cmd, target)
|
|
198
|
+
|
|
199
|
+
def has_curl():
|
|
200
|
+
cmd = ['curl', '--version']
|
|
201
|
+
devnull = open(os.path.devnull, 'wb')
|
|
197
202
|
try:
|
|
198
|
-
import setuptools
|
|
199
|
-
except ImportError:
|
|
200
|
-
egg = None
|
|
201
203
|
try:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
import pkg_resources
|
|
204
|
+
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
|
|
205
|
+
except:
|
|
206
|
+
return False
|
|
207
|
+
finally:
|
|
208
|
+
devnull.close()
|
|
209
|
+
return True
|
|
210
|
+
|
|
211
|
+
download_file_curl.viable = has_curl
|
|
212
|
+
|
|
213
|
+
def download_file_wget(url, target):
|
|
214
|
+
cmd = ['wget', url, '--quiet', '--output-document', target]
|
|
215
|
+
_clean_check(cmd, target)
|
|
216
|
+
|
|
217
|
+
def has_wget():
|
|
218
|
+
cmd = ['wget', '--version']
|
|
219
|
+
devnull = open(os.path.devnull, 'wb')
|
|
219
220
|
try:
|
|
220
|
-
pkg_resources.require(req)
|
|
221
|
-
except pkg_resources.VersionConflict:
|
|
222
221
|
try:
|
|
223
|
-
|
|
224
|
-
except
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if argv:
|
|
230
|
-
from setuptools.command.easy_install import main
|
|
231
|
-
main(argv)
|
|
232
|
-
else:
|
|
233
|
-
print "Setuptools version",version,"or greater has been installed."
|
|
234
|
-
print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
|
|
222
|
+
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
|
|
223
|
+
except:
|
|
224
|
+
return False
|
|
225
|
+
finally:
|
|
226
|
+
devnull.close()
|
|
227
|
+
return True
|
|
235
228
|
|
|
236
|
-
|
|
237
|
-
"""Update our built-in md5 registry"""
|
|
229
|
+
download_file_wget.viable = has_wget
|
|
238
230
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
231
|
+
def download_file_insecure(url, target):
|
|
232
|
+
"""
|
|
233
|
+
Use Python to download the file, even though it cannot authenticate the
|
|
234
|
+
connection.
|
|
235
|
+
"""
|
|
236
|
+
try:
|
|
237
|
+
from urllib.request import urlopen
|
|
238
|
+
except ImportError:
|
|
239
|
+
from urllib2 import urlopen
|
|
240
|
+
src = dst = None
|
|
241
|
+
try:
|
|
242
|
+
src = urlopen(url)
|
|
243
|
+
# Read/write all in one block, so we don't create a corrupt file
|
|
244
|
+
# if the download is interrupted.
|
|
245
|
+
data = src.read()
|
|
246
|
+
dst = open(target, "wb")
|
|
247
|
+
dst.write(data)
|
|
248
|
+
finally:
|
|
249
|
+
if src:
|
|
250
|
+
src.close()
|
|
251
|
+
if dst:
|
|
252
|
+
dst.close()
|
|
253
|
+
|
|
254
|
+
download_file_insecure.viable = lambda: True
|
|
255
|
+
|
|
256
|
+
def get_best_downloader():
|
|
257
|
+
downloaders = [
|
|
258
|
+
download_file_powershell,
|
|
259
|
+
download_file_curl,
|
|
260
|
+
download_file_wget,
|
|
261
|
+
download_file_insecure,
|
|
262
|
+
]
|
|
263
|
+
|
|
264
|
+
for dl in downloaders:
|
|
265
|
+
if dl.viable():
|
|
266
|
+
return dl
|
|
267
|
+
|
|
268
|
+
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
|
|
269
|
+
to_dir=os.curdir, delay=15,
|
|
270
|
+
downloader_factory=get_best_downloader):
|
|
271
|
+
"""Download setuptools from a specified location and return its filename
|
|
254
272
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
273
|
+
`version` should be a valid setuptools version number that is available
|
|
274
|
+
as an egg for download under the `download_base` URL (which should end
|
|
275
|
+
with a '/'). `to_dir` is the directory where the egg will be downloaded.
|
|
276
|
+
`delay` is the number of seconds to pause before an actual download
|
|
277
|
+
attempt.
|
|
259
278
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
279
|
+
``downloader_factory`` should be a function taking no arguments and
|
|
280
|
+
returning a function for downloading a URL to a target.
|
|
281
|
+
"""
|
|
282
|
+
# making sure we use the absolute path
|
|
283
|
+
to_dir = os.path.abspath(to_dir)
|
|
284
|
+
tgz_name = "setuptools-%s.tar.gz" % version
|
|
285
|
+
url = download_base + tgz_name
|
|
286
|
+
saveto = os.path.join(to_dir, tgz_name)
|
|
287
|
+
if not os.path.exists(saveto): # Avoid repeated downloads
|
|
288
|
+
log.warn("Downloading %s", url)
|
|
289
|
+
downloader = downloader_factory()
|
|
290
|
+
downloader(url, saveto)
|
|
291
|
+
return os.path.realpath(saveto)
|
|
264
292
|
|
|
265
293
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
294
|
+
def _extractall(self, path=".", members=None):
|
|
295
|
+
"""Extract all members from the archive to the current working
|
|
296
|
+
directory and set owner, modification time and permissions on
|
|
297
|
+
directories afterwards. `path' specifies a different directory
|
|
298
|
+
to extract to. `members' is optional and must be a subset of the
|
|
299
|
+
list returned by getmembers().
|
|
300
|
+
"""
|
|
301
|
+
import copy
|
|
302
|
+
import operator
|
|
303
|
+
from tarfile import ExtractError
|
|
304
|
+
directories = []
|
|
305
|
+
|
|
306
|
+
if members is None:
|
|
307
|
+
members = self
|
|
308
|
+
|
|
309
|
+
for tarinfo in members:
|
|
310
|
+
if tarinfo.isdir():
|
|
311
|
+
# Extract directories with a safe mode.
|
|
312
|
+
directories.append(tarinfo)
|
|
313
|
+
tarinfo = copy.copy(tarinfo)
|
|
314
|
+
tarinfo.mode = 448 # decimal for oct 0700
|
|
315
|
+
self.extract(tarinfo, path)
|
|
316
|
+
|
|
317
|
+
# Reverse sort directories.
|
|
318
|
+
if sys.version_info < (2, 4):
|
|
319
|
+
def sorter(dir1, dir2):
|
|
320
|
+
return cmp(dir1.name, dir2.name)
|
|
321
|
+
directories.sort(sorter)
|
|
322
|
+
directories.reverse()
|
|
269
323
|
else:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
324
|
+
directories.sort(key=operator.attrgetter('name'), reverse=True)
|
|
275
325
|
|
|
326
|
+
# Set correct owner, mtime and filemode on directories.
|
|
327
|
+
for tarinfo in directories:
|
|
328
|
+
dirpath = os.path.join(path, tarinfo.name)
|
|
329
|
+
try:
|
|
330
|
+
self.chown(tarinfo, dirpath)
|
|
331
|
+
self.utime(tarinfo, dirpath)
|
|
332
|
+
self.chmod(tarinfo, dirpath)
|
|
333
|
+
except ExtractError:
|
|
334
|
+
e = sys.exc_info()[1]
|
|
335
|
+
if self.errorlevel > 1:
|
|
336
|
+
raise
|
|
337
|
+
else:
|
|
338
|
+
self._dbg(1, "tarfile: %s" % e)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _build_install_args(options):
|
|
342
|
+
"""
|
|
343
|
+
Build the arguments to 'python setup.py install' on the setuptools package
|
|
344
|
+
"""
|
|
345
|
+
install_args = []
|
|
346
|
+
if options.user_install:
|
|
347
|
+
if sys.version_info < (2, 6):
|
|
348
|
+
log.warn("--user requires Python 2.6 or later")
|
|
349
|
+
raise SystemExit(1)
|
|
350
|
+
install_args.append('--user')
|
|
351
|
+
return install_args
|
|
352
|
+
|
|
353
|
+
def _parse_args():
|
|
354
|
+
"""
|
|
355
|
+
Parse the command line for options
|
|
356
|
+
"""
|
|
357
|
+
parser = optparse.OptionParser()
|
|
358
|
+
parser.add_option(
|
|
359
|
+
'--user', dest='user_install', action='store_true', default=False,
|
|
360
|
+
help='install in user site package (requires Python 2.6 or later)')
|
|
361
|
+
parser.add_option(
|
|
362
|
+
'--download-base', dest='download_base', metavar="URL",
|
|
363
|
+
default=DEFAULT_URL,
|
|
364
|
+
help='alternative URL from where to download the setuptools package')
|
|
365
|
+
parser.add_option(
|
|
366
|
+
'--insecure', dest='downloader_factory', action='store_const',
|
|
367
|
+
const=lambda: download_file_insecure, default=get_best_downloader,
|
|
368
|
+
help='Use internal, non-validating downloader'
|
|
369
|
+
)
|
|
370
|
+
options, args = parser.parse_args()
|
|
371
|
+
# positional arguments are ignored
|
|
372
|
+
return options
|
|
373
|
+
|
|
374
|
+
def main(version=DEFAULT_VERSION):
|
|
375
|
+
"""Install or upgrade setuptools and EasyInstall"""
|
|
376
|
+
options = _parse_args()
|
|
377
|
+
tarball = download_setuptools(download_base=options.download_base,
|
|
378
|
+
downloader_factory=options.downloader_factory)
|
|
379
|
+
return _install(tarball, _build_install_args(options))
|
|
276
380
|
|
|
381
|
+
if __name__ == '__main__':
|
|
382
|
+
sys.exit(main())
|