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-2024 by the Pygments team, see AUTHORS.33 :license: BSD, see LICENSE for details.34"""35from importlib.metadata import entry_points36 37LEXER_ENTRY_POINT = 'pygments.lexers'38FORMATTER_ENTRY_POINT = 'pygments.formatters'39STYLE_ENTRY_POINT = 'pygments.styles'40FILTER_ENTRY_POINT = 'pygments.filters'41 42 43def iter_entry_points(group_name):44 groups = entry_points()45 if hasattr(groups, 'select'):46 # New interface in Python 3.10 and newer versions of the47 # importlib_metadata backport.48 return groups.select(group=group_name)49 else:50 # Older interface, deprecated in Python 3.10 and recent51 # importlib_metadata, but we need it in Python 3.8 and 3.9.52 return groups.get(group_name, [])53 54 55def find_plugin_lexers():56 for entrypoint in iter_entry_points(LEXER_ENTRY_POINT):57 yield entrypoint.load()58 59 60def find_plugin_formatters():61 for entrypoint in iter_entry_points(FORMATTER_ENTRY_POINT):62 yield entrypoint.name, entrypoint.load()63 64 65def find_plugin_styles():66 for entrypoint in iter_entry_points(STYLE_ENTRY_POINT):67 yield entrypoint.name, entrypoint.load()68 69 70def find_plugin_filters():71 for entrypoint in iter_entry_points(FILTER_ENTRY_POINT):72 yield entrypoint.name, entrypoint.load()73 