rendering ¤
This module implements rendering utilities.
Classes:
-
Order
–Enumeration for the possible members ordering.
Functions:
-
do_any
–Check if at least one of the item in the sequence evaluates to true.
-
do_as_attributes_section
–Build an attributes section from a list of attributes.
-
do_as_classes_section
–Build a classes section from a list of classes.
-
do_as_functions_section
–Build a functions section from a list of functions.
-
do_as_modules_section
–Build a modules section from a list of modules.
-
do_filter_objects
–Filter a dictionary of objects based on their docstrings.
-
do_format_attribute
–Format an attribute using Black.
-
do_format_code
–Format code using Black.
-
do_format_signature
–Format a signature using Black.
-
do_heading
–Render a Markdown heading.
-
do_order_members
–Order members given an ordering method.
-
do_split_path
–Split object paths for building cross-references.
-
from_private_package
–Tell if an alias points to an object coming from a corresponding private package.
Order ¤
Bases: Enum
Enumeration for the possible members ordering.
Attributes:
-
alphabetical
–Alphabetical order.
-
source
–Source code order.
do_any ¤
Check if at least one of the item in the sequence evaluates to true.
The any
builtin as a filter for Jinja templates.
Parameters:
-
seq
(Sequence
) –An iterable object.
-
attribute
(str | None
, default:None
) –The attribute name to use on each object of the iterable.
Returns:
-
bool
–A boolean telling if any object of the iterable evaluated to True.
Source code in src/griffe2md/rendering.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
do_as_attributes_section ¤
do_as_attributes_section(
attributes: Sequence[Attribute],
*,
check_public: bool = True
) -> DocstringSectionAttributes
Build an attributes section from a list of attributes.
Parameters:
-
attributes
(Sequence[Attribute]
) –The attributes to build the section from.
-
check_public
(bool
, default:True
) –Whether to check if the attribute is public.
Returns:
-
DocstringSectionAttributes
–An attributes docstring section.
Source code in src/griffe2md/rendering.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
|
do_as_classes_section ¤
do_as_classes_section(
classes: Sequence[Class], *, check_public: bool = True
) -> DocstringSectionClasses
Build a classes section from a list of classes.
Parameters:
-
classes
(Sequence[Class]
) –The classes to build the section from.
-
check_public
(bool
, default:True
) –Whether to check if the class is public.
Returns:
-
DocstringSectionClasses
–A classes docstring section.
Source code in src/griffe2md/rendering.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
do_as_functions_section ¤
do_as_functions_section(
functions: Sequence[Function],
*,
check_public: bool = True
) -> DocstringSectionFunctions
Build a functions section from a list of functions.
Parameters:
-
functions
(Sequence[Function]
) –The functions to build the section from.
-
check_public
(bool
, default:True
) –Whether to check if the function is public.
Returns:
-
DocstringSectionFunctions
–A functions docstring section.
Source code in src/griffe2md/rendering.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
do_as_modules_section ¤
do_as_modules_section(
modules: Sequence[Module], *, check_public: bool = True
) -> DocstringSectionModules
Build a modules section from a list of modules.
Parameters:
-
modules
(Sequence[Module]
) –The modules to build the section from.
-
check_public
(bool
, default:True
) –Whether to check if the module is public.
Returns:
-
DocstringSectionModules
–A modules docstring section.
Source code in src/griffe2md/rendering.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
|
do_filter_objects ¤
do_filter_objects(
objects_dictionary: dict[str, Object | Alias],
*,
filters: Sequence[tuple[Pattern, bool]] | None = None,
members_list: bool | list[str] | None = None,
inherited_members: bool | list[str] = False,
keep_no_docstrings: bool = True
) -> list[Object | Alias]
Filter a dictionary of objects based on their docstrings.
Parameters:
-
objects_dictionary
(dict[str, Object | Alias]
) –The dictionary of objects.
-
filters
(Sequence[tuple[Pattern, bool]] | None
, default:None
) –Filters to apply, based on members' names. Each element is a tuple: a pattern, and a boolean indicating whether to reject the object if the pattern matches.
-
members_list
(bool | list[str] | None
, default:None
) –An optional, explicit list of members to keep. When given and empty, return an empty list. When given and not empty, ignore filters and docstrings presence/absence.
-
inherited_members
(bool | list[str]
, default:False
) –Whether to keep inherited members or exclude them.
-
keep_no_docstrings
(bool
, default:True
) –Whether to keep objects with no/empty docstrings (recursive check).
Returns:
-
list[Object | Alias]
–A list of objects.
Source code in src/griffe2md/rendering.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
do_format_attribute ¤
do_format_attribute(
context: Context,
attribute_path: Markup,
attribute: Attribute,
line_length: int,
*,
crossrefs: bool = False
) -> str
Format an attribute using Black.
Parameters:
-
context
(Context
) –Jinja context, passed automatically.
-
attribute_path
(Markup
) –The path of the callable we render the signature of.
-
attribute
(Attribute
) –The attribute we render the signature of.
-
line_length
(int
) –The line length to give to Black.
-
crossrefs
(bool
, default:False
) –Whether to cross-reference types in the signature.
Returns:
-
str
–The same code, formatted.
Source code in src/griffe2md/rendering.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
do_format_code ¤
Format code using Black.
Parameters:
Returns:
-
str
–The same code, formatted.
Source code in src/griffe2md/rendering.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
do_format_signature ¤
do_format_signature(
context: Context,
callable_path: Markup,
function: Function,
line_length: int,
*,
annotations: bool | None = None,
crossrefs: bool = False
) -> str
Format a signature using Black.
Parameters:
-
context
(Context
) –Jinja context, passed automatically.
-
callable_path
(Markup
) –The path of the callable we render the signature of.
-
function
(Function
) –The function we render the signature of.
-
line_length
(int
) –The line length to give to Black.
-
annotations
(bool | None
, default:None
) –Whether to show type annotations.
-
crossrefs
(bool
, default:False
) –Whether to cross-reference types in the signature.
Returns:
-
str
–The same code, formatted.
Source code in src/griffe2md/rendering.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
do_heading ¤
Render a Markdown heading.
Source code in src/griffe2md/rendering.py
309 310 311 |
|
do_order_members ¤
do_order_members(
members: Sequence[Object | Alias],
order: Order,
members_list: bool | list[str] | None,
) -> Sequence[Object | Alias]
Order members given an ordering method.
Parameters:
-
members
(Sequence[Object | Alias]
) –The members to order.
-
order
(Order
) –The ordering method.
-
members_list
(bool | list[str] | None
) –An optional member list (manual ordering).
Returns:
-
Sequence[Object | Alias]
–The same members, ordered.
Source code in src/griffe2md/rendering.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
do_split_path ¤
Split object paths for building cross-references.
Parameters:
-
path
(str
) –The path to split.
Returns:
Source code in src/griffe2md/rendering.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
from_private_package ¤
from_private_package(obj: Object | Alias) -> bool
Tell if an alias points to an object coming from a corresponding private package.
For example, return true for an alias in package ast
pointing at an object in package _ast
.
Parameters:
-
obj
(Object | Alias
) –The object (alias) to check.
Returns:
-
bool
–True or false.
Source code in src/griffe2md/rendering.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|