You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ko...@apache.org on 2019/11/21 02:37:42 UTC

[avro] branch master updated: AVRO-2635: Use tools via python -m (#723)

This is an automated email from the ASF dual-hosted git repository.

kojiromike pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


View the commit online:
https://github.com/apache/avro/commit/4254e280271e6b53495d866cf4262af4f1f2a288

The following commit(s) were added to refs/heads/master by this push:
     new 4254e28  AVRO-2635: Use tools via python -m (#723)
4254e28 is described below

commit 4254e280271e6b53495d866cf4262af4f1f2a288
Author: Michael A. Smith <mi...@smith-li.com>
AuthorDate: Wed Nov 20 21:37:36 2019 -0500

    AVRO-2635: Use tools via python -m (#723)
---
 lang/py/src/avro/tool.py                   | 14 ++++++++++----
 share/test/interop/bin/test_rpc_interop.sh |  8 ++++----
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/lang/py/src/avro/tool.py b/lang/py/src/avro/tool.py
index 3c0c228..b8f95ae 100644
--- a/lang/py/src/avro/tool.py
+++ b/lang/py/src/avro/tool.py
@@ -25,12 +25,15 @@ NOTE: The API for the command-line tool is experimental.
 
 from __future__ import absolute_import, division, print_function
 
+import os.path
 import sys
 import threading
 import urlparse
+import warnings
 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
 
-from avro import datafile, io, ipc, protocol
+import avro.io
+from avro import datafile, ipc, protocol
 
 
 class GenericResponder(ipc.Responder):
@@ -101,7 +104,7 @@ def main(args=sys.argv):
     if len(args) != 3:
       print("Usage: %s dump input_file" % args[0])
       return 1
-    for d in datafile.DataFileReader(file_or_stdin(args[2]), io.DatumReader()):
+    for d in datafile.DataFileReader(file_or_stdin(args[2]), avro.io.DatumReader()):
       print(repr(d))
   elif args[1] == "rpcreceive":
     usage_str = "Usage: %s rpcreceive uri protocol_file " % args[0]
@@ -114,7 +117,7 @@ def main(args=sys.argv):
     if len(args) > 5:
       if args[5] == "-file":
         reader = open(args[6], 'rb')
-        datum_reader = io.DatumReader()
+        datum_reader = avro.io.DatumReader()
         dfr = datafile.DataFileReader(reader, datum_reader)
         datum = next(dfr)
       elif args[5] == "-data":
@@ -135,7 +138,7 @@ def main(args=sys.argv):
     if len(args) > 5:
       if args[5] == "-file":
         reader = open(args[6], 'rb')
-        datum_reader = io.DatumReader()
+        datum_reader = avro.io.DatumReader()
         dfr = datafile.DataFileReader(reader, datum_reader)
         datum = next(dfr)
       elif args[5] == "-data":
@@ -148,4 +151,7 @@ def main(args=sys.argv):
   return 0
 
 if __name__ == "__main__":
+  if os.path.dirname(avro.io.__file__) in sys.path:
+    warnings.warn("Invoking avro/tool.py directly is likely to lead to a name collision with the python io module. Try doing `python -m avro.tool` instead.")
+
   sys.exit(main(sys.argv))
diff --git a/share/test/interop/bin/test_rpc_interop.sh b/share/test/interop/bin/test_rpc_interop.sh
index adc450d..6f65b1d 100755
--- a/share/test/interop/bin/test_rpc_interop.sh
+++ b/share/test/interop/bin/test_rpc_interop.sh
@@ -24,11 +24,11 @@ VERSION=`cat share/VERSION.txt`
 java_client="java -jar lang/java/tools/target/avro-tools-$VERSION.jar rpcsend"
 java_server="java -jar lang/java/tools/target/avro-tools-$VERSION.jar rpcreceive"
 
-py_client="env PYTHONPATH=lang/py/build/src python lang/py/build/src/avro/tool.py rpcsend"
-py_server="env PYTHONPATH=lang/py/build/src python lang/py/build/src/avro/tool.py rpcreceive"
+py_client="env PYTHONPATH=lang/py/build/src python -m avro.tool rpcsend"
+py_server="env PYTHONPATH=lang/py/build/src python -m avro.tool rpcreceive"
 
-py3_client="env PYTHONPATH=lang/py3 python3 lang/py3/avro/tool.py rpcsend"
-py3_server="env PYTHONPATH=lang/py3 python3 lang/py3/avro/tool.py rpcreceive"
+py3_client="env PYTHONPATH=lang/py3 python3 -m avro.tool rpcsend"
+py3_server="env PYTHONPATH=lang/py3 python3 -m avro.tool rpcreceive"
 
 ruby_client="ruby -rubygems -Ilang/ruby/lib lang/ruby/test/tool.rb rpcsend"
 ruby_server="ruby -rubygems -Ilang/ruby/lib lang/ruby/test/tool.rb rpcreceive"