1
0
Fork 0
pgcli/release.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

136 lines
3.0 KiB
Python
Raw Permalink Normal View History

2014-12-15 00:06:25 +00:00
#!/usr/bin/env python
"""A script to publish a release of pgcli to PyPI."""
import io
from optparse import OptionParser
2014-12-15 00:06:25 +00:00
import re
import subprocess
2014-12-18 18:30:58 +00:00
import sys
import click
2014-12-15 00:06:25 +00:00
2014-12-15 00:21:17 +00:00
DEBUG = False
CONFIRM_STEPS = False
DRY_RUN = False
def skip_step():
"""
Asks for user's response whether to run a step. Default is yes.
:return: boolean
"""
global CONFIRM_STEPS
if CONFIRM_STEPS:
return not click.confirm("--- Run this step?", default=True)
return False
def run_step(*args):
"""
Prints out the command and asks if it should be run.
If yes (default), runs it.
:param args: list of strings (command and args)
"""
global DRY_RUN
cmd = args
2019-10-29 16:47:18 +00:00
print(" ".join(cmd))
if skip_step():
2019-10-29 16:47:18 +00:00
print("--- Skipping...")
elif DRY_RUN:
2019-10-29 16:47:18 +00:00
print("--- Pretending to run...")
else:
subprocess.check_output(cmd)
2014-12-15 00:21:17 +00:00
def version(version_file):
_version_re = re.compile(
r'__version__\s+=\s+(?P<quote>[\'"])(?P<version>.*)(?P=quote)'
)
2014-12-15 00:06:25 +00:00
with io.open(version_file, encoding="utf-8") as f:
ver = _version_re.search(f.read()).group("version")
2014-12-15 00:06:25 +00:00
2014-12-15 00:21:17 +00:00
return ver
2014-12-15 00:21:17 +00:00
def commit_for_release(version_file, ver):
run_step("git", "reset")
2023-10-31 03:34:14 +00:00
run_step("git", "add", "-u")
run_step("git", "commit", "--message", "Releasing version {}".format(ver))
2014-12-15 00:06:25 +00:00
def create_git_tag(tag_name):
run_step("git", "tag", tag_name)
2014-12-15 00:06:25 +00:00
def create_distribution_files():
run_step("python", "setup.py", "clean", "--all", "sdist", "bdist_wheel")
2014-12-15 00:06:25 +00:00
def upload_distribution_files():
run_step("twine", "upload", "dist/*")
2015-11-12 23:59:48 +00:00
2015-04-03 01:23:29 +00:00
def push_to_github():
2022-02-28 21:51:56 +00:00
run_step("git", "push", "origin", "main")
2015-04-03 01:23:29 +00:00
2015-01-31 23:28:38 +00:00
def push_tags_to_github():
run_step("git", "push", "--tags", "origin")
2015-01-31 23:28:38 +00:00
def checklist(questions):
for question in questions:
if not click.confirm("--- {}".format(question), default=False):
sys.exit(1)
if __name__ == "__main__":
2014-12-15 00:21:17 +00:00
if DEBUG:
subprocess.check_output = lambda x: x
checks = [
"Have you updated the AUTHORS file?",
"Have you updated the `Usage` section of the README?",
]
checklist(checks)
ver = version("pgcli/__init__.py")
2019-10-29 16:47:18 +00:00
print("Releasing Version:", ver)
parser = OptionParser()
parser.add_option(
"-c",
"--confirm-steps",
action="store_true",
dest="confirm_steps",
default=False,
help=(
"Confirm every step. If the step is not " "confirmed, it will be skipped."
),
)
parser.add_option(
"-d",
"--dry-run",
action="store_true",
dest="dry_run",
default=False,
help="Print out, but not actually run any steps.",
)
popts, pargs = parser.parse_args()
CONFIRM_STEPS = popts.confirm_steps
DRY_RUN = popts.dry_run
if not click.confirm("Are you sure?", default=False):
2014-12-18 18:30:58 +00:00
sys.exit(1)
commit_for_release("pgcli/__init__.py", ver)
create_git_tag("v{}".format(ver))
create_distribution_files()
2015-04-03 01:23:29 +00:00
push_to_github()
2015-01-31 23:28:38 +00:00
push_tags_to_github()
upload_distribution_files()