Merge "Support repodir config files"
This commit is contained in:
commit
7ab07f1d26
|
@ -174,13 +174,13 @@ correctness.
|
|||
Configuring Reno
|
||||
================
|
||||
|
||||
Reno looks for an optional ``config.yaml`` file in the release notes
|
||||
directory. If the values in the configuration file do not apply to
|
||||
the command being run, they are ignored. For example, some reno
|
||||
commands take inputs controlling the branch, earliest revision, and
|
||||
other common parameters that control which notes are included in the
|
||||
output. Because they are commonly set options, a configuration file
|
||||
may be the most convenient way to manage the values consistently.
|
||||
Reno looks for an optional config file, either ``config.yaml`` in the release
|
||||
notes directory or ``reno.yaml`` in the root directory. If the values in the
|
||||
configuration file do not apply to the command being run, they are ignored. For
|
||||
example, some reno commands take inputs controlling the branch, earliest
|
||||
revision, and other common parameters that control which notes are included in
|
||||
the output. Because they are commonly set options, a configuration file may be
|
||||
the most convenient way to manage the values consistently.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
reno will now scan for a ``reno.yaml`` file in the root repo directory if a
|
||||
``config.yaml`` file does not exist in the releasenotes directory. This
|
||||
allows users to do away with the unnecessary ``notes`` subdirectory in the
|
||||
releasenotes directory.
|
|
@ -9,7 +9,7 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import errno
|
||||
|
||||
import logging
|
||||
import os.path
|
||||
|
||||
|
@ -90,8 +90,6 @@ other:
|
|||
|
||||
class Config(object):
|
||||
|
||||
_FILENAME = 'config.yaml'
|
||||
|
||||
_OPTS = {
|
||||
# The notes subdirectory within the relnotesdir where the
|
||||
# notes live.
|
||||
|
@ -191,7 +189,6 @@ class Config(object):
|
|||
:param str relnotesdir:
|
||||
The directory containing release notes. Defaults to
|
||||
'releasenotes'.
|
||||
|
||||
"""
|
||||
self.reporoot = reporoot
|
||||
if relnotesdir is None:
|
||||
|
@ -200,22 +197,26 @@ class Config(object):
|
|||
# Initialize attributes from the defaults.
|
||||
self.override(**self._OPTS)
|
||||
|
||||
self._filename = os.path.join(self.reporoot, relnotesdir,
|
||||
self._FILENAME)
|
||||
self._contents = {}
|
||||
self._load_file()
|
||||
|
||||
def _load_file(self):
|
||||
filenames = [
|
||||
os.path.join(self.reporoot, self.relnotesdir, 'config.yaml'),
|
||||
os.path.join(self.reporoot, 'reno.yaml')]
|
||||
|
||||
for filename in filenames:
|
||||
if os.path.isfile(filename):
|
||||
break
|
||||
else:
|
||||
LOG.info('no configuration file in: %s', ', '.join(filenames))
|
||||
return
|
||||
|
||||
try:
|
||||
with open(self._filename, 'r') as fd:
|
||||
with open(filename, 'r') as fd:
|
||||
self._contents = yaml.safe_load(fd)
|
||||
except IOError as err:
|
||||
if err.errno == errno.ENOENT:
|
||||
LOG.info('no configuration file in %s',
|
||||
self._filename)
|
||||
else:
|
||||
LOG.warning('did not load config file %s: %s',
|
||||
self._filename, err)
|
||||
LOG.warning('did not load config file %s: %s', filename, err)
|
||||
else:
|
||||
self.override(**self._contents)
|
||||
|
||||
|
|
|
@ -77,17 +77,23 @@ collapse_pre_releases: false
|
|||
config.Config(self.tempdir.path)
|
||||
self.assertEqual(1, logger.call_count)
|
||||
|
||||
def test_load_file(self):
|
||||
rn_path = self.tempdir.join('releasenotes')
|
||||
os.mkdir(rn_path)
|
||||
config_path = self.tempdir.join('releasenotes/' +
|
||||
config.Config._FILENAME)
|
||||
def _test_load_file(self, config_path):
|
||||
with open(config_path, 'w') as fd:
|
||||
fd.write(self.EXAMPLE_CONFIG)
|
||||
self.addCleanup(os.unlink, config_path)
|
||||
c = config.Config(self.tempdir.path)
|
||||
self.assertEqual(False, c.collapse_pre_releases)
|
||||
|
||||
def test_load_file_in_releasenotesdir(self):
|
||||
rn_path = self.tempdir.join('releasenotes')
|
||||
os.mkdir(rn_path)
|
||||
config_path = self.tempdir.join('releasenotes/config.yaml')
|
||||
self._test_load_file(config_path)
|
||||
|
||||
def test_load_file_in_repodir(self):
|
||||
config_path = self.tempdir.join('reno.yaml')
|
||||
self._test_load_file(config_path)
|
||||
|
||||
def test_get_default(self):
|
||||
d = config.Config.get_default('notesdir')
|
||||
self.assertEqual('notes', d)
|
||||
|
|
Loading…
Reference in New Issue