Skip to content

Commit c941d74

Browse files
committed
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.
1 parent 4b8e89f commit c941d74

26 files changed

+25
-53
lines changed

CONTRIBUTING.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Thanks for taking the time to join our community and start contributing!
44

5-
Any changes to utilites in this repo should be send as a PR to this repo.
5+
Any changes to utilities in this repo should be send as a PR to this repo.
66
After the PR is merged, developers should create another PR in the main repo to update the submodule.
77
See [this document](https://github.com/kubernetes-client/python/blob/master/devel/submodules.md) for more guidelines.
88

@@ -11,3 +11,19 @@ provides detailed instructions on how to get your ideas and bug fixes seen and a
1111

1212
Please remember to sign the [CNCF CLA](https://github.com/kubernetes/community/blob/master/CLA.md) and
1313
read and observe the [Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
14+
15+
## Adding new Python modules or Python scripts
16+
If you add a new Python module please make sure it includes the correct header
17+
as found in:
18+
```
19+
hack/boilerplate/boilerplate.py.txt
20+
```
21+
22+
This module should not include a shebang line.
23+
24+
If you add a new Python helper script intended for developers usage, it should
25+
go into the directory `hack` and include a shebang line `#!/usr/bin/env python`
26+
at the top in addition to rest of the boilerplate text as in all other modules.
27+
28+
In addition this script's name should be added to the list
29+
`SKIP_FILES` at the top of hack/boilerplate/boilerplate.py.

config/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2016 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

config/config_exception.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2016 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

config/dateutil.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2017 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

config/dateutil_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2016 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

config/exec_provider.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2018 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

config/exec_provider_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2018 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

config/incluster_config.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2016 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

config/incluster_config_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2016 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

config/kube_config.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2018 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

config/kube_config_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2018 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

dynamic/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2019 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

dynamic/client.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2019 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

dynamic/discovery.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2019 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

dynamic/exceptions.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2019 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

dynamic/resource.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2019 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

dynamic/test_client.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2019 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

hack/boilerplate/boilerplate.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
import re
2525
import sys
2626

27+
# list all the files contain a shebang line and should be ignored by this
28+
# script
29+
SKIP_FILES = ['hack/boilerplate/boilerplate.py']
30+
2731
parser = argparse.ArgumentParser()
2832
parser.add_argument(
2933
"filenames",
@@ -132,21 +136,19 @@ def file_extension(filename):
132136
return os.path.splitext(filename)[1].split(".")[-1].lower()
133137

134138

135-
# list all the files contain 'DO NOT EDIT', but are not generated
136-
skipped_ungenerated_files = ['hack/boilerplate/boilerplate.py']
137-
138-
139139
def normalize_files(files):
140140
newfiles = []
141141
for pathname in files:
142142
newfiles.append(pathname)
143143
for i, pathname in enumerate(newfiles):
144144
if not os.path.isabs(pathname):
145145
newfiles[i] = os.path.join(args.rootdir, pathname)
146+
146147
return newfiles
147148

148149

149150
def get_files(extensions):
151+
150152
files = []
151153
if len(args.filenames) > 0:
152154
files = args.filenames
@@ -163,6 +165,8 @@ def get_files(extensions):
163165
extension = file_extension(pathname)
164166
if extension in extensions or basename in extensions:
165167
outfiles.append(pathname)
168+
169+
outfiles = list(set(outfiles) - set(normalize_files(SKIP_FILES)))
166170
return outfiles
167171

168172

hack/boilerplate/boilerplate.py.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright YEAR The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

stream/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2017 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

stream/stream.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2018 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

stream/ws_client.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2018 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

stream/ws_client_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2018 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

watch/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2016 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

watch/watch.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2016 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

watch/watch_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2016 The Kubernetes Authors.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");

0 commit comments

Comments
 (0)