github_release plug on setup.py

This commit is contained in:
Manuel Ebert 2014-11-06 12:35:31 +01:00
parent b45e52f743
commit e77037b0f1

102
setup.py
View file

@ -51,13 +51,8 @@ except ImportError:
readline_available = False
if sys.argv[-1] == 'publish':
os.system("python setup.py sdist upload")
sys.exit()
base_dir = os.path.dirname(os.path.abspath(__file__))
def get_version(filename="jrnl/__init__.py"):
with open(os.path.join(base_dir, filename)) as initfile:
for line in initfile.readlines():
@ -65,6 +60,71 @@ def get_version(filename="jrnl/__init__.py"):
if m:
return m.group(1)
def get_changelog(filename="CHANGELOG.md"):
changelog = {}
current_version = None
with open(os.path.join(base_dir, filename)) as changelog_file:
for line in changelog_file.readlines():
if line.startswith("* __"):
parts = line.strip("* ").split(" ", 1)
if len(parts) == 2:
current_version, changes = parts[0].strip("_\n"), parts[1]
changelog[current_version] = [changes.strip()]
else:
current_version = parts[0].strip("_\n")
changelog[current_version] = []
elif line.strip() and current_version and not line.startswith("#"):
changelog[current_version].append(line.strip(" *\n"))
return changelog
def dist_pypi():
os.system("python setup.py sdist upload")
sys.exit()
def dist_github():
"""Creates a release on the maebert/jrnl repository on github"""
import requests
import keyring
import getpass
version = get_version()
version_tuple = version.split(".")
changes_since_last_version = ["* __{}__: {}".format(key, "\n".join(changes)) for key, changes in get_changelog().items() if key.startswith("{}.{}".format(*version_tuple))]
changes_since_last_version = "\n".join(sorted(changes_since_last_version, reverse=True))
payload = {
"tag_name": version,
"target_commitish": "master",
"name": version,
"body": "Changes in Version {}.{}: \n\n{}".format(version_tuple[0], version_tuple[1], changes_since_last_version)
}
print "Preparing release {}...".format(version)
username = keyring.get_password("github", "__default_user") or raw_input("Github username: ")
password = keyring.get_password("github", username) or getpass.getpass()
otp = raw_input("One Time Token: ")
response = requests.post("https://api.github.com/repos/maebert/jrnl/releases", headers={"X-GitHub-OTP": otp}, json=payload, auth=(username, password))
if response.status_code in (403, 404):
print "Authentication error."
else:
keyring.set_password("github", "__default_user", username)
keyring.set_password("github", username, password)
if response.status_code > 299:
if "message" in response.json():
print "Error: {}".format(response.json()['message'])
for error_dict in response.json().get('errors', []):
print "*", error_dict
else:
print "Unkown error"
print response.text
else:
print "Release created."
sys.exit()
if sys.argv[-1] == 'publish':
dist_pypi()
if sys.argv[-1] == 'github_release':
dist_github()
conditional_dependencies = {
"pyreadline>=2.0": not readline_available and "win32" in sys.platform,
"readline>=6.2": not readline_available and "win32" not in sys.platform,
@ -92,24 +152,24 @@ setup(
},
long_description=__doc__,
entry_points={
'console_scripts': [
'jrnl = jrnl:run',
],
"console_scripts": [
"jrnl = jrnl:run",
]
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Office/Business :: News/Diary',
'Topic :: Text Processing'
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Topic :: Office/Business :: News/Diary",
"Topic :: Text Processing"
],
# metadata for upload to PyPI
author = "Manuel Ebert",