diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2013-10-07 14:43:52 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-10-07 18:08:36 +0900 |
commit | d6a9890b0833044fef1b7e916cd355cec325303f (patch) | |
tree | 15de92d6364bab15e4902fe470b7fe9708fb5813 | |
parent | 9159bd74fe9400bbb602fb5b669c46f149b295d4 (diff) |
avoid pbr's non multi-version aware script
otherwise the latest ryu-manager can pick up older modules
if multiple versions of ryu is installed on a system.
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/hooks.py | 29 | ||||
-rw-r--r-- | setup.py | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/ryu/hooks.py b/ryu/hooks.py index c2414cdb..3883a7d2 100644 --- a/ryu/hooks.py +++ b/ryu/hooks.py @@ -16,9 +16,25 @@ # under the License. import sys +from setuptools.command import easy_install from ryu import version +# Global variables in this module doesn't work as we expect +# because, during the setup procedure, this module seems to be +# copied (as a file) and can be loaded multiple times. +# We save them into __main__ module instead. +def _main_module(): + return sys.modules['__main__'] + + +def save_orig(): + """Save original easy_install.get_script_args. + This is necessary because pbr's setup_hook is sometimes called + before ours.""" + _main_module()._orig_get_script_args = easy_install.get_script_args + + def setup_hook(config): """Filter config parsed from a setup.cfg to inject our defaults.""" metadata = config['metadata'] @@ -31,3 +47,16 @@ def setup_hook(config): config['metadata'] = metadata metadata['version'] = str(version) + + # pbr's setup_hook replaces easy_install.get_script_args with + # their own version, override_get_script_args, prefering simpler + # scripts which are not aware of multi-version. + # prevent that by doing the opposite. it's a horrible hack + # but we are in patching wars already... + from pbr import packaging + + def my_get_script_args(*args, **kwargs): + return _main_module()._orig_get_script_args(*args, **kwargs) + + packaging.override_get_script_args = my_get_script_args + easy_install.get_script_args = my_get_script_args @@ -21,8 +21,10 @@ except ImportError: pass import setuptools +import ryu.hooks +ryu.hooks.save_orig() setuptools.setup(name='ryu', setup_requires=['pbr'], pbr=True) |