mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use pathlib in more places
This commit is contained in:
@@ -8,6 +8,8 @@ from typing import TYPE_CHECKING
|
||||
from sphinx.transforms.post_transforms.images import ImageConverter
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import os
|
||||
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.util.typing import ExtensionMetadata
|
||||
|
||||
@@ -20,7 +22,9 @@ class MyConverter(ImageConverter):
|
||||
def is_available(self) -> bool:
|
||||
return True
|
||||
|
||||
def convert(self, _from: str, _to: str) -> bool:
|
||||
def convert(
|
||||
self, _from: str | os.PathLike[str], _to: str | os.PathLike[str]
|
||||
) -> bool:
|
||||
"""Mock converts the image from SVG to PDF."""
|
||||
shutil.copyfile(_from, _to)
|
||||
return True
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
source_dir = os.path.abspath('.')
|
||||
source_dir = str(Path.cwd().resolve())
|
||||
if source_dir not in sys.path:
|
||||
sys.path.insert(0, source_dir)
|
||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
|
||||
|
||||
@@ -4,9 +4,11 @@ from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from sphinx.util._pathlib import _StrPath
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='environment-record-dependencies')
|
||||
def test_record_dependencies_cleared(app):
|
||||
app.builder.read()
|
||||
assert app.env.dependencies['index'] == set()
|
||||
assert app.env.dependencies['api'] == {'example_module.py'}
|
||||
assert 'index' not in app.env.dependencies
|
||||
assert app.env.dependencies['api'] == {_StrPath('example_module.py')}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
@@ -144,10 +145,10 @@ def test_copy_asset_overwrite(app):
|
||||
|
||||
|
||||
def test_template_basename():
|
||||
assert _template_basename('asset.txt') is None
|
||||
assert _template_basename('asset.txt.jinja') == 'asset.txt'
|
||||
assert _template_basename('sidebar.html.jinja') == 'sidebar.html'
|
||||
assert _template_basename(Path('asset.txt')) is None
|
||||
assert _template_basename(Path('asset.txt.jinja')) == Path('asset.txt')
|
||||
assert _template_basename(Path('sidebar.html.jinja')) == Path('sidebar.html')
|
||||
|
||||
|
||||
def test_legacy_template_basename():
|
||||
assert _template_basename('asset.txt_t') == 'asset.txt'
|
||||
assert _template_basename(Path('asset.txt_t')) == Path('asset.txt')
|
||||
|
||||
Reference in New Issue
Block a user