You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by jo...@apache.org on 2023/02/28 17:12:49 UTC
[impala] 02/06: IMPALA-11951: Add tools for checking/fixing python 3 syntax
This is an automated email from the ASF dual-hosted git repository.
joemcdonnell pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit ff62a4df3927ad054d5374e922c8399c2a227182
Author: Joe McDonnell <jo...@cloudera.com>
AuthorDate: Sun Feb 26 13:04:52 2023 -0800
IMPALA-11951: Add tools for checking/fixing python 3 syntax
This adds the bin/check-python-syntax.sh script, which
runs "python -m compileall" for all python files in
Impala with both python2 and python3. This detects
syntax errors in the python files. This will be
incorporated into precommit once it is clean.
This also adds future to the impala-python virtualenv.
This provides the futurize script (exposed via
impala-futurize), which can be used to automatically
fix some py2/py3 issues. Future also provides the
builtins library, which can provide python 3
functionality on python 2.
Testing:
- Ran impala-futurize locally
- Ran the script repeatedly while fixing syntax errors
Change-Id: Iae2c51bc6ddc9b6a04469ee1b8284227fed3bd45
Reviewed-on: http://gerrit.cloudera.org:8080/19550
Reviewed-by: Michael Smith <mi...@cloudera.com>
Tested-by: Michael Smith <mi...@cloudera.com>
---
bin/check-python-syntax.sh | 71 ++++++++++++++++++++++++++++++++++++++
bin/impala-futurize | 21 +++++++++++
infra/python/deps/requirements.txt | 1 +
3 files changed, 93 insertions(+)
diff --git a/bin/check-python-syntax.sh b/bin/check-python-syntax.sh
new file mode 100755
index 000000000..36a7ff87e
--- /dev/null
+++ b/bin/check-python-syntax.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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 -euo pipefail
+
+pushd ${IMPALA_HOME} > /dev/null 2>&1
+
+RETCODE=0
+for file in $(git ls-files '**/*.py'); do
+ # Skip the shell's ext-py code
+ if [[ "${file}" =~ "shell/ext-py" ]]; then
+ continue
+ fi
+ # Skip the shell's pkg_resources.py
+ if [[ "${file}" == "shell/pkg_resources.py" ]]; then
+ continue
+ fi
+
+ # Python 2 checks
+ # -l = no recursion
+ # -q = only print errors
+ # -f = force recompile
+ if ! python2 -m compileall -l -q -f ${file} > /dev/null 2>&1; then
+ RETCODE=1
+ echo "Python 2 compilation failed for ${file}:"
+ set +e
+ python2 -m compileall -l -q -f ${file}
+ set -e
+ fi
+ # Clean up the .pyc files generated by compilation
+ if [[ -f "${file}c" ]]; then
+ rm "${file}c"
+ fi
+
+ # Python 3 checks
+ # -l = no recursion
+ # -q = only print errors
+ # -f = force recompile
+ if ! python3 -m compileall -l -q -f ${file} > /dev/null 2>&1 ; then
+ RETCODE=1
+ echo "Python 3 compilation failed for ${file}:"
+ set +e
+ python3 -m compileall -l -q -f ${file}
+ set -e
+ fi
+ # Clean up the __pycache__ directories generated by compilation
+ py_cache_dir="$(dirname ${file})/__pycache__"
+ if [[ -d "${py_cache_dir}" ]]; then
+ rm -rf ${py_cache_dir}
+ fi
+done
+
+popd > /dev/null 2>&1
+
+exit ${RETCODE}
diff --git a/bin/impala-futurize b/bin/impala-futurize
new file mode 100755
index 000000000..b761b5212
--- /dev/null
+++ b/bin/impala-futurize
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+
+source "$(dirname "$0")/impala-python-common.sh"
+exec "$PY_ENV_DIR/bin/futurize" "$@"
diff --git a/infra/python/deps/requirements.txt b/infra/python/deps/requirements.txt
index 8f8ada7a7..271ddeadc 100644
--- a/infra/python/deps/requirements.txt
+++ b/infra/python/deps/requirements.txt
@@ -37,6 +37,7 @@ flake8 == 3.9.2
contextlib2 == 0.6.0
pathlib2 == 2.3.7.post1
zipp == 1.2.0
+future == 0.18.3
gcovr == 4.2
Jinja2 == 2.11.3
MarkupSafe == 1.1.1