Skip to content

Commit

Permalink
ref: format with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
liborjelinek committed Jun 21, 2024
1 parent 4a27152 commit e6a0b53
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
38 changes: 18 additions & 20 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,50 @@

# -- Project information -----------------------------------------------------

project = 'sphinx-reredirects'
copyright = f'{date.today().year}, Documatt'
author = 'Documatt.com'
project = "sphinx-reredirects"
copyright = f"{date.today().year}, Documatt"
author = "Documatt.com"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx_sitemap"
]
extensions = ["sphinx_sitemap"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

rst_epilog = f'''
rst_epilog = f"""
.. |project| replace:: {project}
'''
"""

highlight_language = 'none'
highlight_language = "none"

# -- Options for HTML output -------------------------------------------------

html_baseurl = 'https://documatt.com/sphinx-reredirects/'
html_extra_path = ['robots.txt']
html_baseurl = "https://documatt.com/sphinx-reredirects/"
html_extra_path = ["robots.txt"]

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_logo = 'logo.png'
html_logo = "logo.png"

html_theme = 'sphinx_documatt_theme'
html_theme = "sphinx_documatt_theme"
html_theme_options = {
'motto': f'{project} is the extension for <a href="https://www.sphinx-doc.org/">Sphinx documentation</a> projects that handles redirects for moved pages. It generates HTML pages with meta refresh redirects to the new page location to prevent 404 errors if you rename or move your documents.',
'header_text': project,
'header_logo_style': 'height: 3em',
'footer_logo_style': 'height: 3em',
"motto": f'{project} is the extension for <a href="https://www.sphinx-doc.org/">Sphinx documentation</a> projects that handles redirects for moved pages. It generates HTML pages with meta refresh redirects to the new page location to prevent 404 errors if you rename or move your documents.',
"header_text": project,
"header_logo_style": "height: 3em",
"footer_logo_style": "height: 3em",
}

# --- Options for sphinx-sitemap ---------------------------------------------

# No lang code in generated URLs
sitemap_url_scheme = "{link}"
sitemap_url_scheme = "{link}"
4 changes: 3 additions & 1 deletion sphinx_reredirects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
OPTION_TEMPLATE_FILE = "redirect_html_template_file"
OPTION_TEMPLATE_FILE_DEFAULT = None

REDIRECT_FILE_DEFAULT_TEMPLATE = '<html><head><meta http-equiv="refresh" content="0; url=${to_uri}"></head></html>' # noqa: E501
REDIRECT_FILE_DEFAULT_TEMPLATE = (
'<html><head><meta http-equiv="refresh" content="0; url=${to_uri}"></head></html>' # noqa: E501
)

logger = logging.getLogger(__name__)

Expand Down
39 changes: 22 additions & 17 deletions tests/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,46 @@ def test_ext(app: Sphinx, status, warning):
status = status.getvalue()

assert (
app.outdir / "faq/one.html"
).read_text() == '<html><head><meta http-equiv="refresh" content="0; url=https://new.com/faq/one.html"></head></html>' # noqa: E501
(app.outdir / "faq/one.html").read_text()
== '<html><head><meta http-equiv="refresh" content="0; url=https://new.com/faq/one.html"></head></html>'
) # noqa: E501

assert (
"""Overwriting 'faq/one.html' with redirect to 'https://new.com/faq/one.html'.""" # noqa: E501
in status
)

assert (
app.outdir / "faq/two.html"
).read_text() == '<html><head><meta http-equiv="refresh" content="0; url=https://new.com/faq/two.html"></head></html>' # noqa: E501
(app.outdir / "faq/two.html").read_text()
== '<html><head><meta http-equiv="refresh" content="0; url=https://new.com/faq/two.html"></head></html>'
) # noqa: E501

assert (
"""Overwriting 'faq/two.html' with redirect to 'https://new.com/faq/two.html'.""" # noqa: E501
in status
)

assert (
app.outdir / "install.html"
).read_text() == '<html><head><meta http-equiv="refresh" content="0; url=go-to-install"></head></html>' # noqa: E501
(app.outdir / "install.html").read_text()
== '<html><head><meta http-equiv="refresh" content="0; url=go-to-install"></head></html>'
) # noqa: E501

assert (
"""Overwriting 'install.html' with redirect to 'go-to-install'.""" # noqa: E501
in status
)

assert (
app.outdir / "setup.html"
).read_text() == '<html><head><meta http-equiv="refresh" content="0; url=install.html"></head></html>' # noqa: E501
(app.outdir / "setup.html").read_text()
== '<html><head><meta http-equiv="refresh" content="0; url=install.html"></head></html>'
) # noqa: E501

assert """Creating redirect 'setup.html' to 'install.html'.""" in status

assert (
app.outdir / "install/requirements.html"
).read_text() == '<html><head><meta http-equiv="refresh" content="0; url=https://web.com/docs/requirements.html"></head></html>' # noqa: E501
(app.outdir / "install/requirements.html").read_text()
== '<html><head><meta http-equiv="refresh" content="0; url=https://web.com/docs/requirements.html"></head></html>'
) # noqa: E501

assert (
"""Creating redirect 'install/requirements.html' to 'https://web.com/docs/requirements.html'.""" # noqa: E501
Expand Down Expand Up @@ -83,8 +88,9 @@ def test_dirhtml(app: Sphinx, status, warning):
status = status.getvalue()

assert (
app.outdir / "index.html"
).read_text() == '<html><head><meta http-equiv="refresh" content="0; url=http://new.com/index"></head></html>' # noqa: E501
(app.outdir / "index.html").read_text()
== '<html><head><meta http-equiv="refresh" content="0; url=http://new.com/index"></head></html>'
) # noqa: E501

assert (
"""Overwriting 'index.html' with redirect to '/newindex/'.""" # noqa: E501
Expand All @@ -97,8 +103,9 @@ def test_dirhtml(app: Sphinx, status, warning):
)

assert (
app.outdir / "install/index.html"
).read_text() == '<html><head><meta http-equiv="refresh" content="0; url=/installing.html"></head></html>' # noqa: E501
(app.outdir / "install/index.html").read_text()
== '<html><head><meta http-equiv="refresh" content="0; url=/installing.html"></head></html>'
) # noqa: E501

assert (
"""Creating redirect 'install/index.html' to '/installing/trailingslash'.""" # noqa: E501
Expand Down Expand Up @@ -136,9 +143,7 @@ def test_invalid_uri(app: Sphinx, status, warning):
with pytest.raises(ExtensionError) as excinfo:
app.build()

assert "for event 'html-collect-pages' threw an exception" in str(
excinfo.value
) # noqa: E501
assert "for event 'html-collect-pages' threw an exception" in str(excinfo.value) # noqa: E501
assert any(
[
# Newer python versions:
Expand Down

0 comments on commit e6a0b53

Please sign in to comment.