let the Config object give us the path to the notes

Add a property to combine the release notes subdirectory and the notes
directory within it to build the path to look for notes files. Remove
the old utils function for doing the same work.

Change-Id: I7f6aa8c7e59f6e4559a583cad4b9bc5b574c77e0
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2016-07-22 17:12:27 -04:00
parent d32fda8b34
commit 0355be32b4
10 changed files with 15 additions and 23 deletions

View File

@ -114,6 +114,10 @@ class Config(object):
def reporoot(self, value):
self._reporoot = value.rstrip('/') + '/'
@property
def notespath(self):
"The path in the repo where notes are kept."
return os.path.join(self.relnotesdir, self.notesdir)
# def parse_config_into(parsed_arguments):

View File

@ -122,7 +122,6 @@ def _make_note_file(filename):
def create_cmd(args, conf):
"Create a new release note file from the template."
notesdir = utils.get_notes_dir(conf)
# NOTE(dhellmann): There is a short race window where we might try
# to pick a name that does not exist, then overwrite the file if
# it is created before we try to write it. This isn't a problem
@ -130,7 +129,7 @@ def create_cmd(args, conf):
# their local git tree, and so there should not be any concurrency
# concern.
slug = args.slug.replace(' ', '-')
filename = _pick_note_file_name(notesdir, slug)
filename = _pick_note_file_name(conf.notespath, slug)
_make_note_file(filename)
print('Created new notes file in %s' % filename)
return

View File

@ -15,7 +15,6 @@ from __future__ import print_function
import logging
from reno import loader
from reno import utils
LOG = logging.getLogger(__name__)
@ -24,11 +23,9 @@ def list_cmd(args, conf):
"List notes files based on query arguments"
LOG.debug('starting list')
reporoot = conf.reporoot
notesdir = utils.get_notes_dir(conf)
collapse = conf.collapse_pre_releases
ldr = loader.Loader(
reporoot=reporoot,
notesdir=notesdir,
branch=conf.branch,
collapse_pre_releases=collapse,
earliest_version=conf.earliest_version,

View File

@ -28,7 +28,7 @@ def get_cache_filename(reporoot, notesdir):
class Loader(object):
"Load the release notes for a given repository."
def __init__(self, reporoot, notesdir, branch=None,
def __init__(self, reporoot, branch=None,
collapse_pre_releases=True,
earliest_version=None,
ignore_cache=False,
@ -42,8 +42,6 @@ class Loader(object):
:param reporoot: Path to the root of the git repository.
:type reporoot: str
:param notesdir: The directory under *reporoot* with the release notes.
:type notesdir: str
:param branch: The name of the branch to scan. Defaults to current.
:type branch: str
:param collapse_pre_releases: When true, merge pre-release versions
@ -57,7 +55,7 @@ class Loader(object):
:type conf: reno.config.Config
"""
self._reporoot = reporoot
self._notesdir = notesdir
self._notespath = conf.notespath
self._branch = branch
self._config = conf
self._collapse_pre_releases = self._config.collapse_pre_releases
@ -66,7 +64,7 @@ class Loader(object):
self._cache = None
self._scanner_output = None
self._cache_filename = get_cache_filename(reporoot, notesdir)
self._cache_filename = get_cache_filename(reporoot, self._notespath)
self._load_data()
@ -89,7 +87,7 @@ class Loader(object):
else:
self._scanner_output = scanner.get_notes_by_version(
reporoot=self._reporoot,
notesdir=self._notesdir,
notesdir=self._notespath,
branch=self._branch,
collapse_pre_releases=self._collapse_pre_releases,
earliest_version=self._earliest_version,

View File

@ -14,17 +14,14 @@ from __future__ import print_function
from reno import formatter
from reno import loader
from reno import utils
def report_cmd(args, conf):
"Generates a release notes report"
reporoot = conf.reporoot
notesdir = utils.get_notes_dir(conf)
collapse = conf.collapse_pre_releases
ldr = loader.Loader(
reporoot=reporoot,
notesdir=notesdir,
branch=conf.branch,
collapse_pre_releases=collapse,
earliest_version=conf.earliest_version,

View File

@ -74,7 +74,6 @@ class ReleaseNotesDirective(rst.Directive):
ldr = loader.Loader(
reporoot=conf.reporoot,
notesdir=notesdir,
branch=branch,
collapse_pre_releases=conf.collapse_pre_releases,
earliest_version=conf.earliest_version,

View File

@ -141,10 +141,15 @@ class TestConfigProperties(base.TestCase):
super(TestConfigProperties, self).setUp()
# Temporary directory to store our config
self.tempdir = self.useFixture(fixtures.TempDir())
self.c = config.Config(self.tempdir.path)
self.c = config.Config('releasenotes')
def test_reporoot(self):
self.c.reporoot = 'blah//'
self.assertEqual('blah/', self.c.reporoot)
self.c.reporoot = 'blah'
self.assertEqual('blah/', self.c.reporoot)
def test_notespath(self):
self.assertEqual('releasenotes/notes', self.c.notespath)
self.c.override(notesdir='thenotes')
self.assertEqual('releasenotes/thenotes', self.c.notespath)

View File

@ -62,7 +62,6 @@ class TestFormatter(base.TestCase):
with mock.patch('reno.loader.Loader._load_data', _load):
self.ldr = loader.Loader(
reporoot='reporoot',
notesdir='notesdir',
branch=None,
collapse_pre_releases=None,
earliest_version=None,

View File

@ -52,7 +52,6 @@ class TestValidate(base.TestCase):
with mock.patch('reno.loader.Loader._load_data', _load):
return loader.Loader(
reporoot='reporoot',
notesdir='notesdir',
branch=None,
collapse_pre_releases=None,
earliest_version=None,

View File

@ -20,11 +20,6 @@ import subprocess
LOG = logging.getLogger(__name__)
def get_notes_dir(conf):
"""Return the path to the release notes directory."""
return os.path.join(conf.relnotesdir, conf.notesdir)
def get_random_string(nbytes=8):
"""Return a fixed-length random string