GitHub

@@ -61,30 +61,8 @@ class PythonHandler(BaseHandler):

6161

which we know will not generate any warnings.

6262

"""

636364-

default_collection_config: dict = {"filters": ["!^_[^_]"]}

65-

"""The default selection options.

66-67-

Option | Type | Description | Default

68-

------ | ---- | ----------- | -------

69-

**`filters`** | `List[str]` | Filter members with regular expressions. | `[ "!^_[^_]" ]`

70-

**`members`** | `Union[bool, List[str]]` | Explicitly select the object members. | *`pytkdocs` default: `True`*

71-72-

If `members` is a list of names, filters are applied only on the members children (not the members themselves).

73-

If `members` is `False`, none are selected.

74-

If `members` is `True` or an empty list, filters are applied on all members and their children.

75-76-

Members affect only the first layer of objects, while filters affect the whole object-tree recursively.

77-78-

Every filters is run against every object name. An object can be un-selected by a filter and re-selected by the

79-

next one:

80-81-

- `"!^_"`: exclude all objects starting with an underscore

82-

- `"^__"`: but select all objects starting with **two** underscores

83-84-

Obviously one could use a single filter instead: `"!^_[^_]"`, which is the default.

85-

"""

86-87-

default_rendering_config: dict = {

64+

default_config: dict = {

65+

"filters": ["!^_[^_]"],

8866

"show_root_heading": False,

8967

"show_root_toc_entry": True,

9068

"show_root_full_path": True,

@@ -100,24 +78,44 @@ class PythonHandler(BaseHandler):

10078

"heading_level": 2,

10179

"members_order": "alphabetical",

10280

}

103-

"""The default rendering options.

104-105-

Option | Type | Description | Default

106-

------ | ---- | ----------- | -------

107-

**`show_root_heading`** | `bool` | Show the heading of the object at the root of the documentation tree. | `False`

108-

**`show_root_toc_entry`** | `bool` | If the root heading is not shown, at least add a ToC entry for it. | `True`

109-

**`show_root_full_path`** | `bool` | Show the full Python path for the root object heading. | `True`

110-

**`show_object_full_path`** | `bool` | Show the full Python path of every object. | `False`

111-

**`show_root_members_full_path`** | `bool` | Show the full Python path of objects that are children of the root object (for example, classes in a module). When False, `show_object_full_path` overrides. | `False`

112-

**`show_category_heading`** | `bool` | When grouped by categories, show a heading for each category. | `False`

113-

**`show_if_no_docstring`** | `bool` | Show the object heading even if it has no docstring or children with docstrings. | `False`

114-

**`show_signature`** | `bool` | Show method and function signatures. | `True`

115-

**`show_signature_annotations`** | `bool` | Show the type annotations in method and function signatures. | `False`

116-

**`show_source`** | `bool` | Show the source code of this object. | `True`

117-

**`show_bases`** | `bool` | Show the base classes of a class. | `True`

118-

**`group_by_category`** | `bool` | Group the object's children by categories: attributes, classes, functions, methods, and modules. | `True`

119-

**`heading_level`** | `int` | The initial heading level to use. | `2`

120-

**`members_order`** | `str` | The members ordering to use. Options: `alphabetical` - order by the members names, `source` - order members as they appear in the source file. | `alphabetical`

81+

"""

82+

**Headings options:**

83+84+

- `heading_level` (`int`): The initial heading level to use. Default: `2`.

85+

- `show_root_heading` (`bool`): Show the heading of the object at the root of the documentation tree

86+

(i.e. the object referenced by the identifier after `:::`). Default: `False`.

87+

- `show_root_toc_entry` (`bool`): If the root heading is not shown, at least add a ToC entry for it. Default: `True`.

88+

- `show_root_full_path` (`bool`): Show the full Python path for the root object heading. Default: `True`.

89+

- `show_root_members_full_path` (`bool`): Show the full Python path of the root members. Default: `False`.

90+

- `show_object_full_path` (`bool`): Show the full Python path of every object. Default: `False`.

91+

- `show_category_heading` (`bool`): When grouped by categories, show a heading for each category. Default: `False`.

92+93+

**Members options:**

94+95+

- `members` (`list[str] | False | None`): An explicit list of members to render. Default: `None`.

96+

- `members_order` (`str`): The members ordering to use. Options: `alphabetical` - order by the members names,

97+

`source` - order members as they appear in the source file. Default: `"alphabetical"`.

98+

- `filters` (`list[str] | None`): A list of filters applied to filter objects based on their name.

99+

A filter starting with `!` will exclude matching objects instead of including them.

100+

The `members` option takes precedence over `filters` (filters will still be applied recursively

101+

to lower members in the hierarchy). Default: `["!^_[^_]"]`.

102+

- `group_by_category` (`bool`): Group the object's children by categories: attributes, classes, functions, and modules. Default: `True`.

103+104+

**Docstrings options:**

105+106+

- `docstring_style` (`str`): The docstring style to use: `google`, `numpy`, `sphinx`, or `None`. Default: `"google"`.

107+

- `docstring_options` (`dict`): The options for the docstring parser. See parsers under [`pytkdocs.parsers.docstrings`][].

108+

- `show_if_no_docstring` (`bool`): Show the object heading even if it has no docstring or children with docstrings. Default: `False`.

109+110+

**Signatures/annotations options:**

111+112+

- `show_signature` (`bool`): Show methods and functions signatures. Default: `True`.

113+

- `show_signature_annotations` (`bool`): Show the type annotations in methods and functions signatures. Default: `False`.

114+115+

**Additional options:**

116+117+

- `show_bases` (`bool`): Show the base classes of a class. Default: `True`.

118+

- `show_source` (`bool`): Show the source code of this object. Default: `True`.

121119

""" # noqa: E501

122120123121

def __init__( # noqa: WPS231

@@ -139,7 +137,7 @@ def __init__( # noqa: WPS231

139137

*args: Handler name, theme and custom templates.

140138

setup_commands: A list of python commands as strings to be executed in the subprocess before `pytkdocs`.

141139

config_file_path: The MkDocs configuration file path.

142-

paths: A list of paths to use as Griffe search paths.

140+

paths: A list of paths to use as search paths.

143141

**kwargs: Same thing, but with keyword arguments.

144142

"""

145143

logger.debug("Opening 'pytkdocs' subprocess")

@@ -251,10 +249,12 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: WPS2

251249

Returns:

252250

The collected object-tree.

253251

"""

254-

final_config = dict(self.default_collection_config)

252+

final_config = {}

255253

for option in ("filters", "members"):

256254

if option in config:

257255

final_config[option] = config[option]

256+

elif option in self.default_config:

257+

final_config[option] = self.default_config[option]

258258259259

logger.debug("Preparing input")

260260

json_input = json.dumps({"objects": [{"path": identifier, **final_config}]})

@@ -300,7 +300,7 @@ def teardown(self) -> None:

300300

self.process.terminate()

301301302302

def render(self, data: CollectorItem, config: dict) -> str: # noqa: D102 (ignore missing docstring)

303-

final_config = ChainMap(config, self.default_rendering_config)

303+

final_config = ChainMap(config, self.default_config)

304304305305

template = self.env.get_template(f"{data['category']}.html")

306306

@@ -352,7 +352,7 @@ def get_handler(

352352

custom_templates: Directory containing custom templates.

353353

setup_commands: A list of commands as strings to be executed in the subprocess before `pytkdocs`.

354354

config_file_path: The MkDocs configuration file path.

355-

paths: A list of paths to use as Griffe search paths.

355+

paths: A list of paths to use as search paths.

356356

config: Configuration passed to the handler.

357357358358

Returns:

Read the original on github.com ↗