Skip to content

FEAT: Add sphinx event hook to conf.py to remove license headers in example scripts during documentation build - #630

Merged
Samuelopez-ansys merged 1 commit into
mainfrom
feat/remove-license-headers-hook
Sep 23, 2026
Merged

Samuelopez-ansys merged 1 commit into
mainfrom
feat/remove-license-headers-hook

Conversation

@ecoussoux-ansys

Copy link
Copy Markdown
Collaborator

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 sphinx event 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 the conf.py changes 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.py file (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.

@ecoussoux-ansys ecoussoux-ansys self-assigned this Sep 16, 2026
@ecoussoux-ansys ecoussoux-ansys added the documentation Improvements or additions to documentation label Sep 16, 2026
@github-actions github-actions Bot added the enhancement New features or code improvements label Sep 16, 2026
@ecoussoux-ansys

Copy link
Copy Markdown
Collaborator Author

Judging by the artifacts generated in the CI doc build, the implementation seems to be working correctly: The high_frequency/antenna/dipole.py example does not contain the license header in the HTML documentation, and the header is also not present in the corresponding .py and .ipynb files available for download.
Note that I was unable to verify this for the generated PDF file because I cannot open it (issue reported in #631, though seemingly not related to the changes introduced here).

@Samuelopez-ansys
Samuelopez-ansys merged commit d9eac5c into main Sep 23, 2026
12 checks passed
@Samuelopez-ansys
Samuelopez-ansys deleted the feat/remove-license-headers-hook branch September 23, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New features or code improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants