Skip to content

add doc:links and docs:links:check #427

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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

Jannis-Mittenzwei
Copy link
Contributor

closes #409

@Jannis-Mittenzwei Jannis-Mittenzwei self-assigned this May 16, 2025
@ArBridgeman ArBridgeman temporarily deployed to manual-approval May 26, 2025 11:04 — with GitHub Actions Inactive
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)
B Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@@ -24,6 +24,7 @@ At this time, PTB currently does not support setting up SonarQube for a **privat

## ✨ Features
* #451: Added nox task to execute pysonar & added Sonar to the CI
* #409: Doc link & checks
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* #409: Doc link & checks
* #409: Added nox tasks for `doc:links` and `docs:links:check`

@@ -24,6 +24,7 @@ At this time, PTB currently does not support setting up SonarQube for a **privat

## ✨ Features
Copy link
Collaborator

@ArBridgeman ArBridgeman Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. At the top of the docs/changes/unreleased.md, please add to the ## Summary section. Below is some suggested text.
  2. Please modify the suggested to explain why you selected certain values & what they do.
  3. Please, above the Sonar part, add ### Sonar.

Links in Documentation

This version of the PTB adds nox tasks to check links present in our documentation:

  • docs:link - List all the links within the documentation
  • docs:links:check - Checks whether all links in the documentation are accessible

docs:links:check is run in the CI checks.yml. If this step fails in the CI, please check the output & manually resolve the issues. There might be some cases where you need to update your doc/conf.py with specific values for the allowed options for the Linkcheck Builder.

We recommend the following values be added

linkcheck_rate_limit_timeout = 40
linkcheck_timeout = 5
linkcheck_delay = 20
linkcheck_retries = 2
linkcheck_anchors = False
linkcheck_ignore: list[str] = []
linkcheck_allowed_redirects = {
    # All HTTP redirections from the source URI to
    # the canonical URI will be treated as "working".
    r"https://github\.com/.*": r"https://github\.com/login*"
}

@@ -4,7 +4,7 @@ sphinx
sphinx-multiversion
+++++++++++++++++++

The `sphinx-multiversion` extension is a modified copy of `Holzhaus/sphinx-multiversion <https://github.com/Holzhaus/sphinx-multiversion>`_. This copy was taken from version :code:`0.24.0`.
The `sphinx-multiversion` extension is a modified copy of `Holzhaus/sphinx-multiversion <https://github.com/sphinx-contrib/multiversion>`_. This copy was taken from version :code:`0.24.0`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repository has moved; thus, the reference text should be updated to reflect that.

Suggested change
The `sphinx-multiversion` extension is a modified copy of `Holzhaus/sphinx-multiversion <https://github.com/sphinx-contrib/multiversion>`_. This copy was taken from version :code:`0.24.0`.
The `sphinx-multiversion` extension is a modified copy of `sphinx-contrib/multiversion <https://github.com/sphinx-contrib/multiversion>`_. This copy was taken from version :code:`0.24.0`.

@@ -78,3 +78,15 @@
"github_url": "https://github.com/exasol/python-toolbox",
"accent_color": "grass",
}
# -- Configure link checking behavior ----------------------------------------
linkcheck_rate_limit_timeout = 40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update project-template/{{cookiecutter.repo_name}}/doc/conf.py with values that you think are worthwhile to have.

def docs_links_check(session: Session) -> None:
"""Checks whether all links in the documentation are accessible."""
parser = argparse.ArgumentParser(
prog="nox -s release:prepare",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prog="nox -s release:prepare",
prog="nox -s docs:links:check",

"""Checks whether all links in the documentation are accessible."""
parser = argparse.ArgumentParser(
prog="nox -s release:prepare",
usage="nox -s release:prepare -- [-h] [-o |--output]",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
usage="nox -s release:prepare -- [-h] [-o |--output]",
usage="nox -s docs:link:check -- [-h] [-o |--output]",


import nox
import requests # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused import

Suggested change
import requests # type: ignore

Container,
Iterable,
)
from itertools import repeat
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused import

Suggested change
from itertools import repeat

import webbrowser
from collections.abc import (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container & Iterable are unused imports. Please remove.

Suggested change
from collections.abc import (

import argparse
import json
import os
import re
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused import

Suggested change
import re

@@ -1,11 +1,27 @@
from __future__ import annotations

import argparse
import json
import os
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused import

Suggested change
import os

tmpdir,
],
)
print(sp.returncode)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove print here?

Suggested change
print(sp.returncode)

@@ -88,6 +100,82 @@ def clean_docs(_session: Session) -> None:
shutil.rmtree(docs_folder)


@nox.session(name="docs:links", python=False)
def docs_list_links(session: Session) -> None:
Copy link
Collaborator

@ArBridgeman ArBridgeman Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to create an integration test and/or unit test(s) similar to https://github.com/exasol/python-toolbox/blob/main/test/unit/util/dependencies/poetry_dependencies_test.py.

For the integration test:

  • Within a tmp directory, make a simple set up with 1 to 3 links & test that what you capture on the capsys matches what you would expect.

For unit test(s):

It is true that we should not test everything that sphinx-build linkcheck does, but as we are building a small part of code (line 124-136) around it, it is best to ensure that the given certain input that we get an expected output. In the example test code (poetry_dependencies_test.py.) above, this was necessitated as when we moved from poetry 1.x to poetry 2.x the format of the pyproject.toml changed, but we had only hard-coded tests that represented a format that no longer existed. An analogous situation could be when we updated sphinx-build that we find the the JSONL format has changed or that the conf.py variable names have changed.

Copy link
Collaborator

@ArBridgeman ArBridgeman Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(In the example with poetry, there was no CI indication before that the code was failing. I just happened to see that the output in the GitHub summary wasn't correct. 😬 . Better to do light testing & catch it earlier on. Tests are relatively free. Developers finding issues isn't as much; we cost more per hour 😉 )

formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"-o", "--output", type=Path, help="path to output file", default=None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"-o", "--output", type=Path, help="path to output file", default=None
"-o", "--output", type=Path, help="path to copy the output json file", default=None

shutil.copyfile(result_json, dst)
print(f"file generated at path: {result_json.resolve()}")
result_txt = tmpdir / "output.txt"
if sp.returncode == 1 or result_txt.read_text() != "":
Copy link
Collaborator

@ArBridgeman ArBridgeman Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like this
-> separate errors visually with a character like -
-> use a walrus operator in some way so that not doing read_text() twice. If you use a walrus operator then, it should be the first item in the or condition, as otherwise, it may not be set later.

Suggested change
if sp.returncode == 1 or result_txt.read_text() != "":
if errors:=result_txt.read_text().splitlines() or sp.returncode == 1:
escape_red = "\033[31m"
print(escape_rot + "errors:")
print('\n'.join(f"- {item}" for item in errors))
session.error(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ Check and report broken hyperlinks
2 participants