Skip to content

Commit

Permalink
Ran black on changelog.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsvanrees committed Aug 16, 2019
1 parent 10513b2 commit 27f43e2
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions plone/releaser/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

def pull_versions(version_number):
package_versions = OrderedDict()
if version_number == 'here':
url = 'versions.cfg'
if version_number == "here":
url = "versions.cfg"
versions_file = open(url)
else:
url = DIST_URL.format(version_number)
Expand All @@ -28,7 +28,7 @@ def pull_versions(version_number):
raise ValueError("Version %s not found." % version_number)
for line in versions_file:
line = line.strip().replace(" ", "")
if line and not (line.startswith('#') or line.startswith('[')):
if line and not (line.startswith("#") or line.startswith("[")):
try:
package, version = line.split("=")
version = LooseVersion(version)
Expand All @@ -48,28 +48,25 @@ def get_source_location(package_name):
# to this:
# https://raw.githubusercontent.com/plone/plone.batching
url = source.url
url = url.replace('git:', 'https:')
url = url.replace('.git', '')
url = url.replace('github.com', 'raw.githubusercontent.com')
url = url.replace("git:", "https:")
url = url.replace(".git", "")
url = url.replace("github.com", "raw.githubusercontent.com")
return url, source.branch
return "", ""


def get_changelog(package_name):
source_url, branch = get_source_location(package_name)
if not source_url:
return ''
file_names = ['CHANGES', 'HISTORY']
file_extensions = ['.rst', '.txt']
if 'github' in source_url:
paths = [
'{0}/'.format(branch),
'{0}/docs/'.format(branch),
]
return ""
file_names = ["CHANGES", "HISTORY"]
file_extensions = [".rst", ".txt"]
if "github" in source_url:
paths = ["{0}/".format(branch), "{0}/docs/".format(branch)]
else:
paths = ['/', '/docs/', '/'.join(package_name.split('.')) + '/']
paths = ["/", "/docs/", "/".join(package_name.split(".")) + "/"]
for pathable in product(paths, file_names, file_extensions):
structure = ''.join(pathable)
structure = "".join(pathable)
url = "{0}/{1}".format(source_url, structure)
try:
response = urllib.urlopen(url)
Expand All @@ -78,17 +75,16 @@ def get_changelog(package_name):
else:
if response.code == 200:
return response.read()
return ''
return ""


class Changelog(object):

def __init__(self, file_location=None, content=None):
self.data = OrderedDict()
if content is not None:
self._parse(content)
elif file_location is not None:
with open(file_location, 'r') as f:
with open(file_location, "r") as f:
self._parse(f.read())

def __iter__(self):
Expand Down Expand Up @@ -120,9 +116,9 @@ def get_changes(self, start_version, end_version=None):
for key, entries in self.data[release].items():
changes[key].extend(entries)
result = []
for key in HEADINGS + ['other']:
for key in HEADINGS + ["other"]:
if key in changes:
if key != 'other':
if key != "other":
result.append(key)
result.extend(changes.pop(key))
return result
Expand All @@ -138,34 +134,34 @@ def _parse(self, content):
def is_valid_version_section(x):
if x.tagname == "section":
try:
LooseVersion(x['names'][0].split()[0])
LooseVersion(x["names"][0].split()[0])
except (ValueError, IndexError):
pass
else:
return True
return False

def heading(x):
if x.tagname != 'paragraph':
return ''
if x.tagname != "paragraph":
return ""
if x.rawsource in HEADINGS:
return x.rawsource
# Might be an old heading or unknown.
return OLD_HEADING_MAPPING.get(x.rawsource, '')
return OLD_HEADING_MAPPING.get(x.rawsource, "")

def is_list_item(x):
return x.tagname == 'list_item'
return x.tagname == "list_item"

found_sections = tree.traverse(condition=is_valid_version_section)
for section in found_sections:
version = section['names'][0].split()[0]
version = section["names"][0].split()[0]
# Look for paragraph headings.
# When two are found, we have a section with:
# paragraph 1, bullet_list 1, paragraph 2, bullet_list 2.
# But a single bullet_list is handled fine too.
# Put items in dictionary, with the headings as possible keys.
entries = defaultdict(list)
current = 'other'
current = "other"
for child in section.children:
child_heading = heading(child)
if child_heading:
Expand Down Expand Up @@ -193,13 +189,15 @@ def build_unified_changelog(start_version, end_version):
if version > prior_version:
print("{0} has a newer version".format(package))
packageChange = u"{0}: {1} {2} {3}".format(
package,
prior_version,
u"\u2192",
version
package, prior_version, u"\u2192", version
)
output_str += (
u"\n"
+ packageChange
+ u"\n"
+ u"-" * len(packageChange)
+ "\n"
)
output_str += u"\n" + packageChange + \
u"\n" + u"-" * len(packageChange) + "\n"

logtext = get_changelog(package)
if not logtext:
Expand All @@ -217,12 +215,13 @@ def build_unified_changelog(start_version, end_version):
output_str += change + u"\n\n"
else:
change = change.replace(
"\n", "\n" + " " * len(bullet))
"\n", "\n" + " " * len(bullet)
)
output_str += bullet + change + u"\n\n"
except AttributeError as e:
# Bad version line, skip
pass
except KeyboardInterrupt:
pass

print(output_str.encode('utf-8'))
print(output_str.encode("utf-8"))

0 comments on commit 27f43e2

Please sign in to comment.