Skip to content

Commit

Permalink
update from:
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Aug 11, 2015
1 parent f2105b0 commit 1275e87
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions setup.py
Expand Up @@ -5,15 +5,17 @@
distutils setup
~~~~~~~~~~~~~~~
:copyleft: 2009-2010 by the django-tools team, see AUTHORS for more details.
:copyleft: 2009-2015 by the django-tools team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""

from __future__ import absolute_import, division, print_function


import os
import subprocess
import sys
import shutil

from setuptools import setup, find_packages

Expand All @@ -35,8 +37,11 @@
long_description = get_long_description(PACKAGE_ROOT)



if "publish" in sys.argv:
"""
'publish' helper for setup.py
Build and upload to PyPi, if...
... __version__ doesn't contains "dev"
... we are on git 'master' branch
Expand All @@ -47,10 +52,14 @@
The cli arguments will be pass to 'twine'. So this is possible:
* Display 'twine' help page...: ./setup.py publish --help
* use testpypi................: ./setup.py publish --repository=test
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 Jens Diemer - GNU GPL v2+
"""
# Imports here, so it's easier to copy&paste this complete code block ;)
import subprocess
import shutil
if sys.version_info[0] == 2:
input = raw_input

try:
# Test if wheel is installed, otherwise the user will only see:
Expand Down Expand Up @@ -116,14 +125,24 @@ def verbose_check_call(*args):
print(output)
sys.exit(-1)

print("\ngit tag version (will raise a error of tag already exists)")
verbose_check_call("git", "tag", "v%s" % __version__)
print("\ncheck if pull is needed")
verbose_check_call("git", "fetch", "--all")
call_info, output = verbose_check_output("git", "log", "HEAD..origin/master", "--oneline")
print("\t%s" % call_info)
if output == "":
print("OK")
else:
print("\n *** ERROR: git repro is not up-to-date:")
print(output)
sys.exit(-1)
verbose_check_call("git", "push")

print("\nCleanup old builds:")
def rmtree(path):
path = os.path.abspath(path)
print("\tremove tree:", path)
shutil.rmtree(path)
if os.path.isdir(path):
print("\tremove tree:", path)
shutil.rmtree(path)
rmtree("./dist")
rmtree("./build")

Expand All @@ -139,6 +158,9 @@ 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__)

print("\nUpload with twine:")
twine_args = sys.argv[1:]
twine_args.remove("publish")
Expand All @@ -147,8 +169,7 @@ def rmtree(path):
from twine.commands.upload import main as twine_upload
twine_upload(twine_args)

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

sys.exit(0)
Expand Down

0 comments on commit 1275e87

Please sign in to comment.