Debian Codegraph @

context/public-api.md

raw
1 # Public surface area
2
3 Starting with ansible-core 2.19 we're trying to be more intentional about what features are part of our public API
4 and other public surface areas (e.g. CLI, configuration options, module arguments, ansible-core provided Jinja globals, etc.).
5
6 ## Imports in public Python modules
7
8 To make public Python modules more self-documenting:
9
10 - Imports in any file considered public API must be sunder-prefixed (e.g. `_module_name`),
11 to avoid confusion about imported objects being part of the public module API.
12 - Prefer module-level imports (e.g. `from ansible._internal import _amodule`) with dotted usage (e.g. `foo: _amodule.thing`).
13 This solves many circular import issues and reduces the need for sunder-prefix aliasing on internal imports in public API.
14 Hot code paths can use locals or aliased objects, but sparingly and only where it really matters.
15
16 ## Internal by default
17
18 New feature implementations in Python code should always be:
19
20 - Added to a module beneath the `ansible._internal` or `ansible.module_utils._internal` package.
21 - In a sunder-prefixed module (easier public module imports without aliasing).
22
23 Only public types and functions should be added to new modules outside `_internal` packages.
24 Small sunder-prefixed utility types and functions are okay in public modules,
25 but in general, non-public API surface area for most new implementations should live completely under an `_internal` package.
26
27 Internal-only types/functions/methods beneath an `_internal` package do not generally require sunder-prefixing on their names.