Skip to content

Commit 273684c

Browse files
committed
Add semi-auto code formatting script
1 parent 98e675e commit 273684c

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

scripts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.py/

scripts/update-pep8.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# Copyright 2015 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Script to fetch latest swagger spec.
18+
# Puts the updated spec at api/swagger-spec/
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
24+
if ! which virtualenv > /dev/null 2>&1; then
25+
echo "virtualenv is not installed. run: [sudo] pip install virtualenv"
26+
exit
27+
fi
28+
29+
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
30+
CLIENT_ROOT="${SCRIPT_ROOT}/.."
31+
32+
pushd "${SCRIPT_ROOT}" > /dev/null
33+
SCRIPT_ROOT=`pwd`
34+
popd > /dev/null
35+
36+
pushd "${CLIENT_ROOT}" > /dev/null
37+
CLIENT_ROOT=`pwd`
38+
popd > /dev/null
39+
40+
virtualenv "${SCRIPT_ROOT}/.py"
41+
42+
VIRTUAL_ENV_DISABLE_PROMPT=1; source "${SCRIPT_ROOT}/.py/bin/activate"
43+
trap "deactivate" EXIT SIGINT
44+
45+
SAVEIFS=$IFS
46+
trap "IFS=$SAVEIFS" EXIT SIGINT
47+
IFS=,
48+
49+
SOURCES="${CLIENT_ROOT}/k8sutil/*.py,${SCRIPT_ROOT}/*.py,${CLIENT_ROOT}/examples/*.py"
50+
51+
echo "--- Updating tools"
52+
pip install --upgrade pep8
53+
pip install --upgrade autopep8
54+
pip install --upgrade isort
55+
56+
echo "--- applying autopep8"
57+
for SOURCE in $SOURCES; do
58+
autopep8 -i -a -a $SOURCE
59+
done
60+
61+
echo "--- applying isort"
62+
for SOURCE in $SOURCES; do
63+
isort -y $SOURCE
64+
done
65+
66+
echo "--- check pep8 (all need to be fixed manually)"
67+
set +o errexit
68+
for SOURCE in $SOURCES; do
69+
pep8 $SOURCE
70+
done
71+
72+
echo "---Done."

0 commit comments

Comments
 (0)