python-pygments: new package (2.19.2)
authorAlexandru Ardelean <redacted>
Mon, 23 Mar 2026 11:59:20 +0000 (11:59 +0000)
committerAlexandru Ardelean <redacted>
Sun, 29 Mar 2026 05:31:47 +0000 (08:31 +0300)
Pygments is a generic syntax highlighting library that supports over
500 languages and text formats. It is used by a wide range of tools
for terminal, HTML, and LaTeX output.

Added as a required dependency for python-pytest >= 7.x, which uses
Pygments to syntax-highlight code snippets in failure reports and
tracebacks.

The package uses hatchling as its build backend and has no runtime
dependencies beyond the Python standard library.

Co-Authored-By: Claude Sonnet 4.6 <redacted>
Signed-off-by: Alexandru Ardelean <redacted>
lang/python/python-pygments/Makefile [new file with mode: 0644]
lang/python/python-pygments/test.sh [new file with mode: 0755]

diff --git a/lang/python/python-pygments/Makefile b/lang/python/python-pygments/Makefile
new file mode 100644 (file)
index 0000000..5154776
--- /dev/null
@@ -0,0 +1,40 @@
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=python-pygments
+PKG_VERSION:=2.19.2
+PKG_RELEASE:=1
+
+PYPI_NAME:=pygments
+PKG_HASH:=636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887
+
+PKG_LICENSE:=BSD-2-Clause
+PKG_LICENSE_FILES:=LICENSE
+PKG_CPE_ID:=cpe:/a:pygments:pygments
+
+PKG_BUILD_DEPENDS:=python-hatchling/host
+
+include ../pypi.mk
+include $(INCLUDE_DIR)/package.mk
+include ../python3-package.mk
+
+define Package/python3-pygments
+  SECTION:=lang
+  CATEGORY:=Languages
+  SUBMENU:=Python
+  TITLE:=Pygments syntax highlighter
+  URL:=https://pygments.org/
+  DEPENDS:=+python3-light +python3-email
+endef
+
+define Package/python3-pygments/description
+  Pygments is a syntax highlighting library written in Python.
+  It supports over 500 languages and text formats.
+endef
+
+$(eval $(call Py3Package,python3-pygments))
+$(eval $(call BuildPackage,python3-pygments))
+$(eval $(call BuildPackage,python3-pygments-src))
diff --git a/lang/python/python-pygments/test.sh b/lang/python/python-pygments/test.sh
new file mode 100755 (executable)
index 0000000..45aedb6
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+[ "$1" = "python3-pygments" ] || exit 0
+
+python3 - << EOF
+import sys
+import pygments
+from pygments import highlight
+from pygments.lexers import PythonLexer, get_lexer_by_name
+from pygments.formatters import HtmlFormatter, NullFormatter
+
+if pygments.__version__ != "$2":
+    print("Wrong version: " + pygments.__version__)
+    sys.exit(1)
+
+code = "def hello(name):\n    print('Hello, ' + name)\n"
+
+# Test basic highlighting to HTML
+formatter = HtmlFormatter()
+result = highlight(code, PythonLexer(), formatter)
+assert '<span' in result, "Expected HTML span tags in output"
+assert 'hello' in result, "Expected function name in output"
+
+# Test getting lexer by name
+lexer = get_lexer_by_name("python")
+assert lexer is not None, "Expected to get Python lexer by name"
+
+# Test highlighting to plain text (NullFormatter strips markup)
+plain = highlight(code, PythonLexer(), NullFormatter())
+assert 'hello' in plain, "Expected function name in plain output"
+
+# Test CSS generation
+css = formatter.get_style_defs('.highlight')
+assert '.highlight' in css, "Expected CSS class in style defs"
+
+sys.exit(0)
+EOF
git clone https://git.99rst.org/PROJECT