Skip to content

Commit

Permalink
refactor: Update code for Griffe 0.48 (removing deprecation warnings)
Browse files Browse the repository at this point in the history
Issue-173: #173
  • Loading branch information
pawamoy committed Jul 25, 2024
1 parent bb85ad3 commit eff10cc
Show file tree
Hide file tree
Showing 35 changed files with 53 additions and 50 deletions.
3 changes: 3 additions & 0 deletions config/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ filterwarnings =
error
# TODO: remove once pytest-xdist 4 is released
ignore:.*rsyncdir:DeprecationWarning:xdist
# TODO: remove once Griffe releases v1
ignore:.*`get_logger`:DeprecationWarning:_griffe
ignore:.*`name`:DeprecationWarning:_griffe
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
]
dependencies = [
"mkdocstrings>=0.25",
"griffe>=0.47",
"griffe>=0.48",
]

[project.urls]
Expand Down
17 changes: 10 additions & 7 deletions src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, BinaryIO, ClassVar, Iterator, Mapping, Sequence

from griffe.collections import LinesCollection, ModulesCollection
from griffe.docstrings.parsers import Parser
from griffe.exceptions import AliasResolutionError
from griffe.extensions import load_extensions
from griffe.loader import GriffeLoader
from griffe.logger import patch_loggers
from griffe import (
AliasResolutionError,
GriffeLoader,
LinesCollection,
ModulesCollection,
Parser,
load_extensions,
patch_logger,
)
from mkdocstrings.extension import PluginError
from mkdocstrings.handlers.base import BaseHandler, CollectionError, CollectorItem
from mkdocstrings.inventory import Inventory
Expand Down Expand Up @@ -47,7 +50,7 @@ def chdir(path: str) -> Iterator[None]: # noqa: D103

logger = get_logger(__name__)

patch_loggers(get_logger)
patch_logger(get_logger)


class PythonHandler(BaseHandler):
Expand Down
15 changes: 7 additions & 8 deletions src/mkdocstrings_handlers/python/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Match, Pattern, Sequence

from griffe.dataclasses import Alias, Object
from griffe.docstrings.dataclasses import (
from griffe import (
Alias,
DocstringSectionAttributes,
DocstringSectionClasses,
DocstringSectionFunctions,
DocstringSectionModules,
Object,
)
from jinja2 import TemplateNotFound, pass_context, pass_environment
from markupsafe import Markup
from mkdocstrings.loggers import get_logger

if TYPE_CHECKING:
from griffe.dataclasses import Attribute, Class, Function, Module
from griffe import Attribute, Class, Function, Module
from jinja2 import Environment, Template
from jinja2.runtime import Context
from mkdocstrings.handlers.base import CollectorItem
Expand Down Expand Up @@ -364,11 +365,9 @@ def _keep_object(name: str, filters: Sequence[tuple[Pattern, bool]]) -> bool:
if regex.search(name):
keep = not exclude
if keep is None:
if rules == {False}:
# only included stuff, no match = reject
return False
# only excluded stuff, or included and excluded stuff, no match = keep
return True
# When we only include stuff, no match = reject.
# When we only exclude stuff, or include and exclude stuff, no match = keep.
return rules != {False}
return keep


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a Python attribute (or variable).
This can be a module attribute or a class attribute.
Context:
attribute (griffe.dataclasses.Attribute): The attribute to render.
attribute (griffe.Attribute): The attribute to render.
root (bool): Whether this is the root object, injected with `:::` in a Markdown page.
heading_level (int): The HTML heading level to use.
config (dict): The configuration options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template iterates on members of a given object and renders them.
It can group members by category (attributes, classes, functions, modules) or render them in a flat list.
Context:
obj (griffe.dataclasses.Object): The object to render.
obj (griffe.Object): The object to render.
config (dict): The configuration options.
root_members (bool): Whether the object is the root object.
heading_level (int): The HTML heading level to use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This template renders a Python class.
Context:
class (griffe.dataclasses.Class): The class to render.
class (griffe.Class): The class to render.
root (bool): Whether this is the root object, injected with `:::` in a Markdown page.
heading_level (int): The HTML heading level to use.
config (dict): The configuration options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Griffe parses docstrings into a list of sections, each with a `kind` and a `valu
This template can then iterate on these sections and render them according to the configuration.
Context:
docstring_sections (list[griffe.docstrings.dataclasses.DocstringSection]): The list of docstring sections.
docstring_sections (list[griffe.DocstringSection]): The list of docstring sections.
config (dict): The configuration dictionary.
heading_level (int): The heading level to use for Markdown conversion.
html_id (str): The HTML ID to use for Markdown conversion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This template renders admonitions using the `details` HTML element.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAdmonition): The section to render.
section (griffe.DocstringSectionAdmonition): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented attributes in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented classes in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented examples.
It alternates between rendering text and code examples.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented functions in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented modules in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented other parameters in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented parameters in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented exceptions in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented received values (generators) in the f
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented returned values in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented warnings in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented yielded values (generators) in the fo
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ which is a tree-like structure representing a Python expression.
This macro outputs a cross-reference to the given name.
Parameters:
name (griffe.expressions.ExprName): The name to cross-reference.
name (griffe.ExprName): The name to cross-reference.
annotation_path (str): Either "brief", "source", or "full".
Returns:
Expand Down Expand Up @@ -48,7 +48,7 @@ which is a tree-like structure representing a Python expression.
{#- Render an expression.
Parameters:
expression (griffe.expressions.Expr): The expression to render.
expression (griffe.Expr): The expression to render.
annotations_path (str): Either "brief", "source", or "full".
Returns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This template renders a Python function or method.
Context:
function (griffe.dataclasses.Function): The function to render.
function (griffe.Function): The function to render.
root (bool): Whether this is the root object, injected with `:::` in a Markdown page.
heading_level (int): The HTML heading level to use.
config (dict): The configuration options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This template renders a Python module.
Context:
module (griffe.dataclasses.Module): The module to render.
module (griffe.Module): The module to render.
root (bool): Whether this is the root object, injected with `:::` in a Markdown page.
heading_level (int): The HTML heading level to use.
config (dict): The configuration options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ It iterates over the parameters of the function to rebuild the signature.
The signature is the list of parameters of a function or method, including their names, default values, and annotations.
Context:
function (griffe.dataclasses.Function): The function or method to render.
function (griffe.Function): The function or method to render.
config (dict): The configuration options.
-#}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented attributes in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented other parameters in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented parameters in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented exceptions in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented received values (generators) in the f
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented returned values in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented warnings in the format
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This template renders a list of documented yielded values (generators) in the fo
specified with the [`docstring_section_style`][] configuration option.
Context:
section (griffe.docstrings.dataclasses.DocstringSectionAttributes): The section to render.
section (griffe.DocstringSectionAttributes): The section to render.
-#}

{% block logs scoped %}
Expand Down
3 changes: 1 addition & 2 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from typing import TYPE_CHECKING

import pytest
from griffe.docstrings.dataclasses import DocstringSectionExamples, DocstringSectionKind
from griffe.tests import temporary_visited_module
from griffe import DocstringSectionExamples, DocstringSectionKind, temporary_visited_module

from mkdocstrings_handlers.python.handler import CollectionError, PythonHandler, get_handler

Expand Down
3 changes: 1 addition & 2 deletions tests/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from typing import TYPE_CHECKING, Any

import pytest
from griffe.collections import ModulesCollection
from griffe.tests import temporary_visited_module
from griffe import ModulesCollection, temporary_visited_module

from mkdocstrings_handlers.python import rendering

Expand Down

0 comments on commit eff10cc

Please sign in to comment.