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

Make API generation more maintainable and readable #223

Closed
Eric-Arellano opened this issue Oct 20, 2023 · 1 comment
Closed

Make API generation more maintainable and readable #223

Eric-Arellano opened this issue Oct 20, 2023 · 1 comment

Comments

@Eric-Arellano
Copy link
Collaborator

Eric-Arellano commented Oct 20, 2023

Right now, it can be somewhat brittle when e.g. Sphinx changes how HTML is generated, which caused the issues in #67. (Although, Axel did a great job writing tests!)

I think probably this looks like adding more testing where possible.

Originally, I thought we should consider switching from Sphinx to https://vemel.github.io/handsdown/. But we decided this is not a good option, including because cross-references are extremely important for the API docs.

--

Update Jan 3: @frankharkins, @arnaucasau, and I agreed this issue is high priority before we add more complexity via #522, #454, and #479.

Rough plan:

  1. Improve test coverage:
    • Add more tests for API generation script #581 adds some
    • Should determine if mergeClassMembers.ts, updateLinks.ts, and generateToc.ts still need better testing. For example, I don't think generateToc.ts is teesting all the differente edge cases adequately
    • We have a lot of non-trivial logic in updateApiDocs.ts - what can we move to lib so that we can test it?
  2. Refactor sphinxHtmlToMarkdown.ts, our most complex file. Split out the huge function into smaller helper functions & write more focused unit tests for those. Right now our unit tests are a bit hard to read and update since they have to mock so much.
  3. Refactor convertHtmlToMarkdown, which right now does a lot. Is there a better level of abstraction?
@Eric-Arellano Eric-Arellano added this to the Qiskit 1.0 milestone Oct 20, 2023
@Eric-Arellano Eric-Arellano changed the title Make API generation more resilient Audit if we can make API generation even more resilient Dec 6, 2023
@Eric-Arellano Eric-Arellano changed the title Audit if we can make API generation even more resilient Make API generation more maintainable and readable Jan 3, 2024
github-merge-queue bot pushed a commit that referenced this issue Jan 5, 2024
Part of #223.

First small refactor of the `sphinxHtmlToMarkdown.ts` script. This PR
divides the `sphinxHtmlToMarkdown` function into different helper
functions, reducing its length and allowing the possibility of adding
tests for different parts of the code.

Changes in this PR:

- Renamed the `$page` variable to `$` to reduce the noise introduced by
the number of calls we had and to follow the
[Cheerio](https://cheerio.js.org/docs/basics/loading#load) convention.
- Moved the code to find all the images into a helper function.
- Grouped similar transformations to the HTML (done previous to its
conversion to markdown) into a helper function called `preprocess`.
- Moved the conversion from HTML to markdown process to a different
function to simplify the `sphinxHtmlToMarkdown` function (divide more in
the future).
- Refactored the recursive search of methods, adding early returns and
merging some parts.
- Moved the unified plugin to the `unifiedParser.ts` file in order to
abstract the transformation, which can now be called from other files.
That script can group together all the unified plugins, such as the link
checker, the mergeClassMembers.ts, and this one.

In this PR, the code has been copied almost identically to how it was
before, except for some little adjustments, like in the unified plugin
where we now use an anonymous function and have the two visitors merged.

More changes will be introduced in a follow-up.

---------

Co-authored-by: Eric Arellano <[email protected]>
github-merge-queue bot pushed a commit that referenced this issue Jan 5, 2024
Part of #223. 

One way to improve the maintainability of our API generation is to test
more. It gives us confidence we aren't breaking things and it makes it
more obvious how the function behaves.

This PR also makes some light refactoring like renaming things to be
more clear.

---------

Co-authored-by: Arnau Casau <[email protected]>
Co-authored-by: Arnau Casau <[email protected]>
github-actions bot pushed a commit that referenced this issue Jan 9, 2024
Part of #223.

First small refactor of the `sphinxHtmlToMarkdown.ts` script. This PR
divides the `sphinxHtmlToMarkdown` function into different helper
functions, reducing its length and allowing the possibility of adding
tests for different parts of the code.

Changes in this PR:

- Renamed the `$page` variable to `$` to reduce the noise introduced by
the number of calls we had and to follow the
[Cheerio](https://cheerio.js.org/docs/basics/loading#load) convention.
- Moved the code to find all the images into a helper function.
- Grouped similar transformations to the HTML (done previous to its
conversion to markdown) into a helper function called `preprocess`.
- Moved the conversion from HTML to markdown process to a different
function to simplify the `sphinxHtmlToMarkdown` function (divide more in
the future).
- Refactored the recursive search of methods, adding early returns and
merging some parts.
- Moved the unified plugin to the `unifiedParser.ts` file in order to
abstract the transformation, which can now be called from other files.
That script can group together all the unified plugins, such as the link
checker, the mergeClassMembers.ts, and this one.

In this PR, the code has been copied almost identically to how it was
before, except for some little adjustments, like in the unified plugin
where we now use an anonymous function and have the two visitors merged.

More changes will be introduced in a follow-up.

---------

Co-authored-by: Eric Arellano <[email protected]>
github-actions bot pushed a commit that referenced this issue Jan 9, 2024
Part of #223. 

One way to improve the maintainability of our API generation is to test
more. It gives us confidence we aren't breaking things and it makes it
more obvious how the function behaves.

This PR also makes some light refactoring like renaming things to be
more clear.

---------

Co-authored-by: Arnau Casau <[email protected]>
Co-authored-by: Arnau Casau <[email protected]>
github-merge-queue bot pushed a commit that referenced this issue Jan 9, 2024
Part of #223. There are
still improvements we can make like better testing.

This PR tries to avoid making code changes and only moves the code to
helper functions.
@javabster javabster moved this to In Progress in Docs Planning Jan 22, 2024
@Eric-Arellano Eric-Arellano removed this from the 24-02-13 Qiskit 1.0 milestone Jan 26, 2024
@Eric-Arellano
Copy link
Collaborator Author

We've made a lot of progress on this. The remaining work can be tracked by #845 and #715.

@github-project-automation github-project-automation bot moved this from In Progress to Done in Docs Planning Feb 19, 2024
frankharkins pushed a commit to frankharkins/documentation that referenced this issue Jul 22, 2024
Part of Qiskit#223.

First small refactor of the `sphinxHtmlToMarkdown.ts` script. This PR
divides the `sphinxHtmlToMarkdown` function into different helper
functions, reducing its length and allowing the possibility of adding
tests for different parts of the code.

Changes in this PR:

- Renamed the `$page` variable to `$` to reduce the noise introduced by
the number of calls we had and to follow the
[Cheerio](https://cheerio.js.org/docs/basics/loading#load) convention.
- Moved the code to find all the images into a helper function.
- Grouped similar transformations to the HTML (done previous to its
conversion to markdown) into a helper function called `preprocess`.
- Moved the conversion from HTML to markdown process to a different
function to simplify the `sphinxHtmlToMarkdown` function (divide more in
the future).
- Refactored the recursive search of methods, adding early returns and
merging some parts.
- Moved the unified plugin to the `unifiedParser.ts` file in order to
abstract the transformation, which can now be called from other files.
That script can group together all the unified plugins, such as the link
checker, the mergeClassMembers.ts, and this one.

In this PR, the code has been copied almost identically to how it was
before, except for some little adjustments, like in the unified plugin
where we now use an anonymous function and have the two visitors merged.

More changes will be introduced in a follow-up.

---------

Co-authored-by: Eric Arellano <[email protected]>
frankharkins pushed a commit to frankharkins/documentation that referenced this issue Jul 22, 2024
Part of Qiskit#223. 

One way to improve the maintainability of our API generation is to test
more. It gives us confidence we aren't breaking things and it makes it
more obvious how the function behaves.

This PR also makes some light refactoring like renaming things to be
more clear.

---------

Co-authored-by: Arnau Casau <[email protected]>
Co-authored-by: Arnau Casau <[email protected]>
frankharkins pushed a commit to frankharkins/documentation that referenced this issue Jul 22, 2024
Part of Qiskit#223. There are
still improvements we can make like better testing.

This PR tries to avoid making code changes and only moves the code to
helper functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants