mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Replace uses of `canon_path()
`
This commit is contained in:
parent
b88edad731
commit
288ce2f4cd
@ -33,7 +33,7 @@ from sphinx.util.build_phase import BuildPhase
|
||||
from sphinx.util.display import progress_message, status_iterator
|
||||
from sphinx.util.docutils import sphinx_domains
|
||||
from sphinx.util.i18n import CatalogRepository, docname_to_domain
|
||||
from sphinx.util.osutil import canon_path, ensuredir, relative_uri, relpath
|
||||
from sphinx.util.osutil import ensuredir, relative_uri, relpath
|
||||
from sphinx.util.parallel import (
|
||||
ParallelTasks,
|
||||
SerialTasks,
|
||||
@ -518,7 +518,7 @@ class Builder:
|
||||
from sphinx.util.matching import _translate_pattern
|
||||
|
||||
master_doc_path = self.env.doc2path(self.config.master_doc)
|
||||
master_doc_canon = canon_path(master_doc_path)
|
||||
master_doc_canon = master_doc_path.as_posix()
|
||||
for pat in EXCLUDE_PATHS:
|
||||
if not re.match(_translate_pattern(pat), master_doc_canon):
|
||||
continue
|
||||
|
@ -7,6 +7,7 @@ import os
|
||||
import pickle
|
||||
from collections import defaultdict
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sphinx import addnodes
|
||||
@ -28,7 +29,7 @@ from sphinx.util._timestamps import _format_rfc3339_microseconds
|
||||
from sphinx.util.docutils import LoggingReporter
|
||||
from sphinx.util.i18n import CatalogRepository, docname_to_domain
|
||||
from sphinx.util.nodes import is_translatable
|
||||
from sphinx.util.osutil import _last_modified_time, _relative_path, canon_path
|
||||
from sphinx.util.osutil import _last_modified_time, _relative_path
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable, Iterable, Iterator, Mapping
|
||||
@ -415,7 +416,9 @@ class BuildEnvironment:
|
||||
"""
|
||||
return self.project.doc2path(docname, absolute=base)
|
||||
|
||||
def relfn2path(self, filename: str, docname: str | None = None) -> tuple[str, str]:
|
||||
def relfn2path(
|
||||
self, filename: str | Path, docname: str | None = None
|
||||
) -> tuple[str, str]:
|
||||
"""Return paths to a file referenced from a document, relative to
|
||||
documentation root and absolute.
|
||||
|
||||
@ -423,9 +426,9 @@ class BuildEnvironment:
|
||||
source dir, while relative filenames are relative to the dir of the
|
||||
containing document.
|
||||
"""
|
||||
filename = canon_path(filename)
|
||||
if filename.startswith('/'):
|
||||
abs_fn = (self.srcdir / filename[1:]).resolve()
|
||||
file_name = Path(filename)
|
||||
if file_name.parts[:1] in {('/',), ('\\',)}:
|
||||
abs_fn = self.srcdir.joinpath(*file_name.parts[1:]).resolve()
|
||||
else:
|
||||
if not docname:
|
||||
if self.docname:
|
||||
@ -434,10 +437,10 @@ class BuildEnvironment:
|
||||
msg = 'docname'
|
||||
raise KeyError(msg)
|
||||
doc_dir = self.doc2path(docname, base=False).parent
|
||||
abs_fn = (self.srcdir / doc_dir / filename).resolve()
|
||||
abs_fn = self.srcdir.joinpath(doc_dir, file_name).resolve()
|
||||
|
||||
rel_fn = _relative_path(abs_fn, self.srcdir)
|
||||
return canon_path(rel_fn), os.fspath(abs_fn)
|
||||
return rel_fn.as_posix(), os.fspath(abs_fn)
|
||||
|
||||
@property
|
||||
def found_docs(self) -> set[str]:
|
||||
|
@ -16,11 +16,7 @@ from sphinx.errors import SphinxError
|
||||
from sphinx.locale import __
|
||||
from sphinx.util import logging
|
||||
from sphinx.util._pathlib import _StrPath
|
||||
from sphinx.util.osutil import (
|
||||
SEP,
|
||||
_last_modified_time,
|
||||
canon_path,
|
||||
)
|
||||
from sphinx.util.osutil import SEP, _last_modified_time
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import datetime as dt
|
||||
@ -163,7 +159,7 @@ class CatalogRepository:
|
||||
@property
|
||||
def catalogs(self) -> Iterator[CatalogInfo]:
|
||||
for basedir, filename in self.pofiles:
|
||||
domain = canon_path(os.path.splitext(filename)[0])
|
||||
domain = filename.with_suffix('').as_posix()
|
||||
yield CatalogInfo(basedir, domain, self.encoding)
|
||||
|
||||
|
||||
|
@ -4,9 +4,9 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
import os.path
|
||||
from collections import defaultdict
|
||||
from contextlib import contextmanager, nullcontext
|
||||
from os.path import abspath
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from docutils import nodes
|
||||
@ -554,9 +554,9 @@ class WarningLogRecordTranslator(SphinxLogRecordTranslator):
|
||||
def get_node_location(node: Node) -> str | None:
|
||||
source, line = get_source_line(node)
|
||||
if source and line:
|
||||
return f'{abspath(source)}:{line}'
|
||||
return f'{os.path.abspath(source)}:{line}'
|
||||
if source:
|
||||
return f'{abspath(source)}:'
|
||||
return f'{os.path.abspath(source)}:'
|
||||
if line:
|
||||
return f'<unknown>:{line}'
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user