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

Add nitpick-mode in sphinx-docs #491

Open
ahangsu opened this issue Aug 3, 2022 · 0 comments
Open

Add nitpick-mode in sphinx-docs #491

ahangsu opened this issue Aug 3, 2022 · 0 comments

Comments

@ahangsu
Copy link
Contributor

ahangsu commented Aug 3, 2022

Problem

Previously when we are handling issue #327 in PR #478, we attempted to use nitpicky mode in SPHINX_OPT (inside Makefile), but due to sphinx requiring all classes need to be exported, and at this moment (2022/08/03) we cannot find a way to specify a class to be unexported, we decided to open this ticket to remind us to allow -n to be activated at some point.

Solution

We used to add nitpick-ignore (regex) in docs/conf.py to ignore the warning, for warning would error by -W error on warning settings. The following is the nitpick configuration code snippet, hopefully it would be somewhat useful when we pick up the issue again.

class NitpickIgnore:
    @staticmethod
    def optional() -> list[tuple[str, str]]:
        """
        Ignores parameter declarations that specify _optional_ usage.
        """
        return [
            ("py:class", "optional"),
        ]

    @staticmethod
    def standard_library() -> list[tuple[str, str]]:
        """
        Ignores Python standard library references that Sphinx does not track.
        """
        return [
            ("py:class", "abc.ABC"),
        ]

    @staticmethod
    def unexported() -> list[tuple[str, str]]:
        """
        Ignores Pyteal internal unexported classes that Sphinx cannot track reference.
        """
        return [
            ("py:class", "pyteal.BlockField"),
            ("py:class", "pyteal.Base64Encoding"),
            ("py:class", "pyteal.VrfVerifyStandard"),
            ("py:class", "pyteal.JsonRefType"),
            ("py:class", "pyteal.OutputKwArgInfo"),
        ]


class NitpickIgnoreRegex:
    @staticmethod
    def type_vars() -> list[tuple[str, str]]:
        """
        Regex ignores generic TypeVar definitions that Sphinx does not track.
        """
        return [
            ("py.obj", r".*\.T$"),
            ("py.obj", r".*\.T[0-9]+$"),
            ("py.class", r".*\.T_co$"),
            ("py.obj", r".*\.T_co$"),
            ("py.class", r".*\.T$"),
            ("py.class", r"^T$"),
            ("py.obj", r".*\.N$"),
            ("py.class", r".*\.N$"),
            ("py.class", r"^N$"),
        ]

    @staticmethod
    def standard_library() -> list[tuple[str, str]]:
        """
        Regex ignores Python standard library references that Sphinx does not track.
        """
        return [
            ("py:class", r"contextlib\..*"),
            ("py:class", r"enum\..*"),
        ]

    @staticmethod
    def third_party() -> list[tuple[str, str]]:
        """
        Regex ignores 3rd party references that Sphinx does not track.
        """
        return [
            ("py:class", r"algosdk\.abi\..*"),
        ]


nitpick_ignore = (
    NitpickIgnore.optional()
    + NitpickIgnore.standard_library()
    + NitpickIgnore.unexported()
)

nitpick_ignore_regex = (
    NitpickIgnoreRegex.standard_library()
    + NitpickIgnoreRegex.third_party()
    + NitpickIgnoreRegex.type_vars()
)

Dependencies

Higher sphinx version that allows one to specify a way to hide a class from exporting.

Urgency

Not quite?

@ahangsu ahangsu added the new-feature-request Feature request that needs triage label Aug 3, 2022
@michaeldiamant michaeldiamant added Team Scytale and removed new-feature-request Feature request that needs triage labels Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants