Skip to content

Commit

Permalink
Use _StrPath in HTMLBuilder (#13045)
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner authored Oct 20, 2024
1 parent 08f8e05 commit 285908a
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 137 deletions.
9 changes: 7 additions & 2 deletions sphinx/builders/_epub_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from sphinx.util.osutil import copyfile, ensuredir, relpath

if TYPE_CHECKING:
from pathlib import Path

from docutils.nodes import Element, Node

try:
Expand Down Expand Up @@ -487,7 +489,8 @@ def handle_page(
pagename: str,
addctx: dict[str, Any],
templatename: str = 'page.html',
outfilename: str | None = None,
*,
outfilename: Path | None = None,
event_arg: Any = None,
) -> None:
"""Create a rendered page.
Expand All @@ -500,7 +503,9 @@ def handle_page(
return
self.fix_genindex(addctx['genindexentries'])
addctx['doctype'] = self.doctype
super().handle_page(pagename, addctx, templatename, outfilename, event_arg)
super().handle_page(
pagename, addctx, templatename, outfilename=outfilename, event_arg=event_arg
)

def build_mimetype(self) -> None:
"""Write the metainfo file mimetype."""
Expand Down
18 changes: 7 additions & 11 deletions sphinx/builders/dirhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from __future__ import annotations

from os import path
from pathlib import Path
from typing import TYPE_CHECKING

from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.util import logging
from sphinx.util.osutil import SEP, os_path
from sphinx.util.osutil import SEP

if TYPE_CHECKING:
from sphinx.application import Sphinx
Expand All @@ -32,15 +32,11 @@ def get_target_uri(self, docname: str, typ: str | None = None) -> str:
return docname[:-5] # up to sep
return docname + SEP

def get_outfilename(self, pagename: str) -> str:
if pagename == 'index' or pagename.endswith(SEP + 'index'):
outfilename = path.join(self.outdir, os_path(pagename) + self.out_suffix)
else:
outfilename = path.join(
self.outdir, os_path(pagename), 'index' + self.out_suffix
)

return outfilename
def get_output_path(self, page_name: str, /) -> Path:
page_parts = page_name.split(SEP)
if page_parts[-1] == 'index':
page_parts.pop()
return Path(self.outdir, *page_parts, f'index{self.out_suffix}')


def setup(app: Sphinx) -> ExtensionMetadata:
Expand Down
Loading

0 comments on commit 285908a

Please sign in to comment.