update sphinxext to use deliverable model classes

Change-Id: I38c8147677b37df2b6e0e995455dbd96099a3eb4
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-03-01 12:57:55 -05:00
parent 9b8f290117
commit 1b736e3f32
3 changed files with 65 additions and 51 deletions

View File

@ -180,7 +180,7 @@ class Deliverables(object):
else:
filenames = self._by_team_and_series[(team, series)]
for filename in filenames:
yield (
yield Deliverable(
team,
self._series_from_filename(filename),
self._deliverable_from_filename(filename),
@ -223,6 +223,10 @@ class Repo(object):
def pypi_name(self):
return self._data.get('pypi-name')
@property
def base_name(self):
return self.name.rsplit('/')[-1]
def __eq__(self, other):
return self.name == other.name
@ -247,6 +251,9 @@ class ReleaseProject(object):
def tarball_base(self):
return self._data.get('tarball-base')
def guess_sdist_name(self):
return self.tarball_base or self.repo.base_name
def __eq__(self, other):
return self.repo == other.repo
@ -420,6 +427,12 @@ class Deliverable(object):
def artifact_link_mode(self):
return self._data.get('artifact-link-mode', 'tarball')
@property
def earliest_release(self):
if not self.is_released:
return ''
return self.releases[0].version
@property
def latest_release(self):
if not self.is_released:
@ -485,6 +498,10 @@ class Deliverable(object):
def stable_branch_type(self):
return self._data.get('stable-branch-type', 'std')
@property
def cycle_highlights(self):
return self._data.get('cycle-highlights', [])
def __eq__(self, other):
return self.name == other.name

View File

@ -33,8 +33,8 @@ def link_exists(url):
def tarball_url(version, project):
repo_base = project['repo'].rsplit('/')[-1]
base = project.get('tarball-base', repo_base)
repo_base = project.repo.base_name
base = project.tarball_base or repo_base
return '{s}/{r}/{n}-{v}.tar.gz'.format(
s='https://tarballs.openstack.org',
v=version,
@ -44,8 +44,8 @@ def tarball_url(version, project):
def wheel_py2_url(version, project):
repo_base = project['repo'].rsplit('/')[-1]
base = project.get('tarball-base', repo_base)
repo_base = project.repo.base_name
base = project.tarball_base or repo_base
return '{s}/{r}/{n}-{v}-py2-none-any.whl'.format(
s='https://tarballs.openstack.org',
v=version,
@ -55,8 +55,8 @@ def wheel_py2_url(version, project):
def wheel_both_url(version, project):
repo_base = project['repo'].rsplit('/')[-1]
base = project.get('tarball-base', repo_base)
repo_base = project.repo.base_name
base = project.tarball_base or repo_base
return '{s}/{r}/{n}-{v}-py2.py3-none-any.whl'.format(
s='https://tarballs.openstack.org',
v=version,
@ -65,8 +65,8 @@ def wheel_both_url(version, project):
)
def artifact_link(version, project, deliverable_info):
mode = deliverable_info.get('artifact-link-mode', 'tarball')
def artifact_link(version, project, deliv):
mode = deliv.artifact_link_mode
if mode == 'tarball':
# Link the version number to the tarball for downloading.
url = tarball_url(version, project)
@ -82,8 +82,8 @@ def signature_url(version, project):
return tb_url + '.asc'
def artifact_signature_link(version, type, project, deliverable_info):
mode = deliverable_info.get('artifact-link-mode', 'tarball')
def artifact_signature_link(version, type, project, deliv):
mode = deliv.artifact_link_mode
if mode == 'tarball':
url = signature_url(version, project)
# Link the signature type to the tarball for downloading.

View File

@ -60,11 +60,11 @@ def _list_table(add, headers, data, title='', columns=None):
add('')
def _get_category(data):
model = data.get('release-model')
def _get_category(deliv):
model = deliv.model
if model == 'cycle-trailing':
return 'cycle-trailing'
return data.get('type', 'other')
return deliv.type
_deliverables = None
@ -117,12 +117,12 @@ class DeliverableDirectiveBase(rst.Directive):
# are organized by series but not type.
d_source = itertools.groupby(
sorted(_deliverables.get_deliverables(self.team_name, series)),
key=operator.itemgetter(1) # the series
key=operator.attrgetter('series')
)
for s, d in d_source:
self._add_deliverables(
None,
((i[2], i[3]) for i in d), # only name and info
d,
s,
app,
result,
@ -132,8 +132,8 @@ class DeliverableDirectiveBase(rst.Directive):
# shown. They are categorized by type, which we need to
# extract from the data.
raw_deliverables = [
(_get_category(_data), _deliv_name, _data)
for _team, _series, _deliv_name, _data in _deliverables.get_deliverables(
(_get_category(deliv), deliv)
for deliv in _deliverables.get_deliverables(
self.team_name,
series,
)
@ -148,12 +148,13 @@ class DeliverableDirectiveBase(rst.Directive):
by_category = {}
for deliverable_category, deliverables in grouped:
by_category[deliverable_category] = [
(d[1], d[2])
d[1]
for d in deliverables
]
for category in self._CATEGORY_ORDER:
if category not in by_category:
app.info('No %r for %s' % (category, (self.team_name, series)))
app.info('No %r for %s' % (category,
(self.team_name, series)))
continue
self._add_deliverables(
category,
@ -185,11 +186,11 @@ class DeliverableDirectiveBase(rst.Directive):
# expand any generators passed in and filter out deliverables
# with no releases
deliverables = list(
deliverables = [
d
for d in deliverables
if d[1].get('releases')
)
if d.releases
]
if not deliverables:
# There are no deliverables of this type, and that's OK.
return
@ -206,13 +207,11 @@ class DeliverableDirectiveBase(rst.Directive):
# deliverable.
if not self.team_name:
most_recent = []
for deliverable_name, deliverable_info in deliverables:
earliest_version = deliverable_info.get('releases', {})[0].get(
'version', 'unreleased')
recent_version = deliverable_info.get('releases', {})[-1].get(
'version', 'unreleased')
ref = ':ref:`%s-%s`' % (series, deliverable_name)
release_notes = deliverable_info.get('release-notes')
for deliv in deliverables:
earliest_version = deliv.earliest_release
recent_version = deliv.latest_release
ref = ':ref:`%s-%s`' % (series, deliv.name)
release_notes = deliv.release_notes
if not release_notes:
notes_link = ''
elif isinstance(release_notes, dict):
@ -235,12 +234,12 @@ class DeliverableDirectiveBase(rst.Directive):
# Show the detailed history of the deliverables within the series.
for deliverable_name, deliverable_info in deliverables:
for deliv in deliverables:
# These closures need to be redefined in each iteration of
# the loop because they use the deliverable name.
def _add(text):
result.append(text, '%s/%s' % (series, deliverable_name))
result.append(text, '%s/%s' % (series, deliv.name))
def _title(text, underline):
text = str(text) # version numbers might be seen as floats
@ -253,12 +252,12 @@ class DeliverableDirectiveBase(rst.Directive):
_add(underline * len(text))
_add('')
_title(deliverable_name, '=')
_title(deliv.name, '=')
app.info('[deliverables] rendering %s (%s)' %
(deliverable_name, series))
(deliv.name, series))
release_notes = deliverable_info.get('release-notes')
release_notes = deliv.release_notes
if not release_notes:
notes_link = None
elif isinstance(release_notes, dict):
@ -267,7 +266,7 @@ class DeliverableDirectiveBase(rst.Directive):
for n, v in sorted(release_notes.items())
)
else:
notes_link = '`%s <%s>`__' % (deliverable_name, release_notes)
notes_link = '`%s <%s>`__' % (deliv.name, release_notes)
if notes_link:
_add('')
_add('Release Notes: %s' % notes_link)
@ -275,22 +274,21 @@ class DeliverableDirectiveBase(rst.Directive):
# We have signatures for artifacts only after newton
if series and series[0] >= 'o':
headers = ['Version', 'Signature', 'Repo', 'Git Commit']
data = ((links.artifact_link(r['version'], p,
deliverable_info),
links.artifact_signature_link(r['version'],
data = ((links.artifact_link(r.version, p, deliv),
links.artifact_signature_link(r.version,
'pgp', p,
deliverable_info),
p['repo'], p['hash'])
for r in reversed(deliverable_info.get('releases', []))
for p in r.get('projects', []))
deliv),
p.repo, p.hash)
for r in reversed(deliv.releases)
for p in r.projects)
columns = [10, 10, 40, 50]
else:
headers = ['Version', 'Repo', 'Git Commit']
data = ((links.artifact_link(r['version'], p,
deliverable_info),
p['repo'], p['hash'])
for r in reversed(deliverable_info.get('releases', []))
for p in r.get('projects', []))
data = ((links.artifact_link(r.version, p,
deliv),
p.repo, p.hash)
for r in reversed(deliv.releases)
for p in r.projects)
columns = [10, 40, 50]
_list_table(
_add,
@ -402,10 +400,9 @@ class HighlightsDirective(rst.Directive):
series_highlights = defaultdict(list)
series_deliverables = _deliverables.get_deliverables(None, series)
for deliv in series_deliverables:
series_info = deliv[3]
highlights = series_info.get('cycle-highlights', [])
highlights = deliv.cycle_highlights
for item in highlights:
series_highlights[series_info['team']].append(item)
series_highlights[deliv.team].append(item)
return series_highlights