]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_vendor/pygments/plugin.py
5 Pygments plugin interface. By default, this tries to use
6 ``importlib.metadata``, which is in the Python standard
7 library since Python 3.8, or its ``importlib_metadata``
8 backport for earlier versions of Python. It falls back on
9 ``pkg_resources`` if not found. Finally, if ``pkg_resources``
10 is not found either, no plugins are loaded at all.
15 yourlexer = yourmodule:YourLexer
20 yourformatter = yourformatter:YourFormatter
21 /.ext = yourformatter:YourFormatter
23 As you can see, you can define extensions for the formatter
29 yourstyle = yourstyle:YourStyle
34 yourfilter = yourfilter:YourFilter
37 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
38 :license: BSD, see LICENSE for details.
41 LEXER_ENTRY_POINT
= 'pygments.lexers'
42 FORMATTER_ENTRY_POINT
= 'pygments.formatters'
43 STYLE_ENTRY_POINT
= 'pygments.styles'
44 FILTER_ENTRY_POINT
= 'pygments.filters'
47 def iter_entry_points(group_name
):
49 from importlib
.metadata
import entry_points
52 from importlib_metadata
import entry_points
55 from pip
._vendor
.pkg_resources
import iter_entry_points
56 except (ImportError, OSError):
59 return iter_entry_points(group_name
)
60 groups
= entry_points()
61 if hasattr(groups
, 'select'):
62 # New interface in Python 3.10 and newer versions of the
63 # importlib_metadata backport.
64 return groups
.select(group
=group_name
)
66 # Older interface, deprecated in Python 3.10 and recent
67 # importlib_metadata, but we need it in Python 3.8 and 3.9.
68 return groups
.get(group_name
, [])
71 def find_plugin_lexers():
72 for entrypoint
in iter_entry_points(LEXER_ENTRY_POINT
):
73 yield entrypoint
.load()
76 def find_plugin_formatters():
77 for entrypoint
in iter_entry_points(FORMATTER_ENTRY_POINT
):
78 yield entrypoint
.name
, entrypoint
.load()
81 def find_plugin_styles():
82 for entrypoint
in iter_entry_points(STYLE_ENTRY_POINT
):
83 yield entrypoint
.name
, entrypoint
.load()
86 def find_plugin_filters():
87 for entrypoint
in iter_entry_points(FILTER_ENTRY_POINT
):
88 yield entrypoint
.name
, entrypoint
.load()