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 a directives for general purpose documentation in downstream proj… #57

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

swrichards
Copy link
Contributor

@swrichards swrichards commented Jan 27, 2025

@swrichards swrichards force-pushed the general-usage-sphinx-directives branch 12 times, most recently from d01c07e to e52e817 Compare January 28, 2025 15:19
@swrichards swrichards marked this pull request as ready for review January 28, 2025 15:36
@swrichards
Copy link
Contributor Author

@stevenbal @Coperh the tests don't yet pass but mainly because I mocking out a function in CI is rather tricky due to the convoluted import sequence, trying to fix that now but it won't change the core of the PR, so I am tagging you now for feedback.

@swrichards swrichards force-pushed the general-usage-sphinx-directives branch 3 times, most recently from bb37337 to ab74c09 Compare January 28, 2025 16:07
@Coperh
Copy link

Coperh commented Jan 29, 2025

One thing is that I don't think it includes the templates in the release or at least when I install from github, they are missing. I do get the usage directive though

@swrichards
Copy link
Contributor Author

One thing is that I don't think it includes the templates in the release or at least when I install from github, they are missing. I do get the usage directive though

This is a good point. I was using it locally as an editable install which did copy over the whole thing, but for setuptools it'll probably require a nudge to include the templates in the package. (In the meantime, it is testable with pip install -e, or should be)

@swrichards swrichards force-pushed the general-usage-sphinx-directives branch 6 times, most recently from 40f9e8f to b6a7ec9 Compare January 29, 2025 12:11
Copy link

@Coperh Coperh left a comment

Choose a reason for hiding this comment

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

I think generally it looks good.

I would like the ability to change the template so I can add custom intro paragraph and remove the autoclass since that is not useful for CI/CD users

Comment on lines 17 to 18
_usage_template = Template((_TEMPLATES_PATH / "config_doc.rst").read_text())
_step_template = Template((_TEMPLATES_PATH / "config_step.rst").read_text())
Copy link

Choose a reason for hiding this comment

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

Would be nice to override these templates. Not sure if I can now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Coperh I see a few options:

  1. As you say, making the templates overridable. This has the drawback that Sphinx is really quite picky in building up the RST nodes (e.g. if you were to add headings or other directives, it might fail).
  2. Add some arguments to this directive, for instance: to include/exclude the usage info, and to add a "style" enum for the headings (which could either be the verbose_title, the autodac tag to the step class as now, or a combination of both
  3. Add some additional directives which adds more composability: so the usage text, TOC, and step sections are each their own directives which could be used separately to mix-and-match, with this directive being effectively a bundle of these separate directives.

I am inclined to do that refactoring in a subsequent PR, unless there's an obvious path to 1. we can add here.

docs/config_docs.rst Outdated Show resolved Hide resolved
@Coperh
Copy link

Coperh commented Jan 29, 2025

OR perhaps I could just override the _TEMPLATES_PATH?

@swrichards swrichards force-pushed the general-usage-sphinx-directives branch 4 times, most recently from dd90b6b to d49dd6c Compare January 30, 2025 09:51
@swrichards swrichards marked this pull request as draft January 30, 2025 11:56
@swrichards swrichards force-pushed the general-usage-sphinx-directives branch 3 times, most recently from 238f5e2 to 720f23e Compare January 30, 2025 15:36
@swrichards swrichards marked this pull request as ready for review January 30, 2025 15:39
@swrichards
Copy link
Contributor Author

@stevenbal @Coperh I have added a few options to customize what sections are included/excluded (See the docs and test examples).

Copy link
Contributor

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

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

Looks good overall, some minor remarks

docs/config_docs.rst Outdated Show resolved Hide resolved
docs/config_docs.rst Show resolved Hide resolved
docs/config_docs.rst Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
for line in step.description.splitlines():
rst.append(line, "<dynamic>")

rst.append(f".. setup-config-example:: {step.module_path}", "<dynamic>")
Copy link
Contributor

Choose a reason for hiding this comment

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

@swrichards something else I ran into just now: it might be useful to add anchors to the steps, that way you can still reference specific steps from other pages

.. _setup_configuration_Baz:

.. setup-config-example:: foo.bar.Baz

not entirely sure what the name of the reference should be though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have now rewritten this so the step sections are always RST sections, which mean they will always have an anchor id, which I've changed to ref-step-{full_step_module_path} for easier linking.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the only way to cross-reference is by adding an explicit reference like .. _ref-config-step-...: unfortunately 😬 (https://www.sphinx-doc.org/en/master/usage/referencing.html#cross-referencing-arbitrary-locations)

I tried linking to this another way, the only thing that seems to work is spelling out the path of the file + the anchor (https://github.com/open-zaak/open-notificaties/pull/228/files#diff-056134d467e07b8255b1205455315b00fd959de8fe75ce378dc3b0698587c7a8L82), but that reference isn't validated when building the docs, so that link would break if the path/anchor change and you wouldn't be notified about it by a failing build

@Coperh
Copy link

Coperh commented Feb 3, 2025

Screenshot from 2025-02-03 10-41-40

"""
    Config for ``ObjectType`` model from objecttypes-api
"""

Also does accept rst formatting which is nice

Copy link

@Coperh Coperh left a comment

Choose a reason for hiding this comment

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

Tests seem fine and the output looks correct to me.

docs/config_docs.rst Show resolved Hide resolved
@swrichards swrichards force-pushed the general-usage-sphinx-directives branch from d992dea to 1e76460 Compare February 4, 2025 15:34
Copy link
Contributor

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

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

Only remaining comment about references to steps, looks good otherwise

for line in step.description.splitlines():
rst.append(line, "<dynamic>")

rst.append(f".. setup-config-example:: {step.module_path}", "<dynamic>")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the only way to cross-reference is by adding an explicit reference like .. _ref-config-step-...: unfortunately 😬 (https://www.sphinx-doc.org/en/master/usage/referencing.html#cross-referencing-arbitrary-locations)

I tried linking to this another way, the only thing that seems to work is spelling out the path of the file + the anchor (https://github.com/open-zaak/open-notificaties/pull/228/files#diff-056134d467e07b8255b1205455315b00fd959de8fe75ce378dc3b0698587c7a8L82), but that reference isn't validated when building the docs, so that link would break if the path/anchor change and you wouldn't be notified about it by a failing build

@@ -0,0 +1,133 @@
<div class="body" role="main">
Copy link
Contributor

Choose a reason for hiding this comment

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

for my understanding: how are these generated and how do you verify if they are correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The HTML is read from the Sphinx output (from disk), I then use bs4 to extract the body (to avoid having to compare ephemeral and potentially dynamic values in the head/footer) and passed through approvaltests for verification. The latter gives better diffs and makes it easier to re-record the dumps if they change.

Whether they're correct: by visual inspection basically (as you would with say a Storybook snapshot).

@swrichards swrichards force-pushed the general-usage-sphinx-directives branch from b64fbc9 to 71fc278 Compare February 6, 2025 14:32
@stevenbal stevenbal self-requested a review February 6, 2025 14:34
@swrichards swrichards force-pushed the general-usage-sphinx-directives branch from 2dbea6a to 46e87c2 Compare February 6, 2025 14:36
@swrichards swrichards merged commit 79cc5ba into main Feb 6, 2025
18 checks passed
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.

3 participants