1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
3 # Copyright 2013 Hewlett-Packard Development Company, L.P.
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
20 from setuptools.command import easy_install
21 from ryu import version
24 # Global variables in this module doesn't work as we expect
25 # because, during the setup procedure, this module seems to be
26 # copied (as a file) and can be loaded multiple times.
27 # We save them into __main__ module instead.
29 return sys.modules['__main__']
33 """Save original easy_install.get_script_args.
34 This is necessary because pbr's setup_hook is sometimes called
36 _main_module()._orig_get_script_args = easy_install.get_script_args
39 def setup_hook(config):
40 """Filter config parsed from a setup.cfg to inject our defaults."""
41 metadata = config['metadata']
42 if sys.platform == 'win32':
43 requires = metadata.get('requires_dist', '').split('\n')
44 metadata['requires_dist'] = "\n".join(requires)
45 config['metadata'] = metadata
47 metadata['version'] = str(version)
49 # pbr's setup_hook replaces easy_install.get_script_args with
50 # their own version, override_get_script_args, prefering simpler
51 # scripts which are not aware of multi-version.
52 # prevent that by doing the opposite. it's a horrible hack
53 # but we are in patching wars already...
54 from pbr import packaging
56 def my_get_script_args(*args, **kwargs):
57 return _main_module()._orig_get_script_args(*args, **kwargs)
59 packaging.override_get_script_args = my_get_script_args
60 easy_install.get_script_args = my_get_script_args
62 # another hack to allow setup from tarball.
63 orig_get_version = packaging.get_version
65 def my_get_version(package_name, pre_version=None):
66 if package_name == 'ryu':
68 return orig_get_version(package_name, pre_version)
70 packaging.get_version = my_get_version