Skip to content

fix: Fix duplicate printed lines when updating license header#422

Merged
klmcadams merged 5 commits intomainfrom
fix/dup-prints
Apr 24, 2026
Merged

fix: Fix duplicate printed lines when updating license header#422
klmcadams merged 5 commits intomainfrom
fix/dup-prints

Conversation

@klmcadams
Copy link
Copy Markdown
Contributor

In v0.7.1, the "Successfully changed {file}" lines are printed twice when a file is changed. This fixes that issue

@klmcadams klmcadams requested a review from a team as a code owner April 23, 2026 15:50
@github-actions github-actions Bot added the bug Something isn't working label Apr 23, 2026
Copy link
Copy Markdown
Contributor

@SMoraisAnsys SMoraisAnsys left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @klmcadams. Could you help me understand what makes a line printed twice ? I tried to follow the flow in the code base and I'm stuck not understanding how this can happpen.

Since we only call non_recursive_file_check once, which loops on pre_commit_files, the if ... else ... statements should prevent us from facing that duplicate issue, no ?

@klmcadams
Copy link
Copy Markdown
Contributor Author

Hi @SMoraisAnsys, no problem! This line add_header(copyright, license, years, file, template, commented, sys.stdout) wraps around reuse, and reuse prints whenever a header has been successfully changed. Then I have the if statement in following lines printing out the success message as well. So to get around it printing twice, I put the add_header output into a tmp file

Copy link
Copy Markdown
Contributor

@SMoraisAnsys SMoraisAnsys left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation ! Here are a few comments, LGTM otherwise

Copy link
Copy Markdown
Contributor

@SMoraisAnsys SMoraisAnsys left a comment

Choose a reason for hiding this comment

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

Forgot to add my review comments xD

Comment thread src/ansys/pre_commit_hooks/add_license_headers.py Outdated
Comment thread src/ansys/pre_commit_hooks/add_license_headers.py Outdated
klmcadams and others added 2 commits April 24, 2026 09:12
Co-authored-by: Sébastien Morais <146729917+SMoraisAnsys@users.noreply.github.com>
Co-authored-by: Sébastien Morais <146729917+SMoraisAnsys@users.noreply.github.com>
@SMoraisAnsys
Copy link
Copy Markdown
Contributor

@klmcadams You need to add the import to io, I didn't add it on the review (sry)

Comment thread src/ansys/pre_commit_hooks/add_license_headers.py Outdated
@klmcadams
Copy link
Copy Markdown
Contributor Author

@SMoraisAnsys, that's ok, no worries. I'll test it

@klmcadams
Copy link
Copy Markdown
Contributor Author

@SMoraisAnsys, it looks like all tests passed so I'm going to merge it!

@klmcadams klmcadams merged commit edcf070 into main Apr 24, 2026
35 checks passed
@klmcadams klmcadams deleted the fix/dup-prints branch April 24, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants