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 /pygments/formatters | |
| parent | a208ea553b17dc50fc2e3498244c74a75909888b (diff) | |
| download | pygments-git-3bb96da3151db1f00501e555c8b52fbac45dcdf6.tar.gz | |
Use autodoc for pygments.styles
Diffstat (limited to 'pygments/formatters')
| -rw-r--r-- | pygments/formatters/__init__.py | 35 |
1 files changed, 20 insertions, 15 deletions
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(): |
