You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wi...@apache.org on 2014/05/12 22:59:51 UTC

git commit: Add python import order wrapper/commit hook

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 289d0ea24 -> 904232439


Add python import order wrapper/commit hook

Adds build-support/isort wrapper for isort.

Adds build-support/isort-run to run import sort, build-support/isort-check
to run import order check.

Adds build-support/hooks which contains hooks that people can place into
their .git/hooks directory, currently just a pre-commit hook that checks
import sort order (which can be overridden with an environment variable.)

The ordering it produces is different than the one we currently have but
closer to straight PEP8.  If it runs, it's about a 500 line diff which I can
send later.

Testing Done:
Ran the isort and ran tests, everything worked.

Bugs closed: AURORA-149

Reviewed at https://reviews.apache.org/r/21136/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/90423243
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/90423243
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/90423243

Branch: refs/heads/master
Commit: 90423243977f141002319f9cd4bd59bcee33aefe
Parents: 289d0ea
Author: Brian Wickman <wi...@apache.org>
Authored: Mon May 12 13:59:45 2014 -0700
Committer: Brian Wickman <wi...@apache.org>
Committed: Mon May 12 13:59:45 2014 -0700

----------------------------------------------------------------------
 .isort.cfg                     | 20 +++++++++++++++++++
 build-support/hooks/pre-commit | 40 +++++++++++++++++++++++++++++++++++++
 build-support/isort            | 34 +++++++++++++++++++++++++++++++
 build-support/isort-check      | 19 ++++++++++++++++++
 build-support/isort-run        | 19 ++++++++++++++++++
 5 files changed, 132 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/90423243/.isort.cfg
----------------------------------------------------------------------
diff --git a/.isort.cfg b/.isort.cfg
new file mode 100644
index 0000000..f53ccba
--- /dev/null
+++ b/.isort.cfg
@@ -0,0 +1,20 @@
+# This is the isort (https://github.com/timothycrosley/isort) configuration for
+# Python import sorting in the aurora repository.
+#
+# To apply against the repository run:
+#    $ build-support/isort-run
+#
+# To check that the repository passes the import order check:
+#    $ build-support/isort-check
+#
+# If you would like to install the isort checker as a local git hook, just run
+#    $ cp -f build-support/hooks/pre-commit .git/hooks/pre-commit
+# and these checks will be done automatically for each commit.
+#
+
+[settings]
+line_length=100
+known_first_party=apache
+multi_line_output=3
+forced_separate=gen
+default_section=THIRDPARTY

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/90423243/build-support/hooks/pre-commit
----------------------------------------------------------------------
diff --git a/build-support/hooks/pre-commit b/build-support/hooks/pre-commit
new file mode 100755
index 0000000..21e2b06
--- /dev/null
+++ b/build-support/hooks/pre-commit
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# Copyright 2014 Apache Software Foundation
+#
+# 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.
+
+set -e
+
+if [ $SKIP_AURORA_HOOKS ]; then
+  echo "Skipping hooks."
+  exit 0
+fi
+
+HERE=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
+
+echo "Performing Python import order check."
+if ! $HERE/../../build-support/isort-check >&/dev/null; then
+  echo ""
+  echo ""
+  echo "** PYTHON IMPORT ORDER CHECK FAILED"
+  echo "*"
+  echo "* please run: build-support/isort-run"
+  echo "*"
+  echo "**"
+  echo ""
+  exit 1
+else
+  echo "SUCCESS"
+fi
+

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/90423243/build-support/isort
----------------------------------------------------------------------
diff --git a/build-support/isort b/build-support/isort
new file mode 100755
index 0000000..a5378f1
--- /dev/null
+++ b/build-support/isort
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+#
+# Copyright 2014 Apache Software Foundation
+#
+# 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.
+#
+# Wrapper script for running isort
+set -e
+
+HERE=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
+ISORT_VERSION=3.8.0
+
+if ! [ -f "$HERE/isort.venv/BOOTSTRAPPED" ] || \
+    [ x`cat "$HERE/isort.venv/BOOTSTRAPPED"` != x$ISORT_VERSION ]; then
+  echo Bootstrapping isort @ $ISORT_VERSION
+  rm -fr "$HERE/isort.venv"
+  "$HERE/virtualenv" "$HERE/isort.venv"
+  source "$HERE/isort.venv/bin/activate"
+  pip install "isort==$ISORT_VERSION"
+  echo $ISORT_VERSION > "$HERE/isort.venv/BOOTSTRAPPED"
+fi
+
+source "$HERE/isort.venv/bin/activate"
+exec isort "$@"

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/90423243/build-support/isort-check
----------------------------------------------------------------------
diff --git a/build-support/isort-check b/build-support/isort-check
new file mode 100755
index 0000000..4129deb
--- /dev/null
+++ b/build-support/isort-check
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+#
+# Copyright 2014 Apache Software Foundation
+#
+# 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.
+set -e
+
+HERE=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
+$HERE/isort -ns __init__.py -rc $HERE/../src -c

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/90423243/build-support/isort-run
----------------------------------------------------------------------
diff --git a/build-support/isort-run b/build-support/isort-run
new file mode 100755
index 0000000..c528b9a
--- /dev/null
+++ b/build-support/isort-run
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+#
+# Copyright 2014 Apache Software Foundation
+#
+# 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.
+set -e
+
+HERE=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
+$HERE/isort -ns __init__.py -rc $HERE/../src