ryu.contrib: Be explicit about sys.path modification

Avoid the automatic modification of sys.path because it hurts
ryu-as-a-library use cases.
An example is the recent versions of neutron OVS-agent,
which optionally imports OVS python bindings, and ends up to
use a wrong copy in ryu.contrib.ovs.

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
YAMAMOTO Takashi 2015-04-17 14:33:09 +09:00 committed by FUJITA Tomonori
parent d4e8026aa8
commit cdd7084b94
7 changed files with 32 additions and 10 deletions

View File

@ -23,12 +23,16 @@ from ryu import cfg
from ryu.lib import hub
from routes import Mapper
from routes.util import URLGenerator
import ryu.contrib
ryu.contrib.update_module_path()
from tinyrpc.server import RPCServer
from tinyrpc.dispatch import RPCDispatcher
from tinyrpc.dispatch import public as rpc_public
from tinyrpc.protocols.jsonrpc import JSONRPCProtocol
from tinyrpc.transports import ServerTransport, ClientTransport
from tinyrpc.client import RPCClient
ryu.contrib.restore_module_path()
CONF = cfg.CONF
CONF.register_cli_opts([

View File

@ -27,6 +27,7 @@ hub.patch(thread=False)
# NOTE: this modifies sys.path and thus affects the following imports.
# eg. oslo.config.cfg.
import ryu.contrib
ryu.contrib.update_module_path()
from ryu import cfg
import logging

View File

@ -24,6 +24,7 @@
# (Cmd) raw_get sw1
import ryu.contrib
ryu.contrib.update_module_path()
from ryu import cfg

View File

@ -30,6 +30,7 @@
# (Cmd)
import ryu.contrib
ryu.contrib.update_module_path()
from ryu import cfg

View File

@ -15,6 +15,7 @@
# limitations under the License.
import ryu.contrib
ryu.contrib.update_module_path()
from ryu import cfg
from ryu import utils

View File

@ -1,11 +1,23 @@
# Adjust module loading path for third party libraries
import os
import sys
for path in __path__:
if path in sys.path:
sys.path.remove(path)
path = os.path.abspath(path)
if path in sys.path:
sys.path.remove(path)
sys.path.insert(0, path) # prioritize our own copy than system's
_orig_sys_path = None
def update_module_path():
# Adjust module loading path for third party libraries
import os
global _orig_sys_path
_orig_sys_path = sys.path[:]
for path in __path__:
if path in sys.path:
sys.path.remove(path)
path = os.path.abspath(path)
if path in sys.path:
sys.path.remove(path)
sys.path.insert(0, path) # prioritize our own copy than system's
def restore_module_path():
global _orig_sys_path
sys.path = _orig_sys_path
_orig_sys_path = None

View File

@ -22,7 +22,9 @@ import glob
import os.path
import sys
import ryu.contrib # we require ncclient
# we require ncclient
import ryu.contrib
ryu.contrib.update_module_path()
SCHEMA_DIR = os.path.dirname(__file__)