From 8e65c17c50f223b6e701ddebcb84f2da1718cfcb Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Sat, 4 May 2019 17:49:58 +0200 Subject: [PATCH] Added py-pygments with patches This adds the py-pygments package from alpine with two patches from the bitbucket repository. --- sr.ht/py-pygments/APKBUILD | 90 +++++++++ .../pr-779-python3-in-analyze_text.patch | 19 ++ sr.ht/py-pygments/pr-815-support-dmesg.patch | 172 ++++++++++++++++++ 3 files changed, 281 insertions(+) create mode 100644 sr.ht/py-pygments/APKBUILD create mode 100644 sr.ht/py-pygments/pr-779-python3-in-analyze_text.patch create mode 100644 sr.ht/py-pygments/pr-815-support-dmesg.patch diff --git a/sr.ht/py-pygments/APKBUILD b/sr.ht/py-pygments/APKBUILD new file mode 100644 index 0000000..9987ca4 --- /dev/null +++ b/sr.ht/py-pygments/APKBUILD @@ -0,0 +1,90 @@ +# Contributor: Peter Bui +# Maintainer: Matt Smith +pkgname=py-pygments +_pkgname=Pygments +pkgver=2.2.0 +pkgrel=2 +pkgdesc="A syntax highlighting package written in Python." +url="http://pygments.org/" +arch="noarch" +license="BSD" +depends="py3-${pkgname#py-}" +makedepends="python2-dev python3-dev py-setuptools" +subpackages="py2-${pkgname#py-}:_py2 py3-${pkgname#py-}:_py3 $pkgname-doc::noarch" +source=" + https://files.pythonhosted.org/packages/source/${_pkgname:0:1}/$_pkgname/$_pkgname-$pkgver.tar.gz + pr-779-python3-in-analyze_text.patch + pr-815-support-dmesg.patch +" +builddir="$srcdir/$_pkgname-$pkgver" + +prepare() { + default_prepare || return 1 + + # Soure files are modified during build with 2to3 tool, so we must build + # it separately for each Python version. + local python; for python in python2 python3; do + cp -r "$builddir" "$builddir-$python" || return 1 + done +} + +build() { + local python; for python in python2 python3; do + cd "$builddir"-$python + $python setup.py build || return 1 + done +} + +package() { + mkdir -p "$pkgdir" + + mkdir -p "$pkgdir"/usr/bin + ln -s pygmentize-3 "$pkgdir"/usr/bin/pygmentize +} + +_py2() { + replaces="$pkgname" + _py python2 +} + +_py3() { + _py python3 +} + +_py() { + local python="$1" + local pyver="${1:6:1}" + pkgdesc="$pkgdesc (for $python)" + depends="$python" + install_if="$pkgname=$pkgver-r$pkgrel $python" + + cd "$builddir"-$python + $python setup.py install --prefix=/usr --root="$subpkgdir" || return 1 + + local path; for path in "$subpkgdir"/usr/bin/*; do + mv "$path" "$path-$pyver" || return 1 + done +} + +doc() { + local destdir="$subpkgdir/usr/share/doc/$pkgname" + + cd "$builddir" + + install -m 644 -D doc/pygmentize.1 \ + "$subpkgdir"/usr/share/man/man1/pygmentize.1 || return 1 + + mkdir -p "$destdir" || return 1 + cp AUTHORS CHANGES LICENSE TODO "$destdir"/ || return 1 + + # Note: The documentation in the doc directory needs to be generated + # by py-sphinx + cp -R ./doc/docs/* "$destdir"/ || return 1 + + default_doc +} + +sha512sums="cc0a4f73e19fa6cbf46314de2e809460c807c631e39ba05cbe5edb5f40db1a687aafcd9715585a0ed45f791710eb6038305e273f282f8682df76f30e63710b29 Pygments-2.2.0.tar.gz +72292d486cd905e68a9f6ee7a717da490a3c187b220b1a24a9ea14f49f588abe9909ff64fab5cc4d58a9756637e033b4a58a53faabeb18b20a08cf4e553dc81d pr-779-python3-in-analyze_text.patch +295068965bce2ed6e97ce69b984dd1dcd070d9bc09a4bc12f77ca45c6d327c31ec5ebeb573a38ad26a5f977f633b30ae2c23379403a7d7c17e46863e6f1c7311 pr-815-support-dmesg.patch" + diff --git a/sr.ht/py-pygments/pr-779-python3-in-analyze_text.patch b/sr.ht/py-pygments/pr-779-python3-in-analyze_text.patch new file mode 100644 index 0000000..f066374 --- /dev/null +++ b/sr.ht/py-pygments/pr-779-python3-in-analyze_text.patch @@ -0,0 +1,19 @@ +# HG changeset patch +# User Drew DeVault +# Date 1537640646 14400 +# Node ID 6ce1e62557062395358f1934e38bb62078aa13a5 +# Parent 7941677dc77d4f2bf0bbd6140ade85a9454b8b80 +Support /usr/bin/env python3 in analyze_text + +diff --git a/pygments/lexers/python.py b/pygments/lexers/python.py +--- a/pygments/lexers/python.py ++++ b/pygments/lexers/python.py +@@ -238,7 +238,7 @@ + } + + def analyse_text(text): +- return shebang_matches(text, r'pythonw?(2(\.\d)?)?') or \ ++ return shebang_matches(text, r'pythonw?(2|3(\.\d)?)?') or \ + 'import ' in text[:1000] + + diff --git a/sr.ht/py-pygments/pr-815-support-dmesg.patch b/sr.ht/py-pygments/pr-815-support-dmesg.patch new file mode 100644 index 0000000..f19ed1a --- /dev/null +++ b/sr.ht/py-pygments/pr-815-support-dmesg.patch @@ -0,0 +1,172 @@ +# HG changeset patch +# User martijn@msi.localhost +# Date 1556805935 -7200 +# Branch lexer-dmesg +# Node ID 7452fc8eec5e070203326abaeeb1e5de6fa59608 +# Parent 6d6b6fc3d439fa1019d9412ef8438dc03c449644 +This commit adds a lexer for linux kernel logs as outputted by `dmesg` + +It supports output from `dmesg`, in that case it highlights based on +keywords in the line + +It can also highlight `dmesg -x` output. In that case it uses the +loglevels from the kernel to highlight the lines. + +diff --git a/AUTHORS b/AUTHORS +--- a/AUTHORS ++++ b/AUTHORS +@@ -35,6 +35,7 @@ + * Stéphane Blondon -- SGF lexer + * Frits van Bommel -- assembler lexers + * Pierre Bourdon -- bugfixes ++* Martijn Braam -- Kernel log lexer + * Matthias Bussonnier -- ANSI style handling for terminal-256 formatter + * chebee7i -- Python traceback lexer improvements + * Hiram Chirino -- Scaml and Jade lexers +diff --git a/doc/languages.rst b/doc/languages.rst +--- a/doc/languages.rst ++++ b/doc/languages.rst +@@ -120,6 +120,11 @@ + * `Smarty `_ templates (PHP templating) + * Tea + ++Log files ++--------- ++ ++* Linux kernel log (dmesg) ++ + Other markup + ------------ + +diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py +--- a/pygments/lexers/_mapping.py ++++ b/pygments/lexers/_mapping.py +@@ -233,6 +233,7 @@ + 'JuttleLexer': ('pygments.lexers.javascript', 'Juttle', ('juttle', 'juttle'), ('*.juttle',), ('application/juttle', 'application/x-juttle', 'text/x-juttle', 'text/juttle')), + 'KalLexer': ('pygments.lexers.javascript', 'Kal', ('kal',), ('*.kal',), ('text/kal', 'application/kal')), + 'KconfigLexer': ('pygments.lexers.configs', 'Kconfig', ('kconfig', 'menuconfig', 'linux-config', 'kernel-config'), ('Kconfig', '*Config.in*', 'external.in*', 'standard-modules.in'), ('text/x-kconfig',)), ++ 'KernelLogLexer': ('pygments.lexers.log', 'Kernel log', ('kmsg', 'dmesg'), ('*.kmsg', '*.dmesg'), ()), + 'KokaLexer': ('pygments.lexers.haskell', 'Koka', ('koka',), ('*.kk', '*.kki'), ('text/x-koka',)), + 'KotlinLexer': ('pygments.lexers.jvm', 'Kotlin', ('kotlin',), ('*.kt',), ('text/x-kotlin',)), + 'LSLLexer': ('pygments.lexers.scripting', 'LSL', ('lsl',), ('*.lsl',), ('text/x-lsl',)), +diff --git a/pygments/lexers/log.py b/pygments/lexers/log.py +new file mode 100644 +--- /dev/null ++++ b/pygments/lexers/log.py +@@ -0,0 +1,59 @@ ++# -*- coding: utf-8 -*- ++""" ++ pygments.lexers.log ++ ~~~~~~~~~~~~~~~~~~~~~ ++ ++ Lexers for various log file formats. ++ ++ :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. ++ :license: BSD, see LICENSE for details. ++""" ++ ++from pygments.lexer import RegexLexer, include ++from pygments.token import * ++ ++__all__ = ['KernelLogLexer'] ++ ++ ++class KernelLogLexer(RegexLexer): ++ name = 'Kernel log' ++ aliases = ['kmsg', 'dmesg'] ++ filenames = ['*.kmsg', '*.dmesg'] ++ ++ tokens = { ++ 'root': [ ++ (r'^(?=\[)', Text, 'unknown'), ++ (r'^([^:]+):debug\s*: (?=\[)', Text, 'debug'), ++ (r'^([^:]+):info\s*: (?=\[)', Text, 'info'), ++ (r'^([^:]+):warn\s*: (?=\[)', Text, 'warn'), ++ (r'^([^:]+):notice\s*: (?=\[)', Text, 'warn'), ++ (r'^([^:]+):err\s*: (?=\[)', Text, 'error'), ++ (r'^([^:]+):crit\s*: (?=\[)', Text, 'error'), ++ ], ++ 'unknown': [ ++ (r'^(?=.+(warning|notice|audit|deprecated))', Text, 'warn'), ++ (r'^(?=.+(error|critical|fail|Bug))', Text, 'error'), ++ (r'', Text, 'info'), ++ ], ++ 'base': [ ++ (r'\[[0-9\. ]+\] ', Number), ++ (r'(?<=\] ).+?:', Keyword), ++ (r'\n', Text, '#pop'), ++ ], ++ 'debug': [ ++ include('base'), ++ (r'.+\n', Text, '#pop') ++ ], ++ 'info': [ ++ include('base'), ++ (r'.+\n', Text, '#pop') ++ ], ++ 'warn': [ ++ include('base'), ++ (r'.+', Comment, '#pop') ++ ], ++ 'error': [ ++ include('base'), ++ (r'.+\n', Generic.Error, '#pop') ++ ] ++ } +diff --git a/tests/examplefiles/example.dmesg b/tests/examplefiles/example.dmesg +new file mode 100644 +--- /dev/null ++++ b/tests/examplefiles/example.dmesg +@@ -0,0 +1,52 @@ ++[ 0.000000] Linux version 5.0.9-arch1-1-ARCH (builduser@heftig-18307) (gcc version 8.3.0 (GCC)) #1 SMP PREEMPT Sat Apr 20 15:00:46 UTC 2019 ++[ 0.000000] Command line: initrd=\initramfs-linux.img root=/dev/nvme0n1p1 nouveau.noaccel=1 rw ++[ 0.000000] KERNEL supported cpus: ++[ 0.000000] Intel GenuineIntel ++[ 0.000000] AMD AuthenticAMD ++[ 0.000000] Hygon HygonGenuine ++[ 0.000000] Centaur CentaurHauls ++[ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers' ++[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers' ++[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers' ++[ 0.000000] x86/fpu: Supporting XSAVE feature 0x008: 'MPX bounds registers' ++[ 0.000000] x86/fpu: Supporting XSAVE feature 0x010: 'MPX CSR' ++[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256 ++[ 0.000000] x86/fpu: xstate_offset[3]: 832, xstate_sizes[3]: 64 ++[ 0.000000] x86/fpu: xstate_offset[4]: 896, xstate_sizes[4]: 64 ++[ 0.000000] x86/fpu: Enabled xstate features 0x1f, context size is 960 bytes, using 'compacted' format. ++[ 2.663456] tpm_crb MSFT0101:00: [Firmware Bug]: ACPI region does not cover the entire command/response buffer. [mem 0xfed40000-0xfed4087f flags 0x200] vs fed40080 f80 ++[ 2.663514] tpm_crb MSFT0101:00: [Firmware Bug]: ACPI region does not cover the entire command/response buffer. [mem 0xfed40000-0xfed4087f flags 0x200] vs fed40080 f80 ++[ 2.664809] Bluetooth: Core ver 2.22 ++[ 2.664820] NET: Registered protocol family 31 ++[ 3134.452501] usb 2-2: new SuperSpeed Gen 1 USB device number 2 using xhci_hcd ++[ 3134.471506] usb 2-2: New USB device found, idVendor=0781, idProduct=cfd2, bcdDevice= 0.02 ++[ 3134.471508] usb 2-2: New USB device strings: Mfr=3, Product=4, SerialNumber=2 ++ ++kern :notice: [ 0.000000] Linux version 5.0.9-arch1-1-ARCH (builduser@heftig-18307) (gcc version 8.3.0 (GCC)) #1 SMP PREEMPT Sat Apr 20 15:00:46 UTC 2019 ++kern :info : [ 0.000000] Command line: initrd=\initramfs-linux.img root=/dev/nvme0n1p1 nouveau.noaccel=1 rw ++kern :info : [ 0.000000] KERNEL supported cpus: ++kern :info : [ 0.000000] Intel GenuineIntel ++kern :info : [ 0.000000] AMD AuthenticAMD ++kern :info : [ 0.000000] Hygon HygonGenuine ++kern :info : [ 0.000000] Centaur CentaurHauls ++kern :info : [ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers' ++kern :info : [ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers' ++kern :info : [ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers' ++kern :info : [ 0.000000] x86/fpu: Supporting XSAVE feature 0x008: 'MPX bounds registers' ++kern :info : [ 0.000000] x86/fpu: Supporting XSAVE feature 0x010: 'MPX CSR' ++kern :info : [ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256 ++kern :info : [ 0.000000] x86/fpu: xstate_offset[3]: 832, xstate_sizes[3]: 64 ++kern :info : [ 0.000000] x86/fpu: xstate_offset[4]: 896, xstate_sizes[4]: 64 ++kern :info : [ 0.000000] x86/fpu: Enabled xstate features 0x1f, context size is 960 bytes, using 'compacted' format. ++kern :info : [ 0.000000] BIOS-provided physical RAM map: ++kern :info : [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000057fff] usable ++kern :info : [ 2.382262] EXT4-fs (nvme0n1p1): re-mounted. Opts: (null) ++kern :notice: [ 2.389774] random: systemd-random-: uninitialized urandom read (512 bytes read) ++kern :info : [ 2.397148] usb 1-10: New USB device found, idVendor=8087, idProduct=0aa7, bcdDevice= 0.01 ++kern :info : [ 2.397150] usb 1-10: New USB device strings: Mfr=0, Product=0, SerialNumber=0 ++kern :info : [ 2.519599] usb 1-12: new high-speed USB device number 4 using xhci_hcd ++kern :crit : [18706.135478] mce: CPU6: Package temperature above threshold, cpu clock throttled (total events = 79) ++kern :crit : [18706.135479] mce: CPU3: Package temperature above threshold, cpu clock throttled (total events = 79) ++kern :crit : [18706.135484] mce: CPU4: Package temperature above threshold, cpu clock throttled (total events = 79) ++kern :info : [18706.136450] mce: CPU4: Core temperature/speed normal ++kern :info : [18706.136451] mce: CPU1: Package temperature/speed normal -- 2.45.2