backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / hooks.py
1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3 # Copyright 2013 Hewlett-Packard Development Company, L.P.
4 # All Rights Reserved.
5 #
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
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
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
16 # under the License.
17
18 import os
19 import sys
20 from setuptools.command import easy_install
21 from ryu import version
22
23
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.
28 def _main_module():
29     return sys.modules['__main__']
30
31
32 def save_orig():
33     """Save original easy_install.get_script_args.
34     This is necessary because pbr's setup_hook is sometimes called
35     before ours."""
36     _main_module()._orig_get_script_args = easy_install.get_script_args
37
38
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
46
47     metadata['version'] = str(version)
48
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
55
56     def my_get_script_args(*args, **kwargs):
57         return _main_module()._orig_get_script_args(*args, **kwargs)
58
59     packaging.override_get_script_args = my_get_script_args
60     easy_install.get_script_args = my_get_script_args
61
62     # another hack to allow setup from tarball.
63     orig_get_version = packaging.get_version
64
65     def my_get_version(package_name, pre_version=None):
66         if package_name == 'ryu':
67             return str(version)
68         return orig_get_version(package_name, pre_version)
69
70     packaging.get_version = my_get_version