From 77b156c4c33fc794af200cec8ed6edff89269e0b Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Thu, 4 Apr 2019 15:50:51 +0900 Subject: [PATCH 01/11] git ignore python-related files --- .gitignore | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 66140b1af..5d25fadb3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +### https://raw.github.com/github/gitignore/f908e51bcf38ae5ede449c55189a7b25d8c507cc/Go.gitignore + # Binaries for programs and plugins *.exe *.exe~ @@ -11,15 +13,134 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out + +### https://raw.github.com/github/gitignore/f908e51bcf38ae5ede449c55189a7b25d8c507cc/Python.gitignore + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + + +### Project-specific config + # Log files *.log -# Coverage files -*.cov +# Coverage file +profile.cov # Misc .envrc -dist/ tmp/ -/config.yaml -AUTHORS From 39db76616ad9887af6e4f3fa0e39627bbcbcf266 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Thu, 4 Apr 2019 16:07:37 +0900 Subject: [PATCH 02/11] Remove redundant "(C)" in modification license terms --- pkg/queue/priority_queue_k8s.go | 2 +- pkg/scheduler/generic_scheduler_k8s.go | 2 +- pkg/util/util_k8s.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/queue/priority_queue_k8s.go b/pkg/queue/priority_queue_k8s.go index cec946267..db140ffd3 100644 --- a/pkg/queue/priority_queue_k8s.go +++ b/pkg/queue/priority_queue_k8s.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Modifications copyright (C) 2019 Preferred Networks, Inc. +// Modifications copyright 2019 Preferred Networks, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/scheduler/generic_scheduler_k8s.go b/pkg/scheduler/generic_scheduler_k8s.go index 507c44155..e30269278 100644 --- a/pkg/scheduler/generic_scheduler_k8s.go +++ b/pkg/scheduler/generic_scheduler_k8s.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Modifications copyright (C) 2019 Preferred Networks, Inc. +// Modifications copyright 2019 Preferred Networks, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/util/util_k8s.go b/pkg/util/util_k8s.go index a2bee91df..d97c2ffac 100644 --- a/pkg/util/util_k8s.go +++ b/pkg/util/util_k8s.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Modifications copyright (C) 2019 Preferred Networks, Inc. +// Modifications copyright 2019 Preferred Networks, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From aed1622918b31ab7ca5fc8b1e7cf04acc4e81d34 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Thu, 4 Apr 2019 16:26:07 +0900 Subject: [PATCH 03/11] Rework license scripts --- scripts/add_license.py | 60 +++++++++++++++++++++++++++++++ scripts/add_license.sh | 76 --------------------------------------- scripts/check_license.py | 59 ++++++++++++++++++++++++++++++ scripts/check_license.sh | 36 ------------------- scripts/license_header.py | 54 ++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 112 deletions(-) create mode 100644 scripts/add_license.py delete mode 100755 scripts/add_license.sh create mode 100644 scripts/check_license.py delete mode 100755 scripts/check_license.sh create mode 100644 scripts/license_header.py diff --git a/scripts/add_license.py b/scripts/add_license.py new file mode 100644 index 000000000..69b851869 --- /dev/null +++ b/scripts/add_license.py @@ -0,0 +1,60 @@ +# Copyright 2019 Preferred Networks, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Adds a license header to files. +""" + +from pathlib import Path + +from license_header import license_header, has_license_header + +PROJECT_ROOT = Path(__file__).resolve().parents[1] + + +def main(): + add(PROJECT_ROOT.glob("*[!vendor]/**/*_k8s.go"), + license_header("//", True)) + add([p for p in PROJECT_ROOT.glob("*[!vendor]/**/*.go") + if p.name[-7:] != "_k8s.go"], license_header("//")) + add(PROJECT_ROOT.glob("*[!vendor]/**/*.py"), license_header("#")) + add(PROJECT_ROOT.glob("*[!vendor]/**/*.sh"), license_header("#")) + + +def add(paths, license_header): + for p in paths: + if has_license_header(p, license_header): + continue + + print("Add license header to file", p.relative_to(PROJECT_ROOT)) + + with open(p) as f: + content = f.readlines() + + if content[0][:2] == "#!": # reserve shebangs + content_new = [content[0], "\n", license_header, "\n"] + + # put a newline after the license header only if necessary + if content[1] != "\n": + content_new += ["\n"] + content_new += content[1:] + else: + content_new = [license_header, "\n", "\n"] + content + + with open(p, "w") as f: + f.write(''.join(content_new)) + + +if __name__ == "__main__": + exit(main()) diff --git a/scripts/add_license.sh b/scripts/add_license.sh deleted file mode 100755 index 99f0b4b44..000000000 --- a/scripts/add_license.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -# Copyright 2019 Preferred Networks, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Adds lincense header to files. -# FIXME: Reserve shebang - -LICENSE_LINE='Licensed under the Apache License, Version 2.0 (the "License");' - -LICENSE_HEADER=( - 'Copyright 2019 Preferred Networks, Inc.' - '' - 'Licensed under the Apache License, Version 2.0 (the "License");' - 'you may not use this file except in compliance with the License.' - 'You may obtain a copy of the License at' - '' - ' http://www.apache.org/licenses/LICENSE-2.0' - '' - 'Unless required by applicable law or agreed to in writing, software' - 'distributed under the License is distributed on an "AS IS" BASIS,' - 'WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.' - 'See the License for the specific language governing permissions and' - 'limitations under the License.' -) - -cd $(git rev-parse --show-toplevel) - -function err() { - echo -e "\033[031m$1\033[0m" - exit $2 -} - -files=$(git ls-files | grep -v vendor | grep -e ".go" -e ".sh" -e ".py") -for f in ${files[@]}; do - if ! grep "$LICENSE_LINE" $f --quiet; then - echo "Add license header to $f" - - b=$(basename $f) - comment="" - if [[ $b == *.go ]]; then - comment="//" - elif [[ $b == *.sh ]]; then - comment="#" - elif [[ $b == *.py ]]; then - comment="#" - else - err "Unkown file extension" 1 - fi - - tmpfile=$(mktemp) - for l in "${LICENSE_HEADER[@]}"; do - if [ -z "$l" ]; then - echo "${comment}" >> $tmpfile - else - echo "${comment} ${l}" >> $tmpfile - fi - done - echo >> $tmpfile - - tmp2=$(mktemp) - cat $tmpfile $f > $tmp2 - mv $tmp2 $f - fi -done diff --git a/scripts/check_license.py b/scripts/check_license.py new file mode 100644 index 000000000..b90750189 --- /dev/null +++ b/scripts/check_license.py @@ -0,0 +1,59 @@ +# Copyright 2019 Preferred Networks, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Checks whether files have an appropriate license header. +""" + +from pathlib import Path + +from license_header import license_header, has_license_header + +PROJECT_ROOT = Path(__file__).resolve().parents[1] + + +def main(): + ok = True + + ok &= check( + PROJECT_ROOT.glob("*[!vendor]/**/*_k8s.go"), + license_header("//", modification=True)) + ok &= check( + [p for p in PROJECT_ROOT.glob( + "*[!vendor]/**/*.go") if p.name[-7:] != "_k8s.go"], + license_header("//")) + ok &= check(PROJECT_ROOT.glob("*[!vendor]/**/*.py"), license_header("#")) + ok &= check(PROJECT_ROOT.glob("*[!vendor]/**/*.sh"), license_header("#")) + + return 0 if ok else 1 + + +def check(paths, license_header): + ok = True + + for p in paths: + if not p.exists(): + print("File", p.relative_to(PROJECT_ROOT), "does not exist") + ok = False + continue + + if not has_license_header(p, license_header): + print(p.relative_to(PROJECT_ROOT), "is missing a license header") + ok = False + + return ok + + +if __name__ == "__main__": + exit(main()) diff --git a/scripts/check_license.sh b/scripts/check_license.sh deleted file mode 100755 index 636c6fec6..000000000 --- a/scripts/check_license.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# Copyright 2019 Preferred Networks, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Checks whether files have an appropriate license header. - -LICENSE_LINE='Licensed under the Apache License, Version 2.0 (the "License");' - -cd $(git rev-parse --show-toplevel) - -files=$(git ls-files | grep -v vendor | grep -e ".go" -e ".sh" -e ".py") - -status=0 -for f in ${files[@]}; do - if ! grep "$LICENSE_LINE" $f --quiet; then - if [ $status -eq 0 ]; then - echo "The following files are missing license headers." - fi - echo "- $f" - status=1 - fi -done - -exit $status diff --git a/scripts/license_header.py b/scripts/license_header.py new file mode 100644 index 000000000..735f53fb8 --- /dev/null +++ b/scripts/license_header.py @@ -0,0 +1,54 @@ +# Copyright 2019 Preferred Networks, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +LICENSE_HEADER = [ + 'Copyright 2019 Preferred Networks, Inc.', + '', + 'Licensed under the Apache License, Version 2.0 (the "License");', + 'you may not use this file except in compliance with the License.', + 'You may obtain a copy of the License at', + '', + ' http://www.apache.org/licenses/LICENSE-2.0', + '', + 'Unless required by applicable law or agreed to in writing, software', + 'distributed under the License is distributed on an "AS IS" BASIS,', + 'WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.', + 'See the License for the specific language governing permissions and', + 'limitations under the License.', +] + +LICENSE_HEADER_MODIFICATION = [ + 'Modifications copyright 2019 Preferred Networks, Inc.', +] + LICENSE_HEADER[1:] + + +def license_header(comment, modification=False): + """ + Returns a license header. + Each line is preceded by `comment` string, and a single space if the line is not empty. + """ + + license = LICENSE_HEADER_MODIFICATION if modification else LICENSE_HEADER + return '\n'.join( + "{} {}".format(comment, l) if len(l) > 0 else comment + for l in license + ) + + +def has_license_header(path, license_header): + """ + Returns whether the file at `path` contains `license_header` string. + """ + + return license_header in open(path).read() From 91753d842dc6a3b58072a109c35a5b3cb1373c0a Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Thu, 4 Apr 2019 16:28:03 +0900 Subject: [PATCH 04/11] Fix .travis.yaml to call check_license.py (commented out) --- .travis.yml | 2 +- Makefile | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7124070af..69108f59c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ script: - make lint test coverage - goveralls -coverprofile=profile.cov -service=travis-ci - make e2e -# - make check-license +# - python3 ./scripts/check_license.py diff --git a/Makefile b/Makefile index c4b472925..3eb7fdabc 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,3 @@ e2e: coverage: go test -covermode=count -coverprofile=profile.cov $(shell go list ./... | grep -v /vendor/) go tool cover -func=profile.cov - -.PHONY: check-license -check-license: - ./scripts/check_license.sh From b128a808c2eabbb5a4fd391a60d1886fd7d39d87 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Thu, 4 Apr 2019 17:01:25 +0900 Subject: [PATCH 05/11] Add license header to e2e.go --- test/e2e/e2e.go | 14 ++++++++++++++ test/e2e/e2e_test.go | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/e2e/e2e.go b/test/e2e/e2e.go index df8caf702..580f07950 100644 --- a/test/e2e/e2e.go +++ b/test/e2e/e2e.go @@ -1 +1,15 @@ +// Copyright 2019 Preferred Networks, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package e2e diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 606d17dfe..5ae892b97 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -1,5 +1,3 @@ -// +build !no_e2e - // Copyright 2019 Preferred Networks, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +build !no_e2e + package e2e import ( From 63cce0d7cceffabb6ed406a4832018c31283af83 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Thu, 4 Apr 2019 17:18:40 +0900 Subject: [PATCH 06/11] Minor fix on add_license.py --- scripts/add_license.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/add_license.py b/scripts/add_license.py index 69b851869..4e24f5dc9 100644 --- a/scripts/add_license.py +++ b/scripts/add_license.py @@ -57,4 +57,4 @@ def add(paths, license_header): if __name__ == "__main__": - exit(main()) + main() From e58e84d8b8f75b627f3827cb3fb8120d4d7b624a Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Thu, 4 Apr 2019 19:09:40 +0900 Subject: [PATCH 07/11] Move license scripts to scripts/license directory --- .travis.yml | 2 +- scripts/{add_license.py => license/add.py} | 0 scripts/{check_license.py => license/check.py} | 0 scripts/{ => license}/license_header.py | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename scripts/{add_license.py => license/add.py} (100%) rename scripts/{check_license.py => license/check.py} (100%) rename scripts/{ => license}/license_header.py (100%) diff --git a/.travis.yml b/.travis.yml index 69108f59c..c8d970bb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ script: - make lint test coverage - goveralls -coverprofile=profile.cov -service=travis-ci - make e2e -# - python3 ./scripts/check_license.py +# - python3 ./scripts/license/check.py diff --git a/scripts/add_license.py b/scripts/license/add.py similarity index 100% rename from scripts/add_license.py rename to scripts/license/add.py diff --git a/scripts/check_license.py b/scripts/license/check.py similarity index 100% rename from scripts/check_license.py rename to scripts/license/check.py diff --git a/scripts/license_header.py b/scripts/license/license_header.py similarity index 100% rename from scripts/license_header.py rename to scripts/license/license_header.py From 700e9a097cc38b0f3d0f62e5f52464f383b48a21 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Thu, 4 Apr 2019 21:39:36 +0900 Subject: [PATCH 08/11] Fix license scripts --- scripts/license/add.py | 8 +++++--- scripts/license/check.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/license/add.py b/scripts/license/add.py index 4e24f5dc9..affdeb03b 100644 --- a/scripts/license/add.py +++ b/scripts/license/add.py @@ -17,10 +17,12 @@ """ from pathlib import Path +import subprocess from license_header import license_header, has_license_header -PROJECT_ROOT = Path(__file__).resolve().parents[1] +PROJECT_ROOT = Path(subprocess.check_output( + "git rev-parse --show-toplevel".split()).strip().decode("utf-8")) def main(): @@ -39,7 +41,7 @@ def add(paths, license_header): print("Add license header to file", p.relative_to(PROJECT_ROOT)) - with open(p) as f: + with p.open() as f: content = f.readlines() if content[0][:2] == "#!": # reserve shebangs @@ -52,7 +54,7 @@ def add(paths, license_header): else: content_new = [license_header, "\n", "\n"] + content - with open(p, "w") as f: + with p.open("w") as f: f.write(''.join(content_new)) diff --git a/scripts/license/check.py b/scripts/license/check.py index b90750189..23d473264 100644 --- a/scripts/license/check.py +++ b/scripts/license/check.py @@ -17,10 +17,12 @@ """ from pathlib import Path +import subprocess from license_header import license_header, has_license_header -PROJECT_ROOT = Path(__file__).resolve().parents[1] +PROJECT_ROOT = Path(subprocess.check_output( + "git rev-parse --show-toplevel".split()).strip().decode("utf-8")) def main(): From 222397c26f9f3f6b027ed80c90b2dbca3bf7f143 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Thu, 4 Apr 2019 21:52:48 +0900 Subject: [PATCH 09/11] Add verbose option to license scripts --- .travis.yml | 2 +- scripts/license/add.py | 23 ++++++++++++++++------- scripts/license/check.py | 29 ++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index c8d970bb1..1f9dd2cb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ script: - make lint test coverage - goveralls -coverprofile=profile.cov -service=travis-ci - make e2e -# - python3 ./scripts/license/check.py +# - python3 ./scripts/license/check.py -v diff --git a/scripts/license/add.py b/scripts/license/add.py index affdeb03b..da9e24ccd 100644 --- a/scripts/license/add.py +++ b/scripts/license/add.py @@ -25,17 +25,20 @@ "git rev-parse --show-toplevel".split()).strip().decode("utf-8")) -def main(): +def main(verbose=False): add(PROJECT_ROOT.glob("*[!vendor]/**/*_k8s.go"), - license_header("//", True)) + license_header("//", True), verbose) add([p for p in PROJECT_ROOT.glob("*[!vendor]/**/*.go") - if p.name[-7:] != "_k8s.go"], license_header("//")) - add(PROJECT_ROOT.glob("*[!vendor]/**/*.py"), license_header("#")) - add(PROJECT_ROOT.glob("*[!vendor]/**/*.sh"), license_header("#")) + if p.name[-7:] != "_k8s.go"], license_header("//"), verbose) + add(PROJECT_ROOT.glob("*[!vendor]/**/*.py"), license_header("#"), verbose) + add(PROJECT_ROOT.glob("*[!vendor]/**/*.sh"), license_header("#"), verbose) -def add(paths, license_header): +def add(paths, license_header, verbose): for p in paths: + if verbose: + print("Checking", p.relative_to(PROJECT_ROOT)) + if has_license_header(p, license_header): continue @@ -59,4 +62,10 @@ def add(paths, license_header): if __name__ == "__main__": - main() + from argparse import ArgumentParser + + parser = ArgumentParser() + parser.add_argument("-v", "--verbose", action="store_true") + + args = parser.parse_args() + main(args.verbose) diff --git a/scripts/license/check.py b/scripts/license/check.py index 23d473264..24deadb59 100644 --- a/scripts/license/check.py +++ b/scripts/license/check.py @@ -25,26 +25,31 @@ "git rev-parse --show-toplevel".split()).strip().decode("utf-8")) -def main(): +def main(verbose=False): ok = True ok &= check( - PROJECT_ROOT.glob("*[!vendor]/**/*_k8s.go"), - license_header("//", modification=True)) + PROJECT_ROOT.glob("./*[!vendor]/**/*_k8s.go"), + license_header("//", modification=True), verbose) ok &= check( [p for p in PROJECT_ROOT.glob( - "*[!vendor]/**/*.go") if p.name[-7:] != "_k8s.go"], - license_header("//")) - ok &= check(PROJECT_ROOT.glob("*[!vendor]/**/*.py"), license_header("#")) - ok &= check(PROJECT_ROOT.glob("*[!vendor]/**/*.sh"), license_header("#")) + "./*[!vendor]/**/*.go") if p.name[-7:] != "_k8s.go"], + license_header("//"), verbose) + ok &= check( + PROJECT_ROOT.glob("./*[!vendor]/**/*.py"), license_header("#"), verbose) + ok &= check( + PROJECT_ROOT.glob("./*[!vendor]/**/*.sh"), license_header("#"), verbose) return 0 if ok else 1 -def check(paths, license_header): +def check(paths, license_header, verbose): ok = True for p in paths: + if verbose: + print("Checking", p.relative_to(PROJECT_ROOT)) + if not p.exists(): print("File", p.relative_to(PROJECT_ROOT), "does not exist") ok = False @@ -58,4 +63,10 @@ def check(paths, license_header): if __name__ == "__main__": - exit(main()) + from argparse import ArgumentParser + + parser = ArgumentParser() + parser.add_argument("-v", "--verbose", action="store_true") + + args = parser.parse_args() + exit(main(args.verbose)) From 5c112dadb1134872edeab850d9666002b2825d25 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Fri, 5 Apr 2019 16:48:28 +0900 Subject: [PATCH 10/11] Enable license checking in CI --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1f9dd2cb0..5811f274b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,11 @@ language: go go: - "1.11.x" +addons: + apt: + packages: + - python3 + before_install: - export PATH=$GOPATH/bin:$PATH - go get -u github.com/golangci/golangci-lint/cmd/golangci-lint @@ -11,4 +16,4 @@ script: - make lint test coverage - goveralls -coverprofile=profile.cov -service=travis-ci - make e2e -# - python3 ./scripts/license/check.py -v +- python3 ./scripts/license/check.py -v From 3a7d8c79b1d05783ca37e768c23a66e016726111 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Fri, 5 Apr 2019 17:06:36 +0900 Subject: [PATCH 11/11] Fix license_header.py --- scripts/license/license_header.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/license/license_header.py b/scripts/license/license_header.py index 735f53fb8..5c40afd55 100644 --- a/scripts/license/license_header.py +++ b/scripts/license/license_header.py @@ -51,4 +51,4 @@ def has_license_header(path, license_header): Returns whether the file at `path` contains `license_header` string. """ - return license_header in open(path).read() + return license_header in path.open().read()