FEAT: Add sphinx event hook to conf.py to remove license headers in example scripts during documentation build - #630
Merged
Conversation
…xample scripts during doc build
ecoussoux-ansys
requested review from
Devin-Crawford,
SMoraisAnsys,
Samuelopez-ansys,
eblanco-ansys,
gmalinve and
maxcapodi78
as code owners
September 16, 2026 15:17
Collaborator
Author
|
Judging by the artifacts generated in the CI doc build, the implementation seems to be working correctly: The |
Samuelopez-ansys
approved these changes
Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is a follow-up to #623.
The final goal of this work is to add license headers to the example scripts in this repository. Following discussions in the referenced PR, it was determined that while these headers (currently missing) are needed, they should not appear in the online documentation of the examples.
To achieve this, this PR introduces a
sphinxevent hook (remove_license_headers()) designed to strip the license header lines from the example scripts.This hook runs at the start of the documentation build process (before the example scripts are converted into notebooks) and is registered as a
"config-inited"hook. The license header has been added to one example (high_frequency/antenna/dipole.py) to allow testing of theconf.pychanges within the CI pipeline.Additionally, another hook named
restore_license_headers()is introduced, registered as a"build-finished"hook. This hook restores the license headers to the example scripts after the HTML and PDF builds are complete. This prevents unwanted diffs in the project files following the documentation build and ensures that both builds (HTML/PDF) operate on the original files when run coupled.Finally, minor reformatting changes have also been made to the
conf.pyfile (in particular for imports).Once the solution introduced here has been discussed, modified if necessary, and accepted, the license headers can be added to all example scripts in a subsequent PR.