Last active
October 16, 2019 20:45
-
-
Save mauritsvanrees/b30c9a8ff7075bfc38e873f03c9ebefe to your computer and use it in GitHub Desktop.
News snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Original: https://gist.github.com/mauritsvanrees/b30c9a8ff7075bfc38e873f03c9ebefe | |
# | |
# Sometimes towncrier is just too hard to understand, or it does too much, | |
# or the combination with zest.releaser is too restricting, | |
# especially when you want to make some manual edits after running towncrier. | |
# So try something out. | |
# Ideas for commands: | |
# - newssnippet create: create a news snippet with a correct name, compatible with towncrier. | |
# - newssnippet print/list: print all news snippets. | |
# - newssnippet run: move all news snippets to CHANGES.rst. | |
from collections import defaultdict | |
import fnmatch | |
import os | |
# Defaults: | |
CHANGELOG = "CHANGES.rst" | |
DIRECTORY = "news" | |
LISTITEM = "-" | |
KNOWN_HEADINGS = { | |
"breaking": "Breaking changes:", | |
"feature": "New features:", | |
"bugfix": "Bug fixes:", | |
} | |
result = {} | |
headers = defaultdict(list) | |
if os.path.isdir(DIRECTORY): | |
for filename in os.listdir(DIRECTORY): | |
if filename.startswith("."): | |
# hidden | |
continue | |
parts = filename.split(".") | |
if 2 <= len(parts) <= 3: | |
number = parts[0] | |
type_ = parts[1] | |
# index = parts[2] | |
else: | |
print("WARNING: ignoring {0} for now.".format(filename)) | |
continue | |
with open(os.path.join(DIRECTORY, filename)) as myfile: | |
text = myfile.read() | |
headers[type_].append((number, text)) | |
from pprint import pprint | |
# Get a specific order. | |
for header in ("breaking", "feature", "bugfix"): | |
if header in headers: | |
print(KNOWN_HEADINGS.get(header, "")) | |
for number, text in headers[header]: | |
# TODO Some indenting needed. | |
print("{0} {1} (#{2})".format(LISTITEM, text, number)) | |
# pprint(headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment