diff options
author | Gunes Bayir <gunes.bayir@arm.com> | 2023-07-01 22:55:42 +0100 |
---|---|---|
committer | Gunes Bayir <gunes.bayir@arm.com> | 2023-08-08 14:23:35 +0000 |
commit | 66b4a6a8ca1ee55e5b7f05bae2543cf99fe22d6d (patch) | |
tree | a11e009e6fc742df0fd4551fd7c545325210a07d /scripts/ensure_single_eol.py | |
parent | f77b969d3375f412ff236586d2b6eb2297c6b96d (diff) | |
download | ComputeLibrary-66b4a6a8ca1ee55e5b7f05bae2543cf99fe22d6d.tar.gz |
Setup pre-commit and include code formatting scripts
This patch
- includes our code formatting scripts used in our precommit pipeline
- sets up pre-commit framework to help contributors validate their patches
This has several benefits:
- our repository becomes more inclusive to external contributions
- we can use several hooks available online efficiently, w/o implementing our own
- it speeds up our development flow
and, it is completely optional.
The pre-commit configuration includes running the following:
- our code formatting scripts
- CMake and Bazel build file generation scripts
- hooks that check trailing whitespace, end of files, committed large files etc.
The number of checks can easily be extended using pre-commit framework.
Change-Id: I06bf1259715579d321f89820726a8301504c36d9
Signed-off-by: Gunes Bayir <gunes.bayir@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10064
Reviewed-by: Jakub Sujak <jakub.sujak@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Benchmark: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'scripts/ensure_single_eol.py')
-rwxr-xr-x | scripts/ensure_single_eol.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/ensure_single_eol.py b/scripts/ensure_single_eol.py new file mode 100755 index 0000000000..0eb105e091 --- /dev/null +++ b/scripts/ensure_single_eol.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2023 Arm Limited. +# +# SPDX-License-Identifier: MIT +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +""" +This script ensures a file ends with exactly one end-of-line character +""" + +import argparse +import pathlib as pl +import os + + +def main(args): + f_p = pl.Path(args.file) + with open(f_p, "r") as f: + lines = f.read() + lines = lines.rstrip(os.linesep) + lines += os.linesep + with open(f_p, "w") as f: + f.write(lines) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("file") + args = parser.parse_args() + main(args) |