Move invoke.generate commands to nox

This commit is contained in:
Pradyun Gedam 2019-07-30 16:56:44 +05:30
parent fe147309ea
commit ae4a22958e
No known key found for this signature in database
GPG Key ID: DA17C4B29CB32E4B
3 changed files with 54 additions and 49 deletions

52
noxfile.py Normal file
View File

@ -0,0 +1,52 @@
"""Release time helpers, executed using nox.
"""
import nox
def get_author_list():
"""Get the list of authors from Git commits.
"""
# subprocess because session.run doesn't give us stdout
result = subprocess.run(
["git", "log", "--use-mailmap", "--format=%aN <%aE>"],
capture_output=True,
encoding="utf-8",
)
# Create a unique list.
authors = []
seen_authors = set()
for author in result.stdout.splitlines():
author = author.strip()
if author.lower() not in seen_authors:
seen_authors.add(author.lower())
authors.append(author)
# Sort our list of Authors by their case insensitive name
return sorted(authors, key=lambda x: x.lower())
# -----------------------------------------------------------------------------
# Commands used during the release process
# -----------------------------------------------------------------------------
@nox.session
def generate_authors(session):
# Get our list of authors
session.log("Collecting author names")
authors = get_author_list()
# Write our authors to the AUTHORS file
session.log("Writing AUTHORS")
with io.open("AUTHORS.txt", "w", encoding="utf-8") as fp:
fp.write(u"\n".join(authors))
fp.write(u"\n")
@nox.session
def generate_news(session):
session.log("Generating NEWS")
session.install("towncrier")
# You can pass 2 possible arguments: --draft, --yes
session.run("towncrier", *session.posargs)

View File

@ -1,5 +1,5 @@
import invoke
from tools.automation import generate, vendoring
from tools.automation import vendoring
ns = invoke.Collection(generate, vendoring)
ns = invoke.Collection(vendoring)

View File

@ -1,47 +0,0 @@
import io
import invoke
@invoke.task
def authors(ctx):
print("[generate.authors] Generating AUTHORS")
# Get our list of authors
print("[generate.authors] Collecting author names")
# Note that it's necessary to use double quotes in the
# --format"=%aN <%aE>" part of the command, as the Windows
# shell doesn't recognise single quotes here.
r = ctx.run('git log --use-mailmap --format"=%aN <%aE>"',
encoding="utf-8", hide=True)
authors = []
seen_authors = set()
for author in r.stdout.splitlines():
author = author.strip()
if author.lower() not in seen_authors:
seen_authors.add(author.lower())
authors.append(author)
# Sort our list of Authors by their case insensitive name
authors = sorted(authors, key=lambda x: x.lower())
# Write our authors to the AUTHORS file
print("[generate.authors] Writing AUTHORS")
with io.open("AUTHORS.txt", "w", encoding="utf8") as fp:
fp.write(u"\n".join(authors))
fp.write(u"\n")
@invoke.task
def news(ctx, draft=False, yes=False):
print("[generate.news] Generating NEWS")
args = []
if draft:
args.append("--draft")
if yes:
args.append("--yes")
ctx.run("towncrier {}".format(" ".join(args)))