Use pathlib in further places

This commit is contained in:
Adam Turner 2025-01-04 06:09:07 +00:00
parent ad0c343d36
commit 81832e1dc7
3 changed files with 13 additions and 8 deletions

View File

@ -93,7 +93,7 @@ class ImageCollector(EnvironmentCollector):
# into a single directory) # into a single directory)
for imgpath in candidates.values(): for imgpath in candidates.values():
app.env.note_dependency(imgpath) app.env.note_dependency(imgpath)
if not os.access(os.path.join(app.srcdir, imgpath), os.R_OK): if not os.access(app.srcdir / imgpath, os.R_OK):
logger.warning( logger.warning(
__('image file not readable: %s'), __('image file not readable: %s'),
imgpath, imgpath,

View File

@ -886,7 +886,7 @@ def process_generate_options(app: Sphinx) -> None:
] ]
for entry in genfiles[:]: for entry in genfiles[:]:
if not os.path.isfile(os.path.join(app.srcdir, entry)): if not (app.srcdir / entry).is_file():
logger.warning(__('autosummary_generate: file not found: %s'), entry) logger.warning(__('autosummary_generate: file not found: %s'), entry)
genfiles.remove(entry) genfiles.remove(entry)

View File

@ -530,12 +530,15 @@ def generate_autosummary_docs(
logger.info(__('[autosummary] writing to %s'), output_dir) logger.info(__('[autosummary] writing to %s'), output_dir)
if base_path is not None: if base_path is not None:
sources = [os.path.join(base_path, filename) for filename in sources] base_path = Path(base_path)
source_paths = [base_path / filename for filename in sources]
else:
source_paths = list(map(Path, sources))
template = AutosummaryRenderer(app) template = AutosummaryRenderer(app)
# read # read
items = find_autosummary_in_files(sources) items = find_autosummary_in_files(source_paths)
# keep track of new files # keep track of new files
new_files: list[Path] = [] new_files: list[Path] = []
@ -628,7 +631,9 @@ def generate_autosummary_docs(
# -- Finding documented entries in files --------------------------------------- # -- Finding documented entries in files ---------------------------------------
def find_autosummary_in_files(filenames: list[str]) -> list[AutosummaryEntry]: def find_autosummary_in_files(
filenames: Sequence[str | os.PathLike[str]],
) -> list[AutosummaryEntry]:
"""Find out what items are documented in source/*.rst. """Find out what items are documented in source/*.rst.
See `find_autosummary_in_lines`. See `find_autosummary_in_lines`.
@ -643,7 +648,7 @@ def find_autosummary_in_files(filenames: list[str]) -> list[AutosummaryEntry]:
def find_autosummary_in_docstring( def find_autosummary_in_docstring(
name: str, name: str,
filename: str | None = None, filename: str | os.PathLike[str] | None = None,
) -> list[AutosummaryEntry]: ) -> list[AutosummaryEntry]:
"""Find out what items are documented in the given object's docstring. """Find out what items are documented in the given object's docstring.
@ -670,7 +675,7 @@ def find_autosummary_in_docstring(
def find_autosummary_in_lines( def find_autosummary_in_lines(
lines: list[str], lines: list[str],
module: str | None = None, module: str | None = None,
filename: str | None = None, filename: str | os.PathLike[str] | None = None,
) -> list[AutosummaryEntry]: ) -> list[AutosummaryEntry]:
"""Find out what items appear in autosummary:: directives in the """Find out what items appear in autosummary:: directives in the
given lines. given lines.
@ -710,7 +715,7 @@ def find_autosummary_in_lines(
if m: if m:
toctree = m.group(1) toctree = m.group(1)
if filename: if filename:
toctree = os.path.join(os.path.dirname(filename), toctree) toctree = str(Path(filename).parent / toctree)
continue continue
m = template_arg_re.match(line) m = template_arg_re.match(line)