diff -Nru sphinx-reredirects-0.1.1+dfsg1/debian/changelog sphinx-reredirects-0.1.2+dfsg1/debian/changelog --- sphinx-reredirects-0.1.1+dfsg1/debian/changelog 2022-06-14 12:19:43.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/debian/changelog 2023-06-11 11:11:31.000000000 +0000 @@ -1,3 +1,15 @@ +sphinx-reredirects (0.1.2+dfsg1-2) unstable; urgency=medium + + * upload to unstable + + -- Georges Khaznadar Sun, 11 Jun 2023 13:11:31 +0200 + +sphinx-reredirects (0.1.2+dfsg1-1) experimental; urgency=medium + + * New upstream version 0.1.2+dfsg1 + + -- Georges Khaznadar Mon, 29 May 2023 14:30:07 +0200 + sphinx-reredirects (0.1.1+dfsg1-1) unstable; urgency=medium * New upstream version 0.1.1+dfsg1 diff -Nru sphinx-reredirects-0.1.1+dfsg1/debian/rules sphinx-reredirects-0.1.2+dfsg1/debian/rules --- sphinx-reredirects-0.1.1+dfsg1/debian/rules 2022-05-31 17:40:51.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/debian/rules 2023-05-29 13:18:05.000000000 +0000 @@ -24,7 +24,7 @@ override_dh_auto_clean: rm -f logo.png - rm -f sphinx_reredirects.egg-info/* + rm -f sphinx_reredirects.egg-info/* .eggs/* dh_auto_clean override_dh_auto_test: diff -Nru sphinx-reredirects-0.1.1+dfsg1/docs/faq.rst sphinx-reredirects-0.1.2+dfsg1/docs/faq.rst --- sphinx-reredirects-0.1.1+dfsg1/docs/faq.rst 2022-06-09 09:41:34.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/docs/faq.rst 2023-05-18 07:38:44.000000000 +0000 @@ -15,11 +15,11 @@ If you want JavaScript redirection instead, wait longer, or whatever, set ``redirect_html_template`` option. This option should points to file inside source dir (directory containing ``conf.py``). For example:: - redirect_html_template = "redirect.html.template" + redirect_html_template_file = "redirect.html.template" Actual target URI requested in configuration is available under ``${to_uri}`` placeholder. Why name "reredirects"? *********************** -Because the name "redirects" is already taken by `another `_ extension. Unfortunately, it doesn't fulfil our requirements (the most notable it doesn't support wildcards and placeholders). These were reasons why we decided to bring a new extension. \ No newline at end of file +Because the name "redirects" is already taken by `another `_ extension. Unfortunately, it doesn't fulfil our requirements (the most notable it doesn't support wildcards and placeholders). These were reasons why we decided to bring a new extension. diff -Nru sphinx-reredirects-0.1.1+dfsg1/docs/rn.rst sphinx-reredirects-0.1.2+dfsg1/docs/rn.rst --- sphinx-reredirects-0.1.1+dfsg1/docs/rn.rst 2022-06-09 09:41:34.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/docs/rn.rst 2023-05-18 07:38:44.000000000 +0000 @@ -1,6 +1,13 @@ Release notes ############# +0.1.2 (2023-05-18) +****************** + +- be explicit about parallel reads (by `Feanil Patel `__) +- docs: fix URL in README (by `Angus Hollands `__ `T `__) +- docs: fix name of redirect template option (by `Angus Hollands `__ `T `__) + 0.1.1 (2022-06-04) ****************** diff -Nru sphinx-reredirects-0.1.1+dfsg1/.gitignore sphinx-reredirects-0.1.2+dfsg1/.gitignore --- sphinx-reredirects-0.1.1+dfsg1/.gitignore 2022-06-09 09:41:34.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/.gitignore 2023-05-18 07:38:44.000000000 +0000 @@ -17,4 +17,7 @@ # Sphinx .doctrees -_build \ No newline at end of file +_build + +# Mac +.DS_Store \ No newline at end of file diff -Nru sphinx-reredirects-0.1.1+dfsg1/README.rst sphinx-reredirects-0.1.2+dfsg1/README.rst --- sphinx-reredirects-0.1.1+dfsg1/README.rst 2022-06-09 09:41:34.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/README.rst 2023-05-18 07:38:44.000000000 +0000 @@ -2,7 +2,7 @@ sphinx-reredirects ################## -.. image:: logo.png +.. image:: https://img.icons8.com/wired/64/undefined/forward-arrow--v1.png :align: right .. image:: https://gitlab.com/documatt/sphinx-reredirects/badges/master/pipeline.svg @@ -14,7 +14,7 @@ .. image:: https://img.shields.io/pypi/v/sphinx-reredirects :target: https://pypi.org/project/sphinx-reredirects/ -sphinx-reredirects is the extension for `Sphinx documentation `_ 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. +sphinx-reredirects is the extension for `Sphinx documentation `_ 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. * docs: https://documatt.gitlab.io/sphinx-reredirects * code: https://gitlab.com/documatt/sphinx-reredirects where issues and contributions are welcome @@ -25,7 +25,7 @@ About ***** -sphinx-reredirects started from the urge to manage redirects for all documents during moving our *Tech writer at work blog* to the new domain https://techwriter.documatt.com. +sphinx-reredirects started from the urge to manage redirects for all documents during moving our *Tech writer at work blog* to the new domain https://documatt.com/blog/. ***** Legal @@ -33,4 +33,4 @@ Forward Arrow icon by `Icons8 `_. -sphinx-reredirects is licensed under BSD3. \ No newline at end of file +sphinx-reredirects is licensed under BSD3. diff -Nru sphinx-reredirects-0.1.1+dfsg1/releasing.rst sphinx-reredirects-0.1.2+dfsg1/releasing.rst --- sphinx-reredirects-0.1.1+dfsg1/releasing.rst 2022-06-09 09:41:34.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/releasing.rst 2023-05-18 07:38:44.000000000 +0000 @@ -6,11 +6,11 @@ #. Choose version. - $ export VERSION=0.0.1 - #. Describe new version in ``docs/rn.rst``. -#. Create commit with message "release $VERSION". +#. Increment version in setup.py. + +#. Create commit with message "release ". #. Run local tests @@ -22,9 +22,9 @@ #. Wait for CI. -#. If they CI passed, stay on master branch, tag just released commit. +#. If they CI passed, stay on master branch, tag just released commit as "vX.Y.Z" - $ git tag -a $VERSION + $ git tag -a vX.Y.Z $ git push origin HEAD Part 2: PyPI release @@ -32,7 +32,7 @@ #. If no errors so far, build with - $ tox -e release + $ tox -e build that creates sdist and wheel in dist/. @@ -40,7 +40,7 @@ $ tox -e publish - and go to https://.... + and go to https://test.pypi.org/project/sphinx-reredirects// #. If you are happy with it, upload to PyPI. diff -Nru sphinx-reredirects-0.1.1+dfsg1/setup.py sphinx-reredirects-0.1.2+dfsg1/setup.py --- sphinx-reredirects-0.1.1+dfsg1/setup.py 2022-06-09 09:41:34.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/setup.py 2023-05-18 07:38:44.000000000 +0000 @@ -2,7 +2,7 @@ setup( name="sphinx_reredirects", - version="0.1.1", + version="0.1.2", url="https://gitlab.com/documatt/sphinx-reredirects", license="BSD3", author="Matt from Documatt", diff -Nru sphinx-reredirects-0.1.1+dfsg1/sphinx_reredirects/__init__.py sphinx-reredirects-0.1.2+dfsg1/sphinx_reredirects/__init__.py --- sphinx-reredirects-0.1.1+dfsg1/sphinx_reredirects/__init__.py 2022-06-09 09:41:34.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/sphinx_reredirects/__init__.py 2023-05-18 07:38:44.000000000 +0000 @@ -6,6 +6,7 @@ from sphinx.application import Sphinx from sphinx.util import logging +from sphinx.util.osutil import SEP OPTION_REDIRECTS = "redirects" OPTION_REDIRECTS_DEFAULT: Dict[str, str] = {} @@ -20,13 +21,14 @@ wildcard_pattern = re.compile(r"[\*\?\[\]]") -def setup(app: Sphinx) -> None: +def setup(app: Sphinx) -> Dict: """ Extension setup, called by Sphinx """ app.connect("html-collect-pages", init) app.add_config_value(OPTION_REDIRECTS, OPTION_REDIRECTS_DEFAULT, "env") app.add_config_value(OPTION_TEMPLATE_FILE, OPTION_TEMPLATE_FILE_DEFAULT, "env") + return dict(parallel_read_safe=True) def init(app: Sphinx) -> Optional[Sequence]: @@ -79,29 +81,52 @@ return to_be_redirected + def docname_out_path(self, docname: str, suffix: str) -> Sequence[str]: + """ + For a Sphinx docname (the path to a source document without suffix), + returns path to outfile that would be created by the used builder. + """ + # Return as-is, if the docname already has been passed with a suffix + if docname.endswith(suffix): + return [docname] + + # Remove any trailing slashes, except for "/"" index + if len(docname) > 1 and docname.endswith(SEP): + docname = docname.rstrip(SEP) + + # Figure out whether we have dirhtml builder + out_uri = self.app.builder.get_target_uri(docname=docname) # type: ignore + + if not out_uri.endswith(suffix): + # If dirhtml builder is used, need to append "index" + return [out_uri, "index"] + + # Otherwise, convert e.g. 'source' to 'source.html' + return [out_uri] + def create_redirects(self, to_be_redirected: Mapping[str, str]) -> None: """Create actual redirect file for each pair in passed mapping of \ docnames to targets.""" - if self.app.config.html_file_suffix is not None: - suffix = self.app.config.html_file_suffix - else: + + # Corresponds to value of `html_file_suffix`, but takes into account + # modifications done by the builder class + try: + suffix = self.app.builder.out_suffix # type: ignore + except Exception: suffix = ".html" - for doc, target in to_be_redirected.items(): - redirect_file_abs = Path(self.app.outdir).joinpath(doc).with_suffix(suffix) + for docname, target in to_be_redirected.items(): + out = self.docname_out_path(docname, suffix) + redirect_file_abs = Path(self.app.outdir).joinpath(*out).with_suffix(suffix) + redirect_file_rel = redirect_file_abs.relative_to(self.app.outdir) if redirect_file_abs.exists(): logger.info( - f"Creating redirect file '{redirect_file_rel}' " - f"pointing to '{target}' that replaces " - f"document '{doc}'." + f"Overwriting '{redirect_file_rel}' with redirect to '{target}'." ) else: - logger.info( - f"Creating redirect file '{redirect_file_rel}' " - f"pointing to '{target}'." - ) + logger.info(f"Creating redirect '{redirect_file_rel}' to '{target}'.") self._create_redirect_file(redirect_file_abs, target) diff -Nru sphinx-reredirects-0.1.1+dfsg1/tests/roots/test-dirhtml/conf.py sphinx-reredirects-0.1.2+dfsg1/tests/roots/test-dirhtml/conf.py --- sphinx-reredirects-0.1.1+dfsg1/tests/roots/test-dirhtml/conf.py 1970-01-01 00:00:00.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/tests/roots/test-dirhtml/conf.py 2023-05-18 07:38:44.000000000 +0000 @@ -0,0 +1 @@ +extensions = ["sphinx_reredirects"] diff -Nru sphinx-reredirects-0.1.1+dfsg1/tests/roots/test-dirhtml/index.rst sphinx-reredirects-0.1.2+dfsg1/tests/roots/test-dirhtml/index.rst --- sphinx-reredirects-0.1.1+dfsg1/tests/roots/test-dirhtml/index.rst 1970-01-01 00:00:00.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/tests/roots/test-dirhtml/index.rst 2023-05-18 07:38:44.000000000 +0000 @@ -0,0 +1,7 @@ +Welcome to sphinx-reredirects +============================= + +.. toctree:: + :glob: + + installing diff -Nru sphinx-reredirects-0.1.1+dfsg1/tests/roots/test-dirhtml/installing.rst sphinx-reredirects-0.1.2+dfsg1/tests/roots/test-dirhtml/installing.rst --- sphinx-reredirects-0.1.1+dfsg1/tests/roots/test-dirhtml/installing.rst 1970-01-01 00:00:00.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/tests/roots/test-dirhtml/installing.rst 2023-05-18 07:38:44.000000000 +0000 @@ -0,0 +1,4 @@ +Installing +########## + +I'm sample document. diff -Nru sphinx-reredirects-0.1.1+dfsg1/tests/test_end2end.py sphinx-reredirects-0.1.2+dfsg1/tests/test_end2end.py --- sphinx-reredirects-0.1.1+dfsg1/tests/test_end2end.py 2022-06-09 09:41:34.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/tests/test_end2end.py 2023-05-18 07:38:44.000000000 +0000 @@ -1,5 +1,6 @@ import pytest from sphinx.application import Sphinx +from sphinx.errors import ExtensionError @pytest.mark.sphinx( @@ -23,14 +24,17 @@ app.outdir / "faq/one.html" ).read_text() == '' # noqa: E501 - assert """Creating redirect file 'faq/one.html' pointing to 'https://new.com/faq/one.html' that replaces document 'faq/one'.""" # 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() == '' # noqa: E501 assert ( - """Creating redirect file 'faq/two.html' pointing to 'https://new.com/faq/two.html' that replaces document 'faq/two'.""" # noqa: E501 + """Overwriting 'faq/two.html' with redirect to 'https://new.com/faq/two.html'.""" # noqa: E501 in status ) @@ -39,7 +43,7 @@ ).read_text() == '' # noqa: E501 assert ( - """Creating redirect file 'install.html' pointing to 'go-to-install' that replaces document 'install'.""" # noqa: E501 + """Overwriting 'install.html' with redirect to 'go-to-install'.""" # noqa: E501 in status ) @@ -47,15 +51,99 @@ app.outdir / "setup.html" ).read_text() == '' # noqa: E501 - assert ( - """Creating redirect file 'setup.html' pointing to 'install.html'.""" in status - ) # noqa: E501 + assert """Creating redirect 'setup.html' to 'install.html'.""" in status assert ( app.outdir / "install/requirements.html" ).read_text() == '' # noqa: E501 assert ( - """Creating redirect file 'install/requirements.html' pointing to 'https://web.com/docs/requirements.html'.""" # noqa: E501 + """Creating redirect 'install/requirements.html' to 'https://web.com/docs/requirements.html'.""" # noqa: E501 + in status + ) + + +@pytest.mark.sphinx( + "dirhtml", + testroot="dirhtml", + freshenv=True, + confoverrides={ + "redirects": { + "index.html": "/newindex/", + "index": "http://new.com/index", + "install": "/installing/trailingslash", + "install/": "/installing/trailingslash", + "install/index": "/installing", + "install/index.html": "/installing.html", + } + }, +) +def test_dirhtml(app: Sphinx, status, warning): + app.build() + status = status.getvalue() + + assert ( + app.outdir / "index.html" + ).read_text() == '' # noqa: E501 + + assert ( + """Overwriting 'index.html' with redirect to '/newindex/'.""" # noqa: E501 + in status + ) + + assert ( + """Overwriting 'index.html' with redirect to 'http://new.com/index'.""" # noqa: E501 + in status + ) + + assert ( + app.outdir / "install/index.html" + ).read_text() == '' # noqa: E501 + + assert ( + """Creating redirect 'install/index.html' to '/installing/trailingslash'.""" # noqa: E501 + in status + ) + + assert ( + """Overwriting 'install/index.html' with redirect to '/installing/trailingslash'.""" # noqa: E501 + in status + ) + + assert ( + """Overwriting 'install/index.html' with redirect to '/installing'.""" # noqa: E501 + in status + ) + + assert ( + """Overwriting 'install/index.html' with redirect to '/installing.html'.""" # noqa: E501 in status ) + + +# Redirect sources starting with a slash are not allowed, use relative URIs +@pytest.mark.sphinx( + "html", + testroot="redirects", + freshenv=True, + confoverrides={ + "redirects": { + "/index": "http://new.com/faq/", + } + }, +) +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 any( + [ + # Newer python versions: + "exception: '/index.html' is not in the subpath of" in str(excinfo.value), + # Older python versions: + "'/index.html' does not start with" in str(excinfo.value), + ] + ) diff -Nru sphinx-reredirects-0.1.1+dfsg1/tox.ini sphinx-reredirects-0.1.2+dfsg1/tox.ini --- sphinx-reredirects-0.1.1+dfsg1/tox.ini 2022-06-09 09:41:34.000000000 +0000 +++ sphinx-reredirects-0.1.2+dfsg1/tox.ini 2023-05-18 07:38:44.000000000 +0000 @@ -71,12 +71,9 @@ skip_install = True deps = build==0.8.0 -passenv = - VERSION allowlist_externals = rm commands = - echo "Releasing version $VERSION" rm -rf dist python -m build