diff options
author | Jean Abou Samra <jean@abou-samra.fr> | 2023-03-30 22:41:29 +0200 |
---|---|---|
committer | Jean Abou Samra <jean@abou-samra.fr> | 2023-03-30 22:41:29 +0200 |
commit | 3bb96da3151db1f00501e555c8b52fbac45dcdf6 (patch) | |
tree | 797bb503ccea06a2c3d088284a0767a3e344ad03 | |
parent | a208ea553b17dc50fc2e3498244c74a75909888b (diff) | |
download | pygments-git-3bb96da3151db1f00501e555c8b52fbac45dcdf6.tar.gz |
Use autodoc for pygments.styles
-rw-r--r-- | doc/docs/api.rst | 47 | ||||
-rw-r--r-- | pygments/formatters/__init__.py | 35 | ||||
-rw-r--r-- | pygments/styles/__init__.py | 10 |
3 files changed, 33 insertions, 59 deletions
diff --git a/doc/docs/api.rst b/doc/docs/api.rst index bf11b46c..945ba012 100644 --- a/doc/docs/api.rst +++ b/doc/docs/api.rst @@ -11,9 +11,7 @@ High-level API Functions from the :mod:`pygments` module: .. autofunction:: lex - .. autofunction:: format - .. autofunction:: highlight @@ -36,51 +34,16 @@ Functions from :mod:`pygments.lexers`: Functions from :mod:`pygments.formatters`: -.. function:: get_formatter_by_name(alias, **options) - - Return an instance of a :class:`.Formatter` subclass that has `alias` in its - aliases list. The formatter is given the `options` at its instantiation. - - Will raise :exc:`pygments.util.ClassNotFound` if no formatter with that - alias is found. - -.. function:: get_formatter_for_filename(fn, **options) - - Return a :class:`.Formatter` subclass instance that has a filename pattern - matching `fn`. The formatter is given the `options` at its instantiation. - - Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename - is found. - -.. function:: load_formatter_from_file(filename, formattername="CustomFormatter", **options) - - Return a `Formatter` subclass instance loaded from the provided file, relative - to the current directory. The file is expected to contain a Formatter class - named ``formattername`` (by default, CustomFormatter). Users should be very - careful with the input, because this method is equivalent to running eval - on the input file. The formatter is given the `options` at its instantiation. - - :exc:`pygments.util.ClassNotFound` is raised if there are any errors loading the Formatter - - .. versionadded:: 2.2 +.. autofunction:: get_formatter_by_name +.. autofunction:: get_formatter_for_filename +.. autofunction:: load_formatter_from_file .. module:: pygments.styles Functions from :mod:`pygments.styles`: -.. function:: get_style_by_name(name) - - Return a style class by its short name. The names of the builtin styles - are listed in :data:`pygments.styles.STYLE_MAP`. - - Will raise :exc:`pygments.util.ClassNotFound` if no style of that name is - found. - -.. function:: get_all_styles() - - Return an iterable over all registered styles, yielding their names. - - .. versionadded:: 0.6 +.. autofunction:: get_style_by_name +.. autofunction:: get_all_styles .. module:: pygments.lexer diff --git a/pygments/formatters/__init__.py b/pygments/formatters/__init__.py index 5e771a04..67caccf1 100644 --- a/pygments/formatters/__init__.py +++ b/pygments/formatters/__init__.py @@ -68,9 +68,12 @@ def find_formatter_class(alias): def get_formatter_by_name(_alias, **options): - """Lookup and instantiate a formatter by alias. + """ + Return an instance of a :class:`.Formatter` subclass that has `alias` in its + aliases list. The formatter is given the `options` at its instantiation. - Raises ClassNotFound if not found. + Will raise :exc:`pygments.util.ClassNotFound` if no formatter with that + alias is found. """ cls = find_formatter_class(_alias) if cls is None: @@ -78,19 +81,18 @@ def get_formatter_by_name(_alias, **options): return cls(**options) -def load_formatter_from_file(filename, formattername="CustomFormatter", - **options): - """Load a formatter from a file. - - This method expects a file located relative to the current working - directory, which contains a class named CustomFormatter. By default, - it expects the Formatter to be named CustomFormatter; you can specify - your own class name as the second argument to this function. +def load_formatter_from_file(filename, formattername="CustomFormatter", **options): + """ + Return a `Formatter` subclass instance loaded from the provided file, relative + to the current directory. - Users should be very careful with the input, because this method - is equivalent to running eval on the input file. + The file is expected to contain a Formatter class named ``formattername`` + (by default, CustomFormatter). Users should be very careful with the input, because + this method is equivalent to running ``eval()`` on the input file. The formatter is + given the `options` at its instantiation. - Raises ClassNotFound if there are any problems importing the Formatter. + :exc:`pygments.util.ClassNotFound` is raised if there are any errors loading + the formatter. .. versionadded:: 2.2 """ @@ -115,9 +117,12 @@ def load_formatter_from_file(filename, formattername="CustomFormatter", def get_formatter_for_filename(fn, **options): - """Lookup and instantiate a formatter by filename pattern. + """ + Return a :class:`.Formatter` subclass instance that has a filename pattern + matching `fn`. The formatter is given the `options` at its instantiation. - Raises ClassNotFound if not found. + Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename + is found. """ fn = basename(fn) for modname, name, _, filenames, _ in FORMATTERS.values(): diff --git a/pygments/styles/__init__.py b/pygments/styles/__init__.py index a58c4e13..34744c6a 100644 --- a/pygments/styles/__init__.py +++ b/pygments/styles/__init__.py @@ -66,6 +66,13 @@ STYLE_MAP = { def get_style_by_name(name): + """ + Return a style class by its short name. The names of the builtin styles + are listed in :data:`pygments.styles.STYLE_MAP`. + + Will raise :exc:`pygments.util.ClassNotFound` if no style of that name is + found. + """ if name in STYLE_MAP: mod, cls = STYLE_MAP[name].split('::') builtin = "yes" @@ -90,8 +97,7 @@ def get_style_by_name(name): def get_all_styles(): - """Return a generator for all styles by name, - both builtin and plugin.""" + """Return a generator for all styles by name, both builtin and plugin.""" yield from STYLE_MAP for name, _ in find_plugin_styles(): yield name |