Skip to content

Commit d6a9890

Browse files
yamtfujita
authored andcommitted
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 <[email protected]> Signed-off-by: FUJITA Tomonori <[email protected]>
1 parent 9159bd7 commit d6a9890

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ryu/hooks.py

+29
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,25 @@
1616
# under the License.
1717

1818
import sys
19+
from setuptools.command import easy_install
1920
from ryu import version
2021

2122

23+
# Global variables in this module doesn't work as we expect
24+
# because, during the setup procedure, this module seems to be
25+
# copied (as a file) and can be loaded multiple times.
26+
# We save them into __main__ module instead.
27+
def _main_module():
28+
return sys.modules['__main__']
29+
30+
31+
def save_orig():
32+
"""Save original easy_install.get_script_args.
33+
This is necessary because pbr's setup_hook is sometimes called
34+
before ours."""
35+
_main_module()._orig_get_script_args = easy_install.get_script_args
36+
37+
2238
def setup_hook(config):
2339
"""Filter config parsed from a setup.cfg to inject our defaults."""
2440
metadata = config['metadata']
@@ -31,3 +47,16 @@ def setup_hook(config):
3147
config['metadata'] = metadata
3248

3349
metadata['version'] = str(version)
50+
51+
# pbr's setup_hook replaces easy_install.get_script_args with
52+
# their own version, override_get_script_args, prefering simpler
53+
# scripts which are not aware of multi-version.
54+
# prevent that by doing the opposite. it's a horrible hack
55+
# but we are in patching wars already...
56+
from pbr import packaging
57+
58+
def my_get_script_args(*args, **kwargs):
59+
return _main_module()._orig_get_script_args(*args, **kwargs)
60+
61+
packaging.override_get_script_args = my_get_script_args
62+
easy_install.get_script_args = my_get_script_args

setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
pass
2222

2323
import setuptools
24+
import ryu.hooks
2425

2526

27+
ryu.hooks.save_orig()
2628
setuptools.setup(name='ryu',
2729
setup_requires=['pbr'],
2830
pbr=True)

0 commit comments

Comments
 (0)