[CRIU] [PATCH 6/9] python lib: rename rpc.py to rpc_pb2.py

Tycho Andersen tycho.andersen at canonical.com
Mon Oct 3 11:13:45 PDT 2016


Unfortunately, newer versions of protobuf check that the file suffix ends
in _pb2.py:

sudo ./zdtm.py run -t zdtm/static/apparmor_stacking
Traceback (most recent call last):
  File "./zdtm.py", line 23, in <module>
    import criu as crpc
  File "/home/ubuntu/criu/test/criu.py", line 12, in <module>
    import rpc
  File "/home/ubuntu/criu/test/rpc.py", line 36, in <module>
    type=None),
  File "/usr/lib/python2.7/dist-packages/google/protobuf/descriptor.py", line 652, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors should not be created directly, but only retrieved from their parent.

v2: fix up the clean target, and remove some comments that were about the
    old rename

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lib/py/.gitignore  |  1 -
 lib/py/Makefile    | 11 ++++-------
 lib/py/__init__.py |  2 +-
 lib/py/criu.py     |  2 +-
 test/rpc.py        |  1 -
 test/rpc_pb2.py    |  1 +
 6 files changed, 7 insertions(+), 11 deletions(-)
 delete mode 120000 test/rpc.py
 create mode 120000 test/rpc_pb2.py

diff --git a/lib/py/.gitignore b/lib/py/.gitignore
index 8d503da..d3090fc 100644
--- a/lib/py/.gitignore
+++ b/lib/py/.gitignore
@@ -1,3 +1,2 @@
 *_pb2.py
 *.pyc
-rpc.py
diff --git a/lib/py/Makefile b/lib/py/Makefile
index 582cc93..9ef4fa4 100644
--- a/lib/py/Makefile
+++ b/lib/py/Makefile
@@ -1,16 +1,13 @@
-all: images rpc.py
+all: images rpc_pb2.py
 
 .PHONY: all images clean
 
 images:
 	$(Q) $(MAKE) -C images all
 
-# rpc_pb2.py doesn't depend on any other file, so
-# it is safe to rename it, dropping ugly _pb2 suffix.
-rpc.py:
-	$(Q) protoc -I=$(SRC_DIR)/images/ --python_out=./ $(SRC_DIR)/images/$(@:.py=.proto)
-	$(Q) mv $(@:.py=_pb2.py) $@
+rpc_pb2.py:
+	$(Q) protoc -I=$(SRC_DIR)/images/ --python_out=./ $(SRC_DIR)/images/$(@:_pb2.py=.proto)
 
 clean:
 	$(Q) $(MAKE) -C images clean
-	$(Q) $(RM) rpc.py *.pyc
+	$(Q) $(RM) rpc_pb2.py *.pyc
diff --git a/lib/py/__init__.py b/lib/py/__init__.py
index 7de6283..8e17499 100644
--- a/lib/py/__init__.py
+++ b/lib/py/__init__.py
@@ -1,3 +1,3 @@
-import rpc
+import rpc_pb2 as rpc
 import images
 from criu import *
diff --git a/lib/py/criu.py b/lib/py/criu.py
index 84dcefe..0ae204a 100644
--- a/lib/py/criu.py
+++ b/lib/py/criu.py
@@ -9,7 +9,7 @@ import signal
 import sys
 import struct
 
-import rpc
+import rpc_pb2 as rpc
 
 class _criu_comm:
 	"""
diff --git a/test/rpc.py b/test/rpc.py
deleted file mode 120000
index 62fc609..0000000
--- a/test/rpc.py
+++ /dev/null
@@ -1 +0,0 @@
-../lib/py/rpc.py
\ No newline at end of file
diff --git a/test/rpc_pb2.py b/test/rpc_pb2.py
new file mode 120000
index 0000000..49648ae
--- /dev/null
+++ b/test/rpc_pb2.py
@@ -0,0 +1 @@
+../lib/py/rpc_pb2.py
\ No newline at end of file
-- 
2.9.3



More information about the CRIU mailing list