|
2 | 2 | # and exposes them as public objects. We have tests to make sure |
3 | 3 | # no object is forgotten in this list. |
4 | 4 |
|
5 | | -"""Griffe package. |
| 5 | +"""Griffe library package. |
6 | 6 |
|
7 | 7 | Signatures for entire Python programs. |
8 | 8 | Extract the structure, the frame, the skeleton of your project, |
9 | 9 | to generate API documentation or find breaking changes in your API. |
10 | 10 |
|
11 | | -The entirety of the public API is exposed here, in the top-level `griffelib` module. |
| 11 | +The entirety of the library API is exposed here, in the top-level `griffelib` module. |
| 12 | +For backward compatibility, you can also import from `griffe` which re-exports everything. |
12 | 13 |
|
13 | 14 | All messages written to standard output or error are logged using the `logging` module. |
14 | | -Our logger's name is set to `"griffelib"` and is public (you can rely on it). |
15 | | -You can obtain the logger from the standard `logging` module: `logging.getLogger("griffelib")`. |
| 15 | +Our logger's name is set to `"griffe"` and is public (you can rely on it). |
| 16 | +You can obtain the logger from the standard `logging` module: `logging.getLogger("griffe")`. |
16 | 17 | Actual logging messages are not part of the public API (they might change without notice). |
17 | 18 |
|
18 | 19 | Raised exceptions throughout the package are part of the public API (you can rely on them). |
19 | 20 | Their actual messages are not part of the public API (they might change without notice). |
20 | 21 |
|
21 | 22 | The following paragraphs will help you discover the package's content. |
22 | 23 |
|
23 | | -## CLI entrypoints |
24 | | -
|
25 | | -Griffe provides a command-line interface (CLI) to interact with the package. The CLI entrypoints can be called from Python code. |
26 | | -
|
27 | | -- [`griffecli.main`][]: Run the main program. |
28 | | -- [`griffecli.check`][]: Check for API breaking changes in two versions of the same package. |
29 | | -- [`griffecli.dump`][]: Load packages data and dump it as JSON. |
30 | | -
|
31 | 24 | ## Loaders |
32 | 25 |
|
33 | 26 | To load API data, Griffe provides several high-level functions. |
34 | 27 |
|
35 | | -- [`griffelib.load`][]: Load and return a Griffe object. |
36 | | -- [`griffelib.load_git`][]: Load and return a module from a specific Git reference. |
37 | | -- [`griffelib.load_pypi`][]: Load and return a module from a specific package version downloaded using pip. |
| 28 | +- [`griffe.load`][]: Load and return a Griffe object. |
| 29 | +- [`griffe.load_git`][]: Load and return a module from a specific Git reference. |
| 30 | +- [`griffe.load_pypi`][]: Load and return a module from a specific package version downloaded using pip. |
38 | 31 |
|
39 | 32 | ## Models |
40 | 33 |
|
41 | 34 | The data loaded by Griffe is represented by several classes. |
42 | 35 |
|
43 | | -- [`griffelib.Module`][]: The class representing a Python module. |
44 | | -- [`griffelib.Class`][]: The class representing a Python class. |
45 | | -- [`griffelib.Function`][]: The class representing a Python function or method. |
46 | | -- [`griffelib.Attribute`][]: The class representing a Python attribute. |
47 | | -- [`griffelib.Alias`][]: This class represents an alias, or indirection, to an object declared in another module. |
| 36 | +- [`griffe.Module`][]: The class representing a Python module. |
| 37 | +- [`griffe.Class`][]: The class representing a Python class. |
| 38 | +- [`griffe.Function`][]: The class representing a Python function or method. |
| 39 | +- [`griffe.Attribute`][]: The class representing a Python attribute. |
| 40 | +- [`griffe.Alias`][]: This class represents an alias, or indirection, to an object declared in another module. |
48 | 41 |
|
49 | 42 | Additional classes are available to represent other concepts. |
50 | 43 |
|
51 | | -- [`griffelib.Decorator`][]: This class represents a decorator. |
52 | | -- [`griffelib.Parameters`][]: This class is a container for parameters. |
53 | | -- [`griffelib.Parameter`][]: This class represent a function parameter. |
| 44 | +- [`griffe.Decorator`][]: This class represents a decorator. |
| 45 | +- [`griffe.Parameters`][]: This class is a container for parameters. |
| 46 | +- [`griffe.Parameter`][]: This class represent a function parameter. |
54 | 47 |
|
55 | 48 | ## Agents |
56 | 49 |
|
57 | 50 | Griffe is able to analyze code both statically and dynamically, using the following "agents". |
58 | 51 | However most of the time you will only need to use the loaders above. |
59 | 52 |
|
60 | | -- [`griffelib.visit`][]: Parse and visit a module file. |
61 | | -- [`griffelib.inspect`][]: Inspect a module. |
| 53 | +- [`griffe.visit`][]: Parse and visit a module file. |
| 54 | +- [`griffe.inspect`][]: Inspect a module. |
62 | 55 |
|
63 | 56 | ## Serializers |
64 | 57 |
|
65 | 58 | Griffe can serizalize data to dictionary and JSON. |
66 | 59 |
|
67 | | -- [`griffelib.Object.as_json`][griffelib.Object.as_json] |
68 | | -- [`griffelib.Object.from_json`][griffelib.Object.from_json] |
69 | | -- [`griffelib.JSONEncoder`][]: JSON encoder for Griffe objects. |
70 | | -- [`griffelib.json_decoder`][]: JSON decoder for Griffe objects. |
| 60 | +- [`griffe.Object.as_json`][griffe.Object.as_json] |
| 61 | +- [`griffe.Object.from_json`][griffe.Object.from_json] |
| 62 | +- [`griffe.JSONEncoder`][]: JSON encoder for Griffe objects. |
| 63 | +- [`griffe.json_decoder`][]: JSON decoder for Griffe objects. |
71 | 64 |
|
72 | 65 | ## API checks |
73 | 66 |
|
74 | 67 | Griffe can compare two versions of the same package to find breaking changes. |
75 | 68 |
|
76 | | -- [`griffelib.find_breaking_changes`][]: Find breaking changes between two versions of the same API. |
77 | | -- [`griffelib.Breakage`][]: Breakage classes can explain what broke from a version to another. |
| 69 | +- [`griffe.find_breaking_changes`][]: Find breaking changes between two versions of the same API. |
| 70 | +- [`griffe.Breakage`][]: Breakage classes can explain what broke from a version to another. |
78 | 71 |
|
79 | 72 | ## Extensions |
80 | 73 |
|
81 | | -Griffe supports extensions. You can create your own extension by subclassing the `griffelib.Extension` class. |
| 74 | +Griffe supports extensions. You can create your own extension by subclassing the `griffe.Extension` class. |
82 | 75 |
|
83 | | -- [`griffelib.load_extensions`][]: Load configured extensions. |
84 | | -- [`griffelib.Extension`][]: Base class for Griffe extensions. |
| 76 | +- [`griffe.load_extensions`][]: Load configured extensions. |
| 77 | +- [`griffe.Extension`][]: Base class for Griffe extensions. |
85 | 78 |
|
86 | 79 | ## Docstrings |
87 | 80 |
|
88 | 81 | Griffe can parse docstrings into structured data. |
89 | 82 |
|
90 | 83 | Main class: |
91 | 84 |
|
92 | | -- [`griffelib.Docstring`][]: This class represents docstrings. |
| 85 | +- [`griffe.Docstring`][]: This class represents docstrings. |
93 | 86 |
|
94 | 87 | Docstring section and element classes all start with `Docstring`. |
95 | 88 |
|
96 | 89 | Docstring parsers: |
97 | 90 |
|
98 | | -- [`griffelib.parse`][]: Parse the docstring. |
99 | | -- [`griffelib.parse_auto`][]: Parse a docstring by automatically detecting the style it uses. |
100 | | -- [`griffelib.parse_google`][]: Parse a Google-style docstring. |
101 | | -- [`griffelib.parse_numpy`][]: Parse a Numpydoc-style docstring. |
102 | | -- [`griffelib.parse_sphinx`][]: Parse a Sphinx-style docstring. |
| 91 | +- [`griffe.parse`][]: Parse the docstring. |
| 92 | +- [`griffe.parse_auto`][]: Parse a docstring by automatically detecting the style it uses. |
| 93 | +- [`griffe.parse_google`][]: Parse a Google-style docstring. |
| 94 | +- [`griffe.parse_numpy`][]: Parse a Numpydoc-style docstring. |
| 95 | +- [`griffe.parse_sphinx`][]: Parse a Sphinx-style docstring. |
103 | 96 |
|
104 | 97 | ## Exceptions |
105 | 98 |
|
106 | 99 | Griffe uses several exceptions to signal errors. |
107 | 100 |
|
108 | | -- [`griffelib.GriffeError`][]: The base exception for all Griffe errors. |
109 | | -- [`griffelib.LoadingError`][]: Exception for loading errors. |
110 | | -- [`griffelib.NameResolutionError`][]: Exception for names that cannot be resolved in a object scope. |
111 | | -- [`griffelib.UnhandledEditableModuleError`][]: Exception for unhandled editables modules, when searching modules. |
112 | | -- [`griffelib.UnimportableModuleError`][]: Exception for modules that cannot be imported. |
113 | | -- [`griffelib.AliasResolutionError`][]: Exception for aliases that cannot be resolved. |
114 | | -- [`griffelib.CyclicAliasError`][]: Exception raised when a cycle is detected in aliases. |
115 | | -- [`griffelib.LastNodeError`][]: Exception raised when trying to access a next or previous node. |
116 | | -- [`griffelib.RootNodeError`][]: Exception raised when trying to use siblings properties on a root node. |
117 | | -- [`griffelib.BuiltinModuleError`][]: Exception raised when trying to access the filepath of a builtin module. |
118 | | -- [`griffelib.ExtensionError`][]: Base class for errors raised by extensions. |
119 | | -- [`griffelib.ExtensionNotLoadedError`][]: Exception raised when an extension could not be loaded. |
120 | | -- [`griffelib.GitError`][]: Exception raised for errors related to Git. |
| 101 | +- [`griffe.GriffeError`][]: The base exception for all Griffe errors. |
| 102 | +- [`griffe.LoadingError`][]: Exception for loading errors. |
| 103 | +- [`griffe.NameResolutionError`][]: Exception for names that cannot be resolved in a object scope. |
| 104 | +- [`griffe.UnhandledEditableModuleError`][]: Exception for unhandled editables modules, when searching modules. |
| 105 | +- [`griffe.UnimportableModuleError`][]: Exception for modules that cannot be imported. |
| 106 | +- [`griffe.AliasResolutionError`][]: Exception for aliases that cannot be resolved. |
| 107 | +- [`griffe.CyclicAliasError`][]: Exception raised when a cycle is detected in aliases. |
| 108 | +- [`griffe.LastNodeError`][]: Exception raised when trying to access a next or previous node. |
| 109 | +- [`griffe.RootNodeError`][]: Exception raised when trying to use siblings properties on a root node. |
| 110 | +- [`griffe.BuiltinModuleError`][]: Exception raised when trying to access the filepath of a builtin module. |
| 111 | +- [`griffe.ExtensionError`][]: Base class for errors raised by extensions. |
| 112 | +- [`griffe.ExtensionNotLoadedError`][]: Exception raised when an extension could not be loaded. |
| 113 | +- [`griffe.GitError`][]: Exception raised for errors related to Git. |
121 | 114 |
|
122 | 115 | # Expressions |
123 | 116 |
|
124 | 117 | Griffe stores snippets of code (attribute values, decorators, base class, type annotations) as expressions. |
125 | 118 | Expressions are basically abstract syntax trees (AST) with a few differences compared to the nodes returned by [`ast`][]. |
126 | 119 | Griffe provides a few helpers to extract expressions from regular AST nodes. |
127 | 120 |
|
128 | | -- [`griffelib.get_annotation`][]: Get a type annotation as expression. |
129 | | -- [`griffelib.get_base_class`][]: Get a base class as expression. |
130 | | -- [`griffelib.get_class_keyword`][]: Get a class keyword as expression. |
131 | | -- [`griffelib.get_condition`][]: Get a condition as expression. |
132 | | -- [`griffelib.get_expression`][]: Get an expression from an AST node. |
133 | | -- [`griffelib.safe_get_annotation`][]: Get a type annotation as expression, safely (returns `None` on error). |
134 | | -- [`griffelib.safe_get_base_class`][]: Get a base class as expression, safely (returns `None` on error). |
135 | | -- [`griffelib.safe_get_class_keyword`][]: Get a class keyword as expression, safely (returns `None` on error). |
136 | | -- [`griffelib.safe_get_condition`][]: Get a condition as expression, safely (returns `None` on error). |
137 | | -- [`griffelib.safe_get_expression`][]: Get an expression from an AST node, safely (returns `None` on error). |
| 121 | +- [`griffe.get_annotation`][]: Get a type annotation as expression. |
| 122 | +- [`griffe.get_base_class`][]: Get a base class as expression. |
| 123 | +- [`griffe.get_class_keyword`][]: Get a class keyword as expression. |
| 124 | +- [`griffe.get_condition`][]: Get a condition as expression. |
| 125 | +- [`griffe.get_expression`][]: Get an expression from an AST node. |
| 126 | +- [`griffe.safe_get_annotation`][]: Get a type annotation as expression, safely (returns `None` on error). |
| 127 | +- [`griffe.safe_get_base_class`][]: Get a base class as expression, safely (returns `None` on error). |
| 128 | +- [`griffe.safe_get_class_keyword`][]: Get a class keyword as expression, safely (returns `None` on error). |
| 129 | +- [`griffe.safe_get_condition`][]: Get a condition as expression, safely (returns `None` on error). |
| 130 | +- [`griffe.safe_get_expression`][]: Get an expression from an AST node, safely (returns `None` on error). |
138 | 131 |
|
139 | 132 | The base class for expressions. |
140 | 133 |
|
141 | | -- [`griffelib.Expr`][] |
| 134 | +- [`griffe.Expr`][] |
142 | 135 |
|
143 | 136 | Expression classes all start with `Expr`. |
144 | 137 |
|
|
147 | 140 | If you want to log messages from extensions, get a logger with `get_logger`. |
148 | 141 | The `logger` attribute is used by Griffe itself. You can use it to temporarily disable Griffe logging. |
149 | 142 |
|
150 | | -- [`griffelib.logger`][]: Our global logger, used throughout the library. |
151 | | -- [`griffelib.get_logger`][]: Create and return a new logger instance. |
| 143 | +- [`griffe.logger`][]: Our global logger, used throughout the library. |
| 144 | +- [`griffe.get_logger`][]: Create and return a new logger instance. |
152 | 145 |
|
153 | 146 | # Helpers |
154 | 147 |
|
155 | 148 | To test your Griffe extensions, or to load API data from code in memory, Griffe provides the following helpers. |
156 | 149 |
|
157 | | -- [`griffelib.temporary_pyfile`][]: Create a Python file containing the given code in a temporary directory. |
158 | | -- [`griffelib.temporary_pypackage`][]: Create a package containing the given modules in a temporary directory. |
159 | | -- [`griffelib.temporary_visited_module`][]: Create and visit a temporary module with the given code. |
160 | | -- [`griffelib.temporary_visited_package`][]: Create and visit a temporary package. |
161 | | -- [`griffelib.temporary_inspected_module`][]: Create and inspect a temporary module with the given code. |
162 | | -- [`griffelib.temporary_inspected_package`][]: Create and inspect a temporary package. |
| 150 | +- [`griffe.temporary_pyfile`][]: Create a Python file containing the given code in a temporary directory. |
| 151 | +- [`griffe.temporary_pypackage`][]: Create a package containing the given modules in a temporary directory. |
| 152 | +- [`griffe.temporary_visited_module`][]: Create and visit a temporary module with the given code. |
| 153 | +- [`griffe.temporary_visited_package`][]: Create and visit a temporary package. |
| 154 | +- [`griffe.temporary_inspected_module`][]: Create and inspect a temporary module with the given code. |
| 155 | +- [`griffe.temporary_inspected_package`][]: Create and inspect a temporary package. |
163 | 156 | """ |
164 | 157 |
|
165 | 158 | from __future__ import annotations |
|
185 | 178 | from griffelib._internal.agents.nodes.values import get_value, safe_get_value |
186 | 179 | from griffelib._internal.agents.visitor import Visitor, builtin_decorators, stdlib_decorators, typing_overload, visit |
187 | 180 | from griffelib._internal.c3linear import c3linear_merge |
188 | | -from griffecli._internal.cli import DEFAULT_LOG_LEVEL, check, dump, get_parser, main |
189 | 181 | from griffelib._internal.collections import LinesCollection, ModulesCollection |
190 | 182 | from griffelib._internal.diff import ( |
191 | 183 | AttributeChangedTypeBreakage, |
|
383 | 375 | # names = sorted(n for n in dir(griffelib) if not n.startswith("_") and n not in ("annotations",)) |
384 | 376 | # print('__all__ = [\n "' + '",\n "'.join(names) + '",\n]') |
385 | 377 | __all__ = [ |
386 | | - "DEFAULT_LOG_LEVEL", |
387 | 378 | "Alias", |
388 | 379 | "AliasResolutionError", |
389 | 380 | "Attribute", |
|
546 | 537 | "builtin_decorators", |
547 | 538 | "builtin_extensions", |
548 | 539 | "c3linear_merge", |
549 | | - "check", |
550 | 540 | "docstring_warning", |
551 | | - "dump", |
552 | 541 | "dynamic_import", |
553 | 542 | "find_breaking_changes", |
554 | 543 | "get__all__", |
|
563 | 552 | "get_name", |
564 | 553 | "get_names", |
565 | 554 | "get_parameters", |
566 | | - "get_parser", |
567 | 555 | "get_value", |
568 | 556 | "htree", |
569 | 557 | "infer_docstring_style", |
|
574 | 562 | "load_git", |
575 | 563 | "load_pypi", |
576 | 564 | "logger", |
577 | | - "main", |
578 | 565 | "merge_stubs", |
579 | 566 | "module_vtree", |
580 | 567 | "parse", |
|
0 commit comments