Add a nox command to build release artifacts

This commit is contained in:
Pradyun Gedam 2019-11-03 01:22:53 +05:30
parent 9e3e82e081
commit db66b6eaf5
No known key found for this signature in database
GPG Key ID: DA17C4B29CB32E4B
2 changed files with 34 additions and 0 deletions

View File

@ -4,6 +4,7 @@
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
import glob
import os
import shutil
import sys
@ -182,3 +183,29 @@ def prepare_release(session):
next_dev_version = release.get_next_development_version(version)
release.update_version_file(next_dev_version, VERSION_FILE)
release.commit_file(session, VERSION_FILE, message="Bump for development")
@nox.session(name="build-release")
def build_release(session):
version = release.get_version_from_arguments(session.posargs)
if not version:
session.error("Usage: nox -s upload-release -- YY.N[.P]")
session.log("# Ensure no files in dist/")
if release.have_files_in_folder("dist"):
session.error("There are files in dist/. Remove them and try again")
session.log("# Install dependencies")
session.install("setuptools", "wheel", "twine")
session.log("# Checkout the tag")
session.run("git", "checkout", version, external=True, silent=True)
session.log("# Build distributions")
session.run("python", "setup.py", "sdist", "bdist_wheel", silent=True)
session.log("# Verify distributions")
session.run("twine", "check", *glob.glob("dist/*"), silent=True)
session.log("# Checkout the master branch")
session.run("git", "checkout", "master", external=True, silent=True)

View File

@ -4,6 +4,7 @@ These are written according to the order they are called in.
"""
import io
import os
import subprocess
@ -102,3 +103,9 @@ def get_next_development_version(version):
minor += 1
return f"{major}.{minor}.dev0"
def have_files_in_folder(folder_name):
if not os.path.exists(folder_name):
return False
return bool(os.listdir(folder_name))