Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / ryu / .eggs / pbr-5.3.1-py2.7.egg / pbr / sphinxext.py
1 # Copyright 2018 Red Hat, Inc.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 import os.path
17
18 from six.moves import configparser
19 from sphinx.util import logging
20
21 import pbr.version
22
23 _project = None
24 logger = logging.getLogger(__name__)
25
26
27 def _find_setup_cfg(srcdir):
28     """Find the 'setup.cfg' file, if it exists.
29
30     This assumes we're using 'doc/source' for documentation, but also allows
31     for single level 'doc' paths.
32     """
33     # TODO(stephenfin): Are we sure that this will always exist, e.g. for
34     # an sdist or wheel? Perhaps we should check for 'PKG-INFO' or
35     # 'METADATA' files, a la 'pbr.packaging._get_version_from_pkg_metadata'
36     for path in [
37             os.path.join(srcdir, os.pardir, 'setup.cfg'),
38             os.path.join(srcdir, os.pardir, os.pardir, 'setup.cfg')]:
39         if os.path.exists(path):
40             return path
41
42     return None
43
44
45 def _get_project_name(srcdir):
46     """Return string name of project name, or None.
47
48     This extracts metadata from 'setup.cfg'. We don't rely on
49     distutils/setuptools as we don't want to actually install the package
50     simply to build docs.
51     """
52     global _project
53
54     if _project is None:
55         parser = configparser.ConfigParser()
56
57         path = _find_setup_cfg(srcdir)
58         if not path or not parser.read(path):
59             logger.info('Could not find a setup.cfg to extract project name '
60                         'from')
61             return None
62
63         try:
64             # for project name we use the name in setup.cfg, but if the
65             # length is longer then 32 we use summary. Otherwise thAe
66             # menu rendering looks brolen
67             project = parser.get('metadata', 'name')
68             if len(project.split()) == 1 and len(project) > 32:
69                 project = parser.get('metadata', 'summary')
70         except configparser.Error:
71             logger.info('Could not extract project metadata from setup.cfg')
72             return None
73
74         _project = project
75
76     return _project
77
78
79 def _builder_inited(app):
80     # TODO(stephenfin): Once Sphinx 1.8 is released, we should move the below
81     # to a 'config-inited' handler
82
83     project_name = _get_project_name(app.srcdir)
84     try:
85         version_info = pbr.version.VersionInfo(project_name)
86     except Exception:
87         version_info = None
88
89     if version_info and not app.config.version and not app.config.release:
90         app.config.version = version_info.canonical_version_string()
91         app.config.release = version_info.version_string_with_vcs()
92
93
94 def setup(app):
95     app.connect('builder-inited', _builder_inited)
96     return {
97         'parallel_read_safe': True,
98         'parallel_write_safe': True,
99     }