Hello,
I took a closer look at the issue and I think I might have a fix. The
attached patchset fixes the computation of app dependencies under
Python 3.x.
The first patch modifies require_app to handle the case where
inspect.getmodule returns None under Python 3.x; None values are
filtered in order to simulate the Python 2.x behavior.
The second patch modifies get_dependent_services by extending the
member predicate with an additional isfunction() check, as python 3.x
does not distinguish between bound/unbound methods.
Greetings from Germany,
-Fadi
--
ryu/base/app_manager.py | 7 ++++---
ryu/controller/handler.py | 4 +++-
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index 340d31a..7f4057d 100644
--- a/ryu/base/app_manager.py
+++ b/ryu/base/app_manager.py
@@ -77,11 +77,12 @@ def require_app(app_name, api_style=False):
If this is used for client application module, set api_style=False.
"""
+ moduleiter = (inspect.getmodule(frame[0]) for frame in inspect.stack())
+ modulestack = [module for module in moduleiter if module is not None]
if api_style:
- frm = inspect.stack()[2] # skip a frame for "api" module
+ m = modulestack[2] # skip a frame for "api" module
else:
- frm = inspect.stack()[1]
- m = inspect.getmodule(frm[0]) # client module
+ m = modulestack[1]
m._REQUIRED_APP = getattr(m, '_REQUIRED_APP', [])
m._REQUIRED_APP.append(app_name)
LOG.debug('require_app: %s is required by %s', app_name, m.__name__)
diff --git a/ryu/controller/handler.py b/ryu/controller/handler.py
index b3d40ae..4b97e59 100644
--- a/ryu/controller/handler.py
+++ b/ryu/controller/handler.py
@@ -85,10 +85,12 @@ def register_instance(i):
for ev_cls, c in m.callers.items():
i.register_handler(ev_cls, m)
+def _is_method(f):
+ return inspect.isfunction(f) or inspect.ismethod(f)
def get_dependent_services(cls):
services = []
- for _k, m in inspect.getmembers(cls, inspect.ismethod):
+ for _k, m in inspect.getmembers(cls, _is_method):
if _has_caller(m):
for ev_cls, c in m.callers.items():
service = getattr(sys.modules[ev_cls.__module__],
2015-07-30 23:32 GMT+02:00 FUJITA Tomonori <[email protected]>:
> Hi,
>
> The framework supports py3. But some of examples under "app" directory
> aren't ready.
>
> On Thu, 30 Jul 2015 14:50:54 +0200
> Fadi Moukayed <[email protected]> wrote:
>
>> Hello,
>>
>> While reading the Ryu book, I discovered that several applications in
>> ryu.app.* seem to be broken under Python 3:
>>
>> test@host:~# ryu-manager --verbose ryu.app.rest_topology
>> loading app ryu.app.rest_topology
>> Traceback (most recent call last):
>> File "/usr/local/lib/python3.4/dist-packages/ryu/utils.py", line 81, in
>> import_module
>> __import__(modname)
>> File "/usr/local/lib/python3.4/dist-packages/ryu/app/rest_topology.py",
>> line 22, in <module>
>> from ryu.topology.api import get_switch, get_link
>> File "/usr/local/lib/python3.4/dist-packages/ryu/topology/api.py", line
>> 38, in <module>
>> app_manager.require_app('ryu.topology.switches', api_style=True)
>> File "/usr/local/lib/python3.4/dist-packages/ryu/base/app_manager.py",
>> line 85, in require_app
>> m._REQUIRED_APP = getattr(m, '_REQUIRED_APP', [])
>> AttributeError: 'NoneType' object has no attribute '_REQUIRED_APP'
>>
>> During handling of the above exception, another exception occurred:
>>
>> Traceback (most recent call last):
>> File "/usr/local/bin/ryu-manager", line 9, in <module>
>> load_entry_point('ryu==3.23.2', 'console_scripts', 'ryu-manager')()
>> File "/usr/local/lib/python3.4/dist-packages/ryu/cmd/manager.py", line
>> 88, in main
>> app_mgr.load_apps(app_lists)
>> File "/usr/local/lib/python3.4/dist-packages/ryu/base/app_manager.py",
>> line 389, in load_apps
>> cls = self.load_app(app_cls_name)
>> File "/usr/local/lib/python3.4/dist-packages/ryu/base/app_manager.py",
>> line 366, in load_app
>> mod = utils.import_module(name)
>> File "/usr/local/lib/python3.4/dist-packages/ryu/utils.py", line 92, in
>> import_module
>> __import__(name)
>> File "/usr/local/lib/python3.4/dist-packages/ryu/app/rest_topology.py",
>> line 22, in <module>
>> from ryu.topology.api import get_switch, get_link
>> File "/usr/local/lib/python3.4/dist-packages/ryu/topology/api.py", line
>> 38, in <module>
>> app_manager.require_app('ryu.topology.switches', api_style=True)
>> File "/usr/local/lib/python3.4/dist-packages/ryu/base/app_manager.py",
>> line 85, in require_app
>> m._REQUIRED_APP = getattr(m, '_REQUIRED_APP', [])
>> AttributeError: 'NoneType' object has no attribute '_REQUIRED_APP'
>>
>> The above happens with Ryu 3.23.2 from PyPI on Python 3.4.0 (Ubuntu 14.04)
>>
>> Additionally, I also saw the following error messages during install (Seems
>> like some files were missed during the 2->3 conversion):
>>
>> Installing collected packages: ryu
>> Running setup.py install for ryu
>> [pbr] Reusing existing SOURCES.txt
>> Installing ryu script to /usr/local/bin
>> Installing ryu-manager script to /usr/local/bin
>> File
>> "/usr/local/lib/python3.4/dist-packages/ryu/contrib/ovs/db/idl.py", line 189
>> except error.Error, e:
>> ^
>> SyntaxError: invalid syntax
>>
>> File
>> "/usr/local/lib/python3.4/dist-packages/ryu/contrib/ovs/stream.py", line 122
>> def open_block((error, stream)):
>> ^
>> SyntaxError: invalid syntax
>>
>> File
>> "/usr/local/lib/python3.4/dist-packages/ryu/contrib/ovs/fatal_signal.py",
>> line 93
>> except OSError, e:
>> ^
>> SyntaxError: invalid syntax
>>
>> File
>> "/usr/local/lib/python3.4/dist-packages/ryu/contrib/ovs/daemon.py", line 147
>> except IOError, e:
>> ^
>> SyntaxError: invalid syntax
>>
>> File
>> "/usr/local/lib/python3.4/dist-packages/ryu/contrib/ovs/poller.py", line 174
>> except select.error, e:
>> ^
>> SyntaxError: invalid syntax
>>
>> File
>> "/usr/local/lib/python3.4/dist-packages/ryu/contrib/ovs/socket_util.py",
>> line 40
>> except socket.error, e:
>> ^
>> SyntaxError: invalid syntax
>>
>> File
>> "/usr/local/lib/python3.4/dist-packages/ryu/contrib/ovs/json.py", line 146
>> except UnicodeDecodeError, e:
>> ^
>> SyntaxError: invalid syntax
>>
>> File
>> "/usr/local/lib/python3.4/dist-packages/ryu/contrib/ovs/ovsuuid.py", line 45
>> except error.Error, e:
>> ^
>> SyntaxError: invalid syntax
>>
>> Successfully installed ryu
>> Cleaning up...
>> test@host:~$
>>
>> Note that other example applications such as simple_vlan and rest_qos are
>> affected by this, since they depend on the contrib.ovs modules.
>>
>> Greetings from Germany,
>> -Fadi
------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel