Skip to content

Commit

Permalink
update "./setup.py publish"
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Dec 6, 2017
1 parent 8951d33 commit 1f64d42
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions setup.py
Expand Up @@ -60,7 +60,7 @@
TODO: Look at: https://github.com/zestsoftware/zest.releaser
Source: https://github.com/jedie/python-code-snippets/blob/master/CodeSnippets/setup_publish.py
copyleft 2015-2016 Jens Diemer - GNU GPL v2+
copyleft 2015-2017 Jens Diemer - GNU GPL v2+
"""
if sys.version_info[0] == 2:
input = raw_input
Expand Down Expand Up @@ -107,21 +107,22 @@ def verbose_check_call(*args):
print("\tCall: %r\n" % " ".join(args))
subprocess.check_call(args, universal_newlines=True)

def confirm(txt):
print("\n%s" % txt)
if input("\nPublish anyhow? (Y/N)").lower() not in ("y", "j"):
print("Bye.")
sys.exit(-1)

if "dev" in __version__:
print("\nERROR: Version contains 'dev': v%s\n" % __version__)
sys.exit(-1)
confirm("WARNING: Version contains 'dev': v%s\n" % __version__)

print("\nCheck if we are on 'master' branch:")
call_info, output = verbose_check_output("git", "branch", "--no-color")
print("\t%s" % call_info)
if "* master" in output:
print("OK")
else:
print("\nNOTE: It seems you are not on 'master':")
print(output)
if input("\nPublish anyhow? (Y/N)").lower() not in ("y", "j"):
print("Bye.")
sys.exit(-1)
confirm("\nNOTE: It seems you are not on 'master':\n%s" % output)

print("\ncheck if if git repro is clean:")
call_info, output = verbose_check_output("git", "status", "--porcelain")
Expand All @@ -145,6 +146,14 @@ def verbose_check_call(*args):
sys.exit(-1)
verbose_check_call("git", "push")

print("\nRun './setup.py check':")
call_info, output = verbose_check_output("./setup.py", "check")
if "warning" in output:
print(output)
confirm("Warning found!")
else:
print("OK")

print("\nCleanup old builds:")
def rmtree(path):
path = os.path.abspath(path)
Expand All @@ -166,8 +175,16 @@ def rmtree(path):
log.write(output)
print("Build output is in log file: %r" % log_filename)

print("\ngit tag version (will raise a error of tag already exists)")
verbose_check_call("git", "tag", "v%s" % __version__)
git_tag="v%s" % __version__

print("\ncheck git tag")
call_info, output = verbose_check_output("git", "log", "HEAD..origin/master", "--oneline")
if git_tag in output:
print("\n *** ERROR: git tag %r already exists!" % git_tag)
print(output)
sys.exit(-1)
else:
print("OK")

print("\nUpload with twine:")
twine_args = sys.argv[1:]
Expand All @@ -177,11 +194,15 @@ def rmtree(path):
from twine.commands.upload import main as twine_upload
twine_upload(twine_args)

print("\ngit tag version")
verbose_check_call("git", "tag", git_tag)

print("\ngit push tag to server")
verbose_check_call("git", "push", "--tags")

sys.exit(0)


def get_authors():
try:
with open(os.path.join(PACKAGE_ROOT, "AUTHORS"), "r") as f:
Expand Down

0 comments on commit 1f64d42

Please sign in to comment.