From c941d74b3745550fc886ebf20e40725aa4722f5c Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Tue, 20 Aug 2019 22:25:57 +0200 Subject: [PATCH] Remove all shebangs from Python modules and checker As discussed, Python modules which aren't intended to be invoked as scripts should not include a shebang line. Update CONTRIBUTING.md and the checker script. This script now includes a list SKIP_FILES for files that should not be checked for boilerplate template. The tests will now fail if a Python module has a shebang line. Scripts which should have a shebang line and exists in the directory `hack` can be ignored by adding them to the SKIP_FILES list. --- CONTRIBUTING.md | 18 +++++++++++++++++- config/__init__.py | 2 -- config/config_exception.py | 2 -- config/dateutil.py | 2 -- config/dateutil_test.py | 2 -- config/exec_provider.py | 2 -- config/exec_provider_test.py | 2 -- config/incluster_config.py | 2 -- config/incluster_config_test.py | 2 -- config/kube_config.py | 2 -- config/kube_config_test.py | 2 -- dynamic/__init__.py | 2 -- dynamic/client.py | 2 -- dynamic/discovery.py | 2 -- dynamic/exceptions.py | 2 -- dynamic/resource.py | 2 -- dynamic/test_client.py | 2 -- hack/boilerplate/boilerplate.py | 12 ++++++++---- hack/boilerplate/boilerplate.py.txt | 2 -- stream/__init__.py | 2 -- stream/stream.py | 2 -- stream/ws_client.py | 2 -- stream/ws_client_test.py | 2 -- watch/__init__.py | 2 -- watch/watch.py | 2 -- watch/watch_test.py | 2 -- 26 files changed, 25 insertions(+), 53 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 252a55548..73862f463 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ Thanks for taking the time to join our community and start contributing! -Any changes to utilites in this repo should be send as a PR to this repo. +Any changes to utilities in this repo should be send as a PR to this repo. After the PR is merged, developers should create another PR in the main repo to update the submodule. See [this document](https://github.com/kubernetes-client/python/blob/master/devel/submodules.md) for more guidelines. @@ -11,3 +11,19 @@ provides detailed instructions on how to get your ideas and bug fixes seen and a Please remember to sign the [CNCF CLA](https://github.com/kubernetes/community/blob/master/CLA.md) and read and observe the [Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). + +## Adding new Python modules or Python scripts +If you add a new Python module please make sure it includes the correct header +as found in: +``` +hack/boilerplate/boilerplate.py.txt +``` + +This module should not include a shebang line. + +If you add a new Python helper script intended for developers usage, it should +go into the directory `hack` and include a shebang line `#!/usr/bin/env python` +at the top in addition to rest of the boilerplate text as in all other modules. + +In addition this script's name should be added to the list +`SKIP_FILES` at the top of hack/boilerplate/boilerplate.py. diff --git a/config/__init__.py b/config/__init__.py index 02a7532d5..3476ff714 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/config/config_exception.py b/config/config_exception.py index 9bf049c69..23fab022c 100644 --- a/config/config_exception.py +++ b/config/config_exception.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/config/dateutil.py b/config/dateutil.py index db880efa3..972e003eb 100644 --- a/config/dateutil.py +++ b/config/dateutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2017 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/config/dateutil_test.py b/config/dateutil_test.py index f5587d6e8..933360d9f 100644 --- a/config/dateutil_test.py +++ b/config/dateutil_test.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/config/exec_provider.py b/config/exec_provider.py index a0348f1e9..4008f2e8b 100644 --- a/config/exec_provider.py +++ b/config/exec_provider.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2018 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/config/exec_provider_test.py b/config/exec_provider_test.py index 8b6517b01..44579beb2 100644 --- a/config/exec_provider_test.py +++ b/config/exec_provider_test.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2018 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/config/incluster_config.py b/config/incluster_config.py index c9bdc907d..6f28a4aea 100644 --- a/config/incluster_config.py +++ b/config/incluster_config.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/config/incluster_config_test.py b/config/incluster_config_test.py index 3cb0abfc8..622b31b37 100644 --- a/config/incluster_config_test.py +++ b/config/incluster_config_test.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/config/kube_config.py b/config/kube_config.py index 386b82c1e..3384d2720 100644 --- a/config/kube_config.py +++ b/config/kube_config.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2018 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/config/kube_config_test.py b/config/kube_config_test.py index 04f6b11e5..b29525e8b 100644 --- a/config/kube_config_test.py +++ b/config/kube_config_test.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2018 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/dynamic/__init__.py b/dynamic/__init__.py index 91ba0501d..a1d3d8f8e 100644 --- a/dynamic/__init__.py +++ b/dynamic/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2019 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/dynamic/client.py b/dynamic/client.py index 02bb984b3..7b82b3d6a 100644 --- a/dynamic/client.py +++ b/dynamic/client.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2019 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/dynamic/discovery.py b/dynamic/discovery.py index a646a96a3..9468a2740 100644 --- a/dynamic/discovery.py +++ b/dynamic/discovery.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2019 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/dynamic/exceptions.py b/dynamic/exceptions.py index d940d4299..c8b908e7d 100644 --- a/dynamic/exceptions.py +++ b/dynamic/exceptions.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2019 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/dynamic/resource.py b/dynamic/resource.py index 3e2897cd2..c83ae9fd8 100644 --- a/dynamic/resource.py +++ b/dynamic/resource.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2019 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/dynamic/test_client.py b/dynamic/test_client.py index d6d65c6d8..dc52a30da 100644 --- a/dynamic/test_client.py +++ b/dynamic/test_client.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2019 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/hack/boilerplate/boilerplate.py b/hack/boilerplate/boilerplate.py index 61d4cb947..eec04b458 100755 --- a/hack/boilerplate/boilerplate.py +++ b/hack/boilerplate/boilerplate.py @@ -24,6 +24,10 @@ import os import re import sys +# list all the files contain a shebang line and should be ignored by this +# script +SKIP_FILES = ['hack/boilerplate/boilerplate.py'] + parser = argparse.ArgumentParser() parser.add_argument( "filenames", @@ -132,10 +136,6 @@ def file_extension(filename): return os.path.splitext(filename)[1].split(".")[-1].lower() -# list all the files contain 'DO NOT EDIT', but are not generated -skipped_ungenerated_files = ['hack/boilerplate/boilerplate.py'] - - def normalize_files(files): newfiles = [] for pathname in files: @@ -143,10 +143,12 @@ def normalize_files(files): for i, pathname in enumerate(newfiles): if not os.path.isabs(pathname): newfiles[i] = os.path.join(args.rootdir, pathname) + return newfiles def get_files(extensions): + files = [] if len(args.filenames) > 0: files = args.filenames @@ -163,6 +165,8 @@ def get_files(extensions): extension = file_extension(pathname) if extension in extensions or basename in extensions: outfiles.append(pathname) + + outfiles = list(set(outfiles) - set(normalize_files(SKIP_FILES))) return outfiles diff --git a/hack/boilerplate/boilerplate.py.txt b/hack/boilerplate/boilerplate.py.txt index d781daf9e..34cb349c4 100644 --- a/hack/boilerplate/boilerplate.py.txt +++ b/hack/boilerplate/boilerplate.py.txt @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright YEAR The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/stream/__init__.py b/stream/__init__.py index e9b7d24ff..e72d05836 100644 --- a/stream/__init__.py +++ b/stream/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2017 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/stream/stream.py b/stream/stream.py index 3eab0b9ab..a9d0b402d 100644 --- a/stream/stream.py +++ b/stream/stream.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2018 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/stream/ws_client.py b/stream/ws_client.py index a1a96f2db..65f0df176 100644 --- a/stream/ws_client.py +++ b/stream/ws_client.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2018 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/stream/ws_client_test.py b/stream/ws_client_test.py index 756d95978..a8f4049dd 100644 --- a/stream/ws_client_test.py +++ b/stream/ws_client_test.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2018 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/watch/__init__.py b/watch/__init__.py index 46a31ceda..ca9ac0698 100644 --- a/watch/__init__.py +++ b/watch/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/watch/watch.py b/watch/watch.py index 5966eaceb..77b979478 100644 --- a/watch/watch.py +++ b/watch/watch.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/watch/watch_test.py b/watch/watch_test.py index ebc400af4..6fec23ec5 100644 --- a/watch/watch_test.py +++ b/watch/watch_test.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License");