Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pathlib #864

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions .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

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions tests/test_commonmark/test_commonmark.py
Expand Up @@ -2,17 +2,15 @@
provided by https://github.com/commonmark/CommonMark.git.
"""
import json
import os
from pathlib import Path

import pytest
from markdown_it.renderer import RendererHTML

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)


Expand Down
7 changes: 3 additions & 4 deletions tests/test_sphinx/conftest.py
Expand Up @@ -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)
Expand All @@ -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}")

Expand Down
42 changes: 18 additions & 24 deletions tests/test_sphinx/test_sphinx_builds.py
Expand Up @@ -7,18 +7,18 @@
which uses semantic HTML tags
(e.g. converting `<div class="section">` to `<section>`)
"""
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"]},
)
Expand Down Expand Up @@ -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"]},
)
Expand Down Expand Up @@ -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},
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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": ["."]},
)
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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"]},
)
Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand Down