codekingpro/portable-devtools
115k
1"""2 pygments.plugin3 ~~~~~~~~~~~~~~~4 5 Pygments plugin interface.6 7 lexer plugins::8 9 [pygments.lexers]10 yourlexer = yourmodule:YourLexer11 12 formatter plugins::13 14 [pygments.formatters]15 yourformatter = yourformatter:YourFormatter16 /.ext = yourformatter:YourFormatter17 18 As you can see, you can define extensions for the formatter19 with a leading slash.20 21 syntax plugins::22 23 [pygments.styles]24 yourstyle = yourstyle:YourStyle25 26 filter plugin::27 28 [pygments.filter]29 yourfilter = yourfilter:YourFilter30 31 32 :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.33 :license: BSD, see LICENSE for details.34"""35import functools36from importlib.metadata import entry_points37 38LEXER_ENTRY_POINT = 'pygments.lexers'39FORMATTER_ENTRY_POINT = 'pygments.formatters'40STYLE_ENTRY_POINT = 'pygments.styles'41FILTER_ENTRY_POINT = 'pygments.filters'42 43 44@functools.cache45def iter_entry_points(group_name):46 groups = entry_points()47 if hasattr(groups, 'select'):48 # New interface in Python 3.10 and newer versions of the49 # importlib_metadata backport.50 return groups.select(group=group_name)51 else:52 # Older interface, deprecated in Python 3.10 and recent53 # importlib_metadata, but we need it in Python 3.8 and 3.9.54 return groups.get(group_name, [])55 56 57def find_plugin_lexers():58 for entrypoint in iter_entry_points(LEXER_ENTRY_POINT):59 yield entrypoint.load()60 61 62def find_plugin_formatters():63 for entrypoint in iter_entry_points(FORMATTER_ENTRY_POINT):64 yield entrypoint.name, entrypoint.load()65 66 67def find_plugin_styles():68 for entrypoint in iter_entry_points(STYLE_ENTRY_POINT):69 yield entrypoint.name, entrypoint.load()70 71 72def find_plugin_filters():73 for entrypoint in iter_entry_points(FILTER_ENTRY_POINT):74 yield entrypoint.name, entrypoint.load()75 