diff --git a/.github/workflows/docutils_setup.py b/.github/workflows/docutils_setup.py
index 9d745222..b05aa803 100755
--- a/.github/workflows/docutils_setup.py
+++ b/.github/workflows/docutils_setup.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
"""Script to convert package setup to myst-docutils."""
import sys
+from pathlib import Path
import tomlkit
@@ -42,15 +43,12 @@ def modify_readme(content: str) -> str:
if __name__ == "__main__":
- project_path = sys.argv[1]
- readme_path = sys.argv[2]
- with open(project_path) as f:
- content = f.read()
+ project_path = Path(sys.argv[1])
+ content = project_path.read_text()
content = modify_toml(content)
- with open(project_path, "w") as f:
- f.write(content)
- with open(readme_path) as f:
- content = f.read()
+ project_path.write_text(content)
+
+ readme_path = Path(sys.argv[2])
+ content = readme_path.read_text()
content = modify_readme(content)
- with open(readme_path, "w") as f:
- f.write(content)
+ readme_path.write_text(content)
diff --git a/pyproject.toml b/pyproject.toml
index 2993b24f..ad948b1a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -102,7 +102,7 @@ exclude = [
]
[tool.ruff]
-extend-select = ["B0", "C4", "I", "ICN", "ISC", "N", "RUF", "SIM", "UP"]
+extend-select = ["B0", "C4", "I", "ICN", "ISC", "N", "PTH", "RUF", "SIM", "UP"]
extend-ignore = ["ISC001", "RUF005", "RUF012"]
[tool.mypy]
diff --git a/tests/test_commonmark/test_commonmark.py b/tests/test_commonmark/test_commonmark.py
index 3cee1eb8..b69118d5 100644
--- a/tests/test_commonmark/test_commonmark.py
+++ b/tests/test_commonmark/test_commonmark.py
@@ -2,7 +2,7 @@
provided by https://github.com/commonmark/CommonMark.git.
"""
import json
-import os
+from pathlib import Path
import pytest
from markdown_it.renderer import RendererHTML
@@ -10,9 +10,7 @@
from myst_parser.config.main import MdParserConfig
from myst_parser.parsers.mdit import create_md_parser
-with open(
- os.path.join(os.path.dirname(__file__), "commonmark.json"), encoding="utf8"
-) as fin:
+with (Path(__file__).parent / "commonmark.json").open(encoding="utf8") as fin:
tests = json.load(fin)
diff --git a/tests/test_sphinx/conftest.py b/tests/test_sphinx/conftest.py
index 4a244872..2e233a29 100644
--- a/tests/test_sphinx/conftest.py
+++ b/tests/test_sphinx/conftest.py
@@ -31,18 +31,17 @@ def test_basic(app, status, warning, get_sphinx_app_output):
- docutilsconf=None
"""
-import os
import pathlib
import shutil
+from pathlib import Path
import pytest
from bs4 import BeautifulSoup
from docutils import nodes
-from sphinx.testing.path import path
from myst_parser._compat import findall
-SOURCE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "sourcedirs"))
+SOURCE_DIR = (Path(__file__).parent / "sourcedirs").resolve()
@pytest.fixture(scope="session", autouse=True)
@@ -66,7 +65,7 @@ def read(
regress_ext=".html",
replace=None,
):
- outpath = path(os.path.join(str(app.srcdir), "_build", buildername, filename))
+ outpath = Path(app.srcdir) / "_build" / buildername / filename
if not outpath.exists():
raise OSError(f"no output file exists: {outpath}")
diff --git a/tests/test_sphinx/test_sphinx_builds.py b/tests/test_sphinx/test_sphinx_builds.py
index 57039d8f..447bbc11 100644
--- a/tests/test_sphinx/test_sphinx_builds.py
+++ b/tests/test_sphinx/test_sphinx_builds.py
@@ -7,18 +7,18 @@
which uses semantic HTML tags
(e.g. converting `
` to ``)
"""
-import os
import re
+from pathlib import Path
import pytest
from docutils import VersionInfo, __version_info__
-SOURCE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "sourcedirs"))
+SOURCE_DIR = (Path(__file__).parent / "sourcedirs").resolve()
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "basic"),
+ srcdir=SOURCE_DIR / "basic",
freshenv=True,
confoverrides={"myst_enable_extensions": ["dollarmath"]},
)
@@ -83,7 +83,7 @@ def test_basic(
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "references"),
+ srcdir=SOURCE_DIR / "references",
freshenv=True,
confoverrides={"myst_enable_extensions": ["dollarmath"]},
)
@@ -121,7 +121,7 @@ def test_references(
@pytest.mark.sphinx(
buildername="singlehtml",
- srcdir=os.path.join(SOURCE_DIR, "references_singlehtml"),
+ srcdir=SOURCE_DIR / "references_singlehtml",
freshenv=True,
confoverrides={"nitpicky": True},
)
@@ -171,7 +171,7 @@ def test_references_singlehtml(
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "heading_slug_func"),
+ srcdir=SOURCE_DIR / "heading_slug_func",
freshenv=True,
)
def test_heading_slug_func(
@@ -202,7 +202,7 @@ def test_heading_slug_func(
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "extended_syntaxes"),
+ srcdir=SOURCE_DIR / "extended_syntaxes",
freshenv=True,
)
def test_extended_syntaxes(
@@ -237,9 +237,7 @@ def test_extended_syntaxes(
)
-@pytest.mark.sphinx(
- buildername="html", srcdir=os.path.join(SOURCE_DIR, "includes"), freshenv=True
-)
+@pytest.mark.sphinx(buildername="html", srcdir=SOURCE_DIR / "includes", freshenv=True)
def test_includes(
app,
status,
@@ -285,7 +283,7 @@ def test_includes(
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "include_from_rst"),
+ srcdir=SOURCE_DIR / "include_from_rst",
freshenv=True,
)
def test_include_from_rst(
@@ -313,9 +311,7 @@ def test_include_from_rst(
__version_info__ < VersionInfo(0, 19, 0, "final", 0, True),
reason="Footnote HTML changed in docutils 0.19",
)
-@pytest.mark.sphinx(
- buildername="html", srcdir=os.path.join(SOURCE_DIR, "footnotes"), freshenv=True
-)
+@pytest.mark.sphinx(buildername="html", srcdir=SOURCE_DIR / "footnotes", freshenv=True)
def test_footnotes(
app,
status,
@@ -346,7 +342,7 @@ def test_footnotes(
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "commonmark_only"),
+ srcdir=SOURCE_DIR / "commonmark_only",
freshenv=True,
)
def test_commonmark_only(
@@ -375,7 +371,7 @@ def test_commonmark_only(
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "substitutions"),
+ srcdir=SOURCE_DIR / "substitutions",
freshenv=True,
)
def test_substitutions(
@@ -402,9 +398,7 @@ def test_substitutions(
get_sphinx_app_output(app, filename="index.html", regress_html=True)
-@pytest.mark.sphinx(
- buildername="gettext", srcdir=os.path.join(SOURCE_DIR, "gettext"), freshenv=True
-)
+@pytest.mark.sphinx(buildername="gettext", srcdir=SOURCE_DIR / "gettext", freshenv=True)
def test_gettext(
app,
status,
@@ -427,7 +421,7 @@ def test_gettext(
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "gettext"),
+ srcdir=SOURCE_DIR / "gettext",
freshenv=True,
confoverrides={"language": "fr", "gettext_compact": False, "locale_dirs": ["."]},
)
@@ -471,7 +465,7 @@ def test_gettext_html(
@pytest.mark.sphinx(
buildername="gettext",
- srcdir=os.path.join(SOURCE_DIR, "gettext"),
+ srcdir=SOURCE_DIR / "gettext",
freshenv=True,
confoverrides={
"gettext_additional_targets": [
@@ -505,7 +499,7 @@ def test_gettext_additional_targets(
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "mathjax"),
+ srcdir=SOURCE_DIR / "mathjax",
freshenv=True,
confoverrides={"myst_enable_extensions": ["dollarmath"]},
)
@@ -526,7 +520,7 @@ def test_mathjax_warning(
@pytest.mark.sphinx(
buildername="html",
- srcdir=os.path.join(SOURCE_DIR, "fieldlist"),
+ srcdir=SOURCE_DIR / "fieldlist",
freshenv=True,
)
def test_fieldlist_extension(
@@ -573,7 +567,7 @@ def test_fieldlist_extension(
@pytest.mark.sphinx(
buildername="texinfo",
- srcdir=os.path.join(SOURCE_DIR, "texinfo"),
+ srcdir=SOURCE_DIR / "texinfo",
freshenv=True,
)
def test_texinfo(app, status, warning):