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

TEST: Copyright pre-commit #34

Merged
merged 4 commits into from
Jun 21, 2024
Merged

TEST: Copyright pre-commit #34

merged 4 commits into from
Jun 21, 2024

Conversation

cpelley
Copy link
Collaborator

@cpelley cpelley commented Jun 18, 2024

Added copyright pre-commit check.

Copyright check acts to check for the presence of and verify the validity of the copyright header of python files. Additionally, the role of the script is to automatically add this copyright notice (thus eliminating the need to deal with copyright headers yourself).

  • Verifies that non-empty python files contains some sort-of copyright header.
    • If copyright is present, checks that this copyright exactly matches the header we expect and fail if the copyright header doesn't match.
    • If copyright not present, then add it and fail.
      • Respects files including a hash bang (i.e. correctly auto adds copyright AFTER the hash bang line when present).

Issues

Note

Just to raise awareness as the first dagrunner PR under review - since this branch makes changes that impact the reference documentation, an auto reference documentation build commit will be pushed accordingly thanks to the dagrunner action workflow.

image

@cpelley cpelley added the test label Jun 18, 2024
@cpelley cpelley self-assigned this Jun 18, 2024
@cpelley
Copy link
Collaborator Author

cpelley commented Jun 18, 2024

Ping @s-boardman - I think you might be interested in this.

@s-boardman
Copy link

Ping @s-boardman - I think you might be interested in this.

That's absurdly clever Carwyn!

copyright_check Outdated
echo "Adding missing Copyright to '${filepath}'"
tmp_file="${filepath}.tmp"
rm -f ${tmp_file} 2&> /dev/null
touch ${tmp_file}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can replace the "rm" and "touch" lines with a single line:

echo -n > ${tmp_file}

copyright_check Outdated
echo -e ${copyright_header} >> ${tmp_file}
tail -n +2 ${filepath} >> ${tmp_file}
else
echo -e ${copyright_header} >> ${tmp_file}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you change this to > rather than >> you can do away with removing the ${tmp_file} above because then the if and the else will both create the file afresh anyway.

Copy link
Contributor

@mo-robert-purvis mo-robert-purvis left a comment

Choose a reason for hiding this comment

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

Just some comments on the bash, but looks good.

@cpelley
Copy link
Collaborator Author

cpelley commented Jun 20, 2024

Thanks @mo-robert-purvis

Tidied up based on feedback.

Additionally improved by adding:

  • trap to ensure that temporary files are removed at the end no matter what happens within the script.
  • Commandline help.

Copy link
Contributor

@mo-robert-purvis mo-robert-purvis left a comment

Choose a reason for hiding this comment

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

Looks good

@cpelley cpelley merged commit 21c1475 into main Jun 21, 2024
2 checks passed
@cpelley cpelley deleted the COPYRIGHT_PRECOMMIT branch June 21, 2024 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants