Skip to content

Commit e843b85

Browse files
authored
Fix missed deprecations (#15)
- Fix some missed deprecations - Fix config parsing - Fix passing of configuration into CrystalCollector
1 parent 9904395 commit e843b85

6 files changed

Lines changed: 44 additions & 29 deletions

File tree

.github/workflows/autofix.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
python-version: '3.12'
1515
- name: Install Hatch
1616
run: |
17+
pip install 'pip==25.2'
1718
pip install hatch
1819
- name: Install dependencies
1920
run: |

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
sed -i -E 's/#min //; s/\b >=([0-9])/ ==\1/' pyproject.toml
4343
- name: Install Hatch
4444
run: |
45+
pip install 'pip==25.2'
4546
pip install hatch
4647
- name: Install dependencies
4748
run: |
@@ -60,6 +61,7 @@ jobs:
6061
python-version: '3.12'
6162
- name: Install Hatch
6263
run: |
64+
pip install 'pip==25.2'
6365
pip install hatch
6466
- name: Install dependencies
6567
run: |
Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,52 @@
11
from __future__ import annotations
22

3-
from collections.abc import Mapping, Sequence
4-
from typing import Any
3+
from collections.abc import Mapping, MutableMapping, Sequence
4+
from typing import TYPE_CHECKING, Any
55

6-
from mkdocstrings import BaseHandler
6+
from mkdocstrings import BaseHandler, HandlerOptions
77

88
from . import inventory
99
from .collector import CrystalCollector
1010
from .renderer import CrystalRenderer
1111

12-
__version__ = "0.3.8"
12+
if TYPE_CHECKING:
13+
from markdown import Extension
14+
from mkdocs.config.defaults import MkDocsConfig
15+
16+
__version__ = "0.3.9"
1317

1418

1519
class CrystalHandler(CrystalCollector, CrystalRenderer, BaseHandler):
20+
name = "crystal"
21+
domain = "cr"
1622
load_inventory = staticmethod(inventory.list_object_urls) # type: ignore[assignment]
1723

1824
def __init__(
1925
self,
26+
*,
2027
theme: str,
2128
custom_templates: str | None = None,
22-
crystal_docs_flags: Sequence[str] = (),
23-
source_locations: Mapping[str, str] = {},
24-
**config: Any,
29+
mdx: Sequence[str | Extension],
30+
mdx_config: Mapping[str, Any],
31+
handler_config: MutableMapping[str, Any],
32+
tool_config: MkDocsConfig,
2533
) -> None:
26-
BaseHandler.__init__(self, "crystal", theme, custom_templates)
34+
BaseHandler.__init__(
35+
self, theme=theme, custom_templates=custom_templates, mdx=mdx, mdx_config=mdx_config
36+
)
2737
CrystalCollector.__init__(
28-
self, crystal_docs_flags=crystal_docs_flags, source_locations=source_locations
38+
self,
39+
**handler_config,
2940
)
3041

42+
def get_options(self, local_options: Mapping[str, Any]) -> HandlerOptions:
43+
return {
44+
"nested_types": False,
45+
"file_filters": True,
46+
"show_source_links": True,
47+
"heading_level": 2,
48+
**local_options,
49+
}
50+
3151

3252
get_handler = CrystalHandler

mkdocstrings_handlers/crystal/collector.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from functools import cached_property
1414
from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast
1515

16-
from mkdocstrings import BaseHandler, CollectionError
16+
from mkdocstrings import BaseHandler, CollectionError, HandlerOptions
1717

1818
from . import inventory
1919
from .items import DocConstant, DocItem, DocLocation, DocMapping, DocMethod, DocModule, DocType
@@ -82,22 +82,16 @@ def root(self) -> DocRoot:
8282
cmd = " ".join(shlex.quote(arg) for arg in args)
8383
raise PluginError(f"Command `{cmd}` exited with status {self._proc.returncode}")
8484

85-
def collect(self, identifier: str, config: Mapping[str, Any]) -> DocView:
85+
def collect(self, identifier: str, options: HandlerOptions) -> DocView:
8686
"""[Find][mkdocstrings_handlers.crystal.items.DocItem.lookup] an item by its identifier.
8787
8888
Raises:
8989
CollectionError: When an item by that identifier couldn't be found.
9090
"""
91-
config = {
92-
"nested_types": False,
93-
"file_filters": True,
94-
**config,
95-
}
96-
9791
item: DocItem = self.root
9892
if identifier != "::":
9993
item = item.lookup(identifier)
100-
return DocView(item, config)
94+
return DocView(item, options)
10195

10296

10397
@dataclasses.dataclass

mkdocstrings_handlers/crystal/renderer.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@ def collector(self):
2424
return self
2525

2626
def render(self, data: DocItem, options: HandlerOptions, *, locale: str | None = None) -> str:
27-
subconfig = {
28-
"show_source_links": True,
29-
"heading_level": 2,
30-
**options,
31-
}
3227
template = self.env.get_template(data._TEMPLATE)
3328

3429
with self._monkeypatch_highlight_function(default_lang="crystal"):
3530
return template.render(
36-
config=subconfig,
31+
config=options,
3732
obj=data,
38-
heading_level=subconfig["heading_level"],
33+
heading_level=options["heading_level"],
3934
root=True,
4035
)
4136

42-
@classmethod
43-
def get_anchors(cls, data: DocItem) -> tuple[str, ...]:
44-
return (data.abs_id,)
37+
def get_aliases(self, identifier: str) -> tuple[str, ...]:
38+
try:
39+
data = self.collector.root.lookup(identifier)
40+
return (data.abs_id,)
41+
except CollectionError:
42+
return (identifier,)
4543

4644
def update_env(self, config: dict) -> None:
4745
self._pymdownx_hl = None

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ include = ["/mkdocstrings_handlers", "/tests"]
5959
[tool.hatch.env]
6060
requires = [
6161
"hatch-mkdocs",
62-
"hatch-pip-compile >=1.7.0",
62+
"hatch-pip-compile >=1.11.2",
6363
]
6464

6565
[tool.hatch.build.targets.wheel]

0 commit comments

Comments
 (0)