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

apidoc: Restore support for legacy '_t'-suffix template files #12929

Conversation

jayaddison
Copy link
Contributor

Feature or Bugfix

  • Bugfix

Purpose

Detail

  • There should always be a .jinja template suffix available within the Sphinx package itself -- but the operator can provide a --templatedir argument to prepend a named directory to the template search path.
  • Check for .jinja and then _t suffixed files in the template search path, and return the first successful result.

Relates

sphinx/ext/apidoc.py Outdated Show resolved Hide resolved
@AA-Turner
Copy link
Member

@jayaddison I think the new approach is nice, thank you.

I've pushed a commit to simplify the test by avoiding the apidoc machinery and only testing SphinxFileSystemLoader -- let me know your thoughts on this & if you think it goes too far.

In general I think the test suite is geared too much towards (slow) integration tests rather than simpler unit tests -- the proliferation of the test roots etc.

A

@AA-Turner AA-Turner changed the title [apidoc] Restore support for legacy '_t'-suffix template files apidoc: Restore support for legacy '_t'-suffix template files Oct 2, 2024
@@ -53,6 +55,28 @@ def test_simple(make_app, apidoc):
print(app._warning.getvalue())


def test_custom_templates(rootdir):
Copy link
Member

Choose a reason for hiding this comment

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

Given the new simplified test this could go into test_util/test_util_template.py instead...

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 think it's useful to have coverage here as confirmation that the reported regression has been solved; perhaps some unit testing on the template code does make sense too though.

And yep, almost every time I go to modify/add a testroot I question whether it is a good idea or not. In a way I think it's nice to have a compendium of examples of "this is how we think a given project should be displayed" - engineering-wise though, that seems unwieldly (currently?) and so I'll try to use unit testing more often.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To provide more-actionable feedback, though: yep, if we keep this test as-is, I do think it should probably be relocated to test_util_template.py (or even a test_jinja2glue.py?) since it's exercising code that is only coincidentally apidoc-related.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, missed this sorry. Feel free to update as you see fit & ping me when done!

A

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've started looking at restructuring the test.

  • ✅ I like that the templates are simplified - no need to keep the irrelevant template content.
  • ✅ Adding the assertion on the directory listing is sensible; it confirms that the inputs are as expected, and that a successful result isn't due to some other unrelated content.
  • ❌ I'm not so keen on the updated testroot - it's not really a complete Sphinx project root, and I don't think that's in the spirit of the testroots.
  • After more consideration I do think that the test -- because it is a regression fix -- should stay in the apidoc part of the test suite.

I'll try to find a middle-ground that accommodates these.

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'll try to find a middle-ground that accommodates these.

I'm not sure the changes I've pushed are ideal; some of the test framework is still a bit quirky. But I think it is cleaner than it was originally.

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

Ready to merge?

A

@jayaddison
Copy link
Contributor Author

Ready to merge?

Almost - I'd like to do a quick sense-check to confirm whether the imgmath template rendering code could interfere unexpectedly with this.

@jayaddison
Copy link
Contributor Author

Ready to merge?

Almost - I'd like to do a quick sense-check to confirm whether the imgmath template rendering code could interfere unexpectedly with this.

I think this is OK. The _t suffix lookups here should become redundant with this (#12929) changeset applied -- because the .render(...) call will find the legacy templates when attempting the initial .jinja suffix -- and the final case should be fine because the built-in preview.tex.jinja and template.tex.jinja files should always be available in the template search path (I think?).

@jayaddison
Copy link
Contributor Author

@AA-Turner I'm reasonably comfortable with these changes for merge now, but please feel free to re-question and/or adjust the test case structure; I don't mind taking some more time to try to improve it. Similarly, perhaps I'm being lazy by not adding a smaller unit-test over the jinja2glue code - so I could attempt adding that in the next day or two if that'd be worthwhile.

@AA-Turner AA-Turner merged commit 80c4b65 into sphinx-doc:master Oct 2, 2024
23 checks passed
@AA-Turner
Copy link
Member

I think fine as is; more tests are always nice but more important to fix the issue in hand.

A

@jayaddison
Copy link
Contributor Author

Thanks @AA-Turner!

@jayaddison jayaddison deleted the issue-12916/apidoc-rst-template-discovery branch October 3, 2024 09:42
@AA-Turner AA-Turner added this to the 8.1.x milestone Oct 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.rst_t apidoc template files are not found
2 participants