|
| 1 | +import subprocess |
| 2 | +import sys |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import nox # type: ignore |
| 6 | + |
| 7 | +nox.options.reuse_existing_virtualenvs = True |
| 8 | + |
| 9 | + |
| 10 | +def has_changes(): |
| 11 | + status = ( |
| 12 | + subprocess.run( |
| 13 | + "git status --porcelain", shell=True, check=True, stdout=subprocess.PIPE |
| 14 | + ) |
| 15 | + .stdout.decode() |
| 16 | + .strip() |
| 17 | + ) |
| 18 | + return len(status) > 0 |
| 19 | + |
| 20 | + |
| 21 | +def on_master_no_changes(session): |
| 22 | + if has_changes(): |
| 23 | + session.error("All changes must be committed or removed before publishing") |
| 24 | + # branch = get_branch() |
| 25 | + # if branch != "master": |
| 26 | + # session.error(f"Must be on 'master' branch. Currently on {branch!r} branch") |
| 27 | + |
| 28 | + |
| 29 | +def get_branch(): |
| 30 | + return ( |
| 31 | + subprocess.run( |
| 32 | + "git rev-parse --abbrev-ref HEAD", |
| 33 | + shell=True, |
| 34 | + check=True, |
| 35 | + stdout=subprocess.PIPE, |
| 36 | + ) |
| 37 | + .stdout.decode() |
| 38 | + .strip() |
| 39 | + ) |
| 40 | + |
| 41 | + |
| 42 | +@nox.session() |
| 43 | +def build(session): |
| 44 | + session.install("--upgrade", "pip") |
| 45 | + session.install("build") |
| 46 | + session.run("rm", "-rf", "dist", "build", external=True) |
| 47 | + session.run("python", "-m", "build") |
| 48 | + |
| 49 | + |
| 50 | +@nox.session() |
| 51 | +def publish(session): |
| 52 | + on_master_no_changes(session) |
| 53 | + session.install("--upgrade", "pip") |
| 54 | + session.install("twine") |
| 55 | + build(session) |
| 56 | + print("REMINDER: Has the changelog been updated?") |
| 57 | + session.run("python", "-m", "twine", "upload", "dist/*") |
0 commit comments