Skip to content

Conversation

@SamRemis
Copy link
Contributor

@SamRemis SamRemis commented Mar 10, 2025

This PR adds generation of sphinx docs. There are a number of changes that are necessary to accomplish this:

  1. Converting the HTML provided by service teams to RST for sphinx (AwsDocConverter.java)
  2. Updating the linewrapping to respect RST formatting (PythonWriter.java)
  3. Add the core sphinx files to be generated during the initial repo setup (SetupGenerator.java)
  4. Add events during client generation for when we are generating a symbol that needs to be documented (many files- most of the *Generator.java files as well as the *Section.java files)
  5. Add more necessary boiler plate code- requirements, references to the new interceptors, etc.

This is still in draft mode pending the following action items:

  1. Add tests

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@SamRemis SamRemis force-pushed the convert-docs-to-rst branch from a0c24c0 to 0036e2e Compare March 17, 2025 16:58
Comment on lines 186 to 189
// If no space found, force wrap at maxLineLength
wrapAt = maxLineLength;
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work for things like links and code that may stretch beyond the limit. Is this going to create rendering issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does create some; with the current docs there is only one link I can find with this issue.

What is the ideal behavior here? Should we allow these docs to exceed the max line length?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's a link, probably. That only affects rendering in the code. There's a question of if we even want the links in the docstrings, but I don't think we need to solve that now.

@SamRemis SamRemis changed the title Convert HTML to RST in doc models Add sphinx doc generation Mar 17, 2025
@SamRemis SamRemis force-pushed the convert-docs-to-rst branch from 764264e to f1b9ced Compare March 18, 2025 15:08
@SamRemis SamRemis force-pushed the convert-docs-to-rst branch from f1b9ced to 1a36552 Compare March 18, 2025 18:19
@SamRemis SamRemis marked this pull request as ready for review March 18, 2025 19:02
@SamRemis SamRemis requested a review from a team as a code owner March 18, 2025 19:02
dependencies {
implementation(project(":core"))
implementation(libs.smithy.aws.traits)
implementation("org.jsoup:jsoup:1.19.1")
Copy link
Contributor

Choose a reason for hiding this comment

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

The version should go in here. Docs on how that works are here.

}

private static class RstNodeVisitor implements NodeVisitor {
private final StringBuilder sb = new StringBuilder();
Copy link
Contributor

Choose a reason for hiding this comment

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

It'll probably be better to use a SimpleCodeWriter for this. There's a few major benefits. For starters, it will make indentation management easier. Right now any list values that happen to have a newline will break the indentation. Same for anything in any sort of block.

A secondary benefit is that you can then create a named section that can be pushed in the opening tag and popped in the closing tag. That'll let you intercept those sections later down the line if you need to do customizations. It'll also let you support ordered lists since you can put context into the writer to say which list element you're on. Since context is scoped to sections, you won't have to worry about overriding some parent.

Given time constraints we have right now, this can be a fast follow.

DocumentationTrait docTrait = shape.getTrait(DocumentationTrait.class).get();
String html = docTrait.getValue();
String rst = convertHtmlToRst(html);
DocumentationTrait newDocTrait = new DocumentationTrait(rst);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather run this in PythonWrtier where we write documentation. The format of the documentation trait is commonmark, so putting RST in there isn't really correct.

Speaking of commonmark, you need to account for that. The easiest way is to just render the whole thing to HTML like this. commonmark can contain HTML (and most of the docs we get from AWS are just HTML) but there's more to it.

return String.format("%s%n%s%n%n", title, "=".repeat(title.length()));
}

private static final class OperationGenerationInterceptor
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the advantage of doing this over just autoclassing the client itself?

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't need to be AWS specific, nor does the rst doc file generator

/**
* Write the files required for sphinx doc generation
*/
private static void writeDocsSkeleton(
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to do this now, but lets add a todo to make this configurable. We should be able to turn off generating all the sphinx setup files and select a theme.

import sys
sys.path.insert(0, os.path.abspath('..'))
project = 'AWS SDK for Python'
Copy link
Contributor

Choose a reason for hiding this comment

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

This should reference the service title, falling back to the shape name. You could preprocess the model in the AWS side to set the title trait to be based on the SDK ID if you like.

SamRemis and others added 2 commits March 19, 2025 18:08
…en/generators/SetupGenerator.java

Co-authored-by: Nate Prewitt <nate.prewitt@gmail.com>
JordonPhillips
JordonPhillips previously approved these changes Mar 19, 2025
JordonPhillips
JordonPhillips previously approved these changes Mar 20, 2025
Copy link
Contributor

@JordonPhillips JordonPhillips left a comment

Choose a reason for hiding this comment

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

Once this and that bug are fixed I'm approving

@SamRemis SamRemis merged commit ff78144 into smithy-lang:develop Mar 20, 2025
2 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