Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / ryu / .eggs / pbr-5.3.1-py2.7.egg / pbr / core.py
1 # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # Copyright (C) 2013 Association of Universities for Research in Astronomy
17 #                    (AURA)
18 #
19 # Redistribution and use in source and binary forms, with or without
20 # modification, are permitted provided that the following conditions are met:
21 #
22 #     1. Redistributions of source code must retain the above copyright
23 #        notice, this list of conditions and the following disclaimer.
24 #
25 #     2. Redistributions in binary form must reproduce the above
26 #        copyright notice, this list of conditions and the following
27 #        disclaimer in the documentation and/or other materials provided
28 #        with the distribution.
29 #
30 #     3. The name of AURA and its representatives may not be used to
31 #        endorse or promote products derived from this software without
32 #        specific prior written permission.
33 #
34 # THIS SOFTWARE IS PROVIDED BY AURA ``AS IS'' AND ANY EXPRESS OR IMPLIED
35 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
36 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 # DISCLAIMED. IN NO EVENT SHALL AURA BE LIABLE FOR ANY DIRECT, INDIRECT,
38 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40 # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
42 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
43 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
44 # DAMAGE.
45
46 import logging
47 import os
48 import sys
49 import warnings
50
51 from distutils import errors
52
53 from pbr import util
54
55
56 if sys.version_info[0] == 3:
57     string_type = str
58     integer_types = (int,)
59 else:
60     string_type = basestring  # noqa
61     integer_types = (int, long)  # noqa
62
63
64 def pbr(dist, attr, value):
65     """Implements the actual pbr setup() keyword.
66
67     When used, this should be the only keyword in your setup() aside from
68     `setup_requires`.
69
70     If given as a string, the value of pbr is assumed to be the relative path
71     to the setup.cfg file to use.  Otherwise, if it evaluates to true, it
72     simply assumes that pbr should be used, and the default 'setup.cfg' is
73     used.
74
75     This works by reading the setup.cfg file, parsing out the supported
76     metadata and command options, and using them to rebuild the
77     `DistributionMetadata` object and set the newly added command options.
78
79     The reason for doing things this way is that a custom `Distribution` class
80     will not play nicely with setup_requires; however, this implementation may
81     not work well with distributions that do use a `Distribution` subclass.
82     """
83
84     if not value:
85         return
86     if isinstance(value, string_type):
87         path = os.path.abspath(value)
88     else:
89         path = os.path.abspath('setup.cfg')
90     if not os.path.exists(path):
91         raise errors.DistutilsFileError(
92             'The setup.cfg file %s does not exist.' % path)
93
94     # Converts the setup.cfg file to setup() arguments
95     try:
96         attrs = util.cfg_to_args(path, dist.script_args)
97     except Exception:
98         e = sys.exc_info()[1]
99         # NB: This will output to the console if no explicit logging has
100         # been setup - but thats fine, this is a fatal distutils error, so
101         # being pretty isn't the #1 goal.. being diagnosable is.
102         logging.exception('Error parsing')
103         raise errors.DistutilsSetupError(
104             'Error parsing %s: %s: %s' % (path, e.__class__.__name__, e))
105
106     # There are some metadata fields that are only supported by
107     # setuptools and not distutils, and hence are not in
108     # dist.metadata.  We are OK to write these in.  For gory details
109     # see
110     #  https://github.com/pypa/setuptools/pull/1343
111     _DISTUTILS_UNSUPPORTED_METADATA = (
112         'long_description_content_type', 'project_urls', 'provides_extras'
113     )
114
115     # Repeat some of the Distribution initialization code with the newly
116     # provided attrs
117     if attrs:
118         # Skips 'options' and 'licence' support which are rarely used; may
119         # add back in later if demanded
120         for key, val in attrs.items():
121             if hasattr(dist.metadata, 'set_' + key):
122                 getattr(dist.metadata, 'set_' + key)(val)
123             elif hasattr(dist.metadata, key):
124                 setattr(dist.metadata, key, val)
125             elif hasattr(dist, key):
126                 setattr(dist, key, val)
127             elif key in _DISTUTILS_UNSUPPORTED_METADATA:
128                 setattr(dist.metadata, key, val)
129             else:
130                 msg = 'Unknown distribution option: %s' % repr(key)
131                 warnings.warn(msg)
132
133     # Re-finalize the underlying Distribution
134     try:
135         super(dist.__class__, dist).finalize_options()
136     except TypeError:
137         # If dist is not declared as a new-style class (with object as
138         # a subclass) then super() will not work on it. This is the case
139         # for Python 2. In that case, fall back to doing this the ugly way
140         dist.__class__.__bases__[-1].finalize_options(dist)
141
142     # This bit comes out of distribute/setuptools
143     if isinstance(dist.metadata.version, integer_types + (float,)):
144         # Some people apparently take "version number" too literally :)
145         dist.metadata.version = str(dist.metadata.version)