diff --git a/.gitignore b/.gitignore index e2a49b897e..42646a7814 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Compiled python files +*.pyc + # OSX leaves these everywhere on SMB shares ._* diff --git a/Makefile b/Makefile index 1e84592742..97bbbf758e 100644 --- a/Makefile +++ b/Makefile @@ -273,6 +273,11 @@ gofmt: gofmt -w -s dns-controller/cmd gofmt -w -s dns-controller/pkg +goimports: + sh -c hack/update-goimports + +verify-goimports: + sh -c hack/verify-goimports govet: go vet \ diff --git a/hack/lib/__init__.py b/hack/lib/__init__.py new file mode 100644 index 0000000000..c9733f32c9 --- /dev/null +++ b/hack/lib/__init__.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +# Copyright 2017 The Kubernetes Authors. +# +# 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. + +__all__ = ["kubernetes"] \ No newline at end of file diff --git a/hack/lib/kubernetes/__init__.py b/hack/lib/kubernetes/__init__.py new file mode 100644 index 0000000000..9d2a12c2a7 --- /dev/null +++ b/hack/lib/kubernetes/__init__.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +# Copyright 2017 The Kubernetes Authors. +# +# 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. + +__all__ = ["devtools"] \ No newline at end of file diff --git a/hack/lib/kubernetes/devtools.py b/hack/lib/kubernetes/devtools.py new file mode 100644 index 0000000000..33c9d2a509 --- /dev/null +++ b/hack/lib/kubernetes/devtools.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +# Copyright 2017 The Kubernetes Authors. +# +# 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. + +import os +from os import path + +gopath=os.environ['GOPATH'] + +def read_packages_file(package_name): + packages = [] + with open(path.join(gopath, 'src', package_name, 'hack/.packages')) as packages_file: + for package in packages_file: + packages.append(package.replace('\n', '')) + return packages diff --git a/hack/update-goimports b/hack/update-goimports new file mode 100755 index 0000000000..5807297ee2 --- /dev/null +++ b/hack/update-goimports @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +# Copyright 2017 The Kubernetes Authors. +# +# 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. + +import os +from os import path +import subprocess +import sys + +from lib.kubernetes import devtools + +gopath=os.environ['GOPATH'] + +package_name='k8s.io/kops' + +packages = devtools.read_packages_file(package_name) + +paths = [] + +for package in packages: + if package == package_name: + continue + paths.append(package) + +print("packages %s" % paths) + +subprocess.call(['goimports', '-w'] + paths, cwd=path.join(gopath, 'src')) diff --git a/hack/verify-goimports b/hack/verify-goimports new file mode 100755 index 0000000000..f8e95a7f72 --- /dev/null +++ b/hack/verify-goimports @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +# Copyright 2017 The Kubernetes Authors. +# +# 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. + +import os +from os import path +import subprocess +import sys + +from lib.kubernetes import devtools + +gopath=os.environ['GOPATH'] + +package_name='k8s.io/kops' + +packages = devtools.read_packages_file(package_name) + +paths = [] + +for package in packages: + if package == package_name: + continue + paths.append(package) + +print("packages %s" % paths) + +process = subprocess.Popen(['goimports', '-l'] + paths, stdout=subprocess.PIPE, cwd=path.join(gopath, 'src')) +stdout, stderr = process.communicate() + +if stdout != "": + print("!!! 'goimports -w' needs to be run on the following files: ") + print(stdout) + print('!!! Please run: make goimports') + sys.exit(1)