Skip to content

Commit

Permalink
Update examples/bin/dsql scripts to accept Python 3 (#16677)
Browse files Browse the repository at this point in the history
* Update examples/bin/dsql scripts to accept Python 3

Remove redundant urllib import

Translating to Python3: Changing xrange to range

Translating to Python3: Changing long to int

Translating to Python3: Change urllib2 methods, and fix encoding/decoding issues

Remove unnecessary import

Add option for Python2

Rename files

* Update examples/bin/dsql

Co-authored-by: Benedict Jin <asdf2014@apache.org>

* Resolve PR comments

Add comment in files indicating updates need to be made in both places

Update examples/bin/dsql

Co-authored-by: Benedict Jin <asdf2014@apache.org>

* Update error output when using Python 2.

Co-authored-by: Abhishek Radhakrishnan <abhishek.rb19@gmail.com>

---------

Co-authored-by: Benedict Jin <asdf2014@apache.org>
Co-authored-by: Abhishek Radhakrishnan <abhishek.rb19@gmail.com>
  • Loading branch information
3 people committed Jul 3, 2024
1 parent 6c87b16 commit f290cf0
Show file tree
Hide file tree
Showing 3 changed files with 538 additions and 3 deletions.
13 changes: 10 additions & 3 deletions examples/bin/dsql
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ PWD="$(pwd)"
WHEREAMI="$(dirname "$0")"
WHEREAMI="$(cd "$WHEREAMI" && pwd)"

if [ -x "$(command -v python2)" ]
if [ -x "$(command -v python3)" ]
then
exec python2 "$WHEREAMI/dsql-main" "$@"
exec python3 "$WHEREAMI/dsql-main-py3" "$@"
elif [ -x "$(command -v python2)" ]
then
echo "Warning: Support for Python 2 will be removed in the future. Please consider upgrading to Python 3"
exec python2 "$WHEREAMI/dsql-main-py2" "$@"
elif [ -x "$(command -v python)" ]
then
exec python "$WHEREAMI/dsql-main-py3" "$@"
else
exec "$WHEREAMI/dsql-main" "$@"
echo "python interepreter not found"
fi
5 changes: 5 additions & 0 deletions examples/bin/dsql-main → examples/bin/dsql-main-py2
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# specific language governing permissions and limitations
# under the License.

# NOTE:
# Any feature updates to this script must also be reflected in
# `dsql-main-py3` so that intended changes work for users using
# Python 2 or 3.

from __future__ import print_function

import argparse
Expand Down
Loading

0 comments on commit f290cf0

Please sign in to comment.