generated from CuriBio/python-github-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prerelease.py
117 lines (98 loc) · 3.87 KB
/
prerelease.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- coding: utf-8 -*-
"""Do the checks and tasks that have to happen before doing a release."""
from __future__ import unicode_literals
import datetime
import logging
import sys
from zest.releaser import baserelease
from zest.releaser import utils
logger = logging.getLogger(__name__)
HISTORY_HEADER = "%(new_version)s (%(today)s)"
PRERELEASE_COMMIT_MSG = "Preparing release %(new_version)s"
# Documentation for self.data. You get runtime warnings when something is in
# self.data that is not in this list. Embarrassment-driven documentation!
DATA = baserelease.DATA.copy()
DATA.update(
{
"today": "Date string used in history header",
}
)
class Prereleaser(baserelease.Basereleaser):
"""Prepare release, ready for making a tag and an sdist.
self.data holds data that can optionally be changed by plugins.
"""
def __init__(self, vcs=None):
baserelease.Basereleaser.__init__(self, vcs=vcs)
# Prepare some defaults for potential overriding.
date_format = self.pypiconfig.date_format()
self.data.update(
dict(
commit_msg=PRERELEASE_COMMIT_MSG,
history_header=HISTORY_HEADER,
today=datetime.datetime.today().strftime(date_format),
update_history=True,
)
)
def prepare(self):
"""Prepare self.data by asking about new version etc."""
# Tanner (7/29/20): We do not want to do this in GitHub
# if not utils.sanity_check(self.vcs):
# logger.critical("Sanity check failed.")
# sys.exit(1)
if not utils.check_recommended_files(self.data, self.vcs):
logger.debug("Recommended files check failed.")
sys.exit(1)
# Grab current version.
self._grab_version(initial=True)
# Grab current history.
# It seems useful to do this even when we will not update the history.
self._grab_history()
if self.data["update_history"]:
# Print changelog for this release.
print( # allow-print
f"Changelog entries for version {self.data['new_version']}:\n"
)
print(self.data.get("history_last_release")) # allow-print
# Grab and set new version.
self._grab_version()
if self.data["update_history"]:
# Look for unwanted 'Nothing changed yet' in latest header.
self._check_nothing_changed()
# Look for required text under the latest header.
self._check_required()
def execute(self):
"""Make the changes and offer a commit."""
if self.data["update_history"]:
self._change_header()
self._write_version()
if self.data["update_history"]:
self._write_history()
self._diff_and_commit()
def _grab_version(self, initial=False):
"""Grab the version.
When initial is False, ask the user for a non-development
version. When initial is True, grab the current suggestion.
"""
original_version = self.vcs.version
logger.debug("Extracted version: %s", original_version)
if not original_version:
logger.critical("No version found.")
sys.exit(1)
suggestion = utils.cleanup_version(original_version)
new_version = None
if not initial:
new_version = utils.ask_version("Enter version", default=suggestion)
if not new_version:
new_version = suggestion
self.data["original_version"] = original_version
self.data["new_version"] = new_version
def datacheck(data):
"""Entrypoint: ensure that the data dict is fully documented"""
utils.is_data_documented(data, documentation=DATA)
def main():
utils.parse_options()
utils.configure_logging()
prereleaser = Prereleaser()
prereleaser.run()
if __name__ == "__main__":
main()