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.display import progress_message, status_iterator
|
||||||
from sphinx.util.docutils import sphinx_domains
|
from sphinx.util.docutils import sphinx_domains
|
||||||
from sphinx.util.i18n import CatalogRepository, docname_to_domain
|
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 (
|
from sphinx.util.parallel import (
|
||||||
ParallelTasks,
|
ParallelTasks,
|
||||||
SerialTasks,
|
SerialTasks,
|
||||||
@ -518,7 +518,7 @@ class Builder:
|
|||||||
from sphinx.util.matching import _translate_pattern
|
from sphinx.util.matching import _translate_pattern
|
||||||
|
|
||||||
master_doc_path = self.env.doc2path(self.config.master_doc)
|
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:
|
for pat in EXCLUDE_PATHS:
|
||||||
if not re.match(_translate_pattern(pat), master_doc_canon):
|
if not re.match(_translate_pattern(pat), master_doc_canon):
|
||||||
continue
|
continue
|
||||||
|
@ -7,6 +7,7 @@ import os
|
|||||||
import pickle
|
import pickle
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from sphinx import addnodes
|
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.docutils import LoggingReporter
|
||||||
from sphinx.util.i18n import CatalogRepository, docname_to_domain
|
from sphinx.util.i18n import CatalogRepository, docname_to_domain
|
||||||
from sphinx.util.nodes import is_translatable
|
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:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Callable, Iterable, Iterator, Mapping
|
from collections.abc import Callable, Iterable, Iterator, Mapping
|
||||||
@ -415,7 +416,9 @@ class BuildEnvironment:
|
|||||||
"""
|
"""
|
||||||
return self.project.doc2path(docname, absolute=base)
|
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
|
"""Return paths to a file referenced from a document, relative to
|
||||||
documentation root and absolute.
|
documentation root and absolute.
|
||||||
|
|
||||||
@ -423,9 +426,9 @@ class BuildEnvironment:
|
|||||||
source dir, while relative filenames are relative to the dir of the
|
source dir, while relative filenames are relative to the dir of the
|
||||||
containing document.
|
containing document.
|
||||||
"""
|
"""
|
||||||
filename = canon_path(filename)
|
file_name = Path(filename)
|
||||||
if filename.startswith('/'):
|
if file_name.parts[:1] in {('/',), ('\\',)}:
|
||||||
abs_fn = (self.srcdir / filename[1:]).resolve()
|
abs_fn = self.srcdir.joinpath(*file_name.parts[1:]).resolve()
|
||||||
else:
|
else:
|
||||||
if not docname:
|
if not docname:
|
||||||
if self.docname:
|
if self.docname:
|
||||||
@ -434,10 +437,10 @@ class BuildEnvironment:
|
|||||||
msg = 'docname'
|
msg = 'docname'
|
||||||
raise KeyError(msg)
|
raise KeyError(msg)
|
||||||
doc_dir = self.doc2path(docname, base=False).parent
|
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)
|
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
|
@property
|
||||||
def found_docs(self) -> set[str]:
|
def found_docs(self) -> set[str]:
|
||||||
|
@ -16,11 +16,7 @@ from sphinx.errors import SphinxError
|
|||||||
from sphinx.locale import __
|
from sphinx.locale import __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
from sphinx.util._pathlib import _StrPath
|
from sphinx.util._pathlib import _StrPath
|
||||||
from sphinx.util.osutil import (
|
from sphinx.util.osutil import SEP, _last_modified_time
|
||||||
SEP,
|
|
||||||
_last_modified_time,
|
|
||||||
canon_path,
|
|
||||||
)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
@ -163,7 +159,7 @@ class CatalogRepository:
|
|||||||
@property
|
@property
|
||||||
def catalogs(self) -> Iterator[CatalogInfo]:
|
def catalogs(self) -> Iterator[CatalogInfo]:
|
||||||
for basedir, filename in self.pofiles:
|
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)
|
yield CatalogInfo(basedir, domain, self.encoding)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
import os.path
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from contextlib import contextmanager, nullcontext
|
from contextlib import contextmanager, nullcontext
|
||||||
from os.path import abspath
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
@ -554,9 +554,9 @@ class WarningLogRecordTranslator(SphinxLogRecordTranslator):
|
|||||||
def get_node_location(node: Node) -> str | None:
|
def get_node_location(node: Node) -> str | None:
|
||||||
source, line = get_source_line(node)
|
source, line = get_source_line(node)
|
||||||
if source and line:
|
if source and line:
|
||||||
return f'{abspath(source)}:{line}'
|
return f'{os.path.abspath(source)}:{line}'
|
||||||
if source:
|
if source:
|
||||||
return f'{abspath(source)}:'
|
return f'{os.path.abspath(source)}:'
|
||||||
if line:
|
if line:
|
||||||
return f'<unknown>:{line}'
|
return f'<unknown>:{line}'
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user