Skip to content

Commit 8df9329

Browse files
committed
Add release target
1 parent a0b75cc commit 8df9329

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ repos:
3232
args: []
3333
- id: mypy
3434
name: mypy, for Py2
35-
exclude: docs|tests
35+
exclude: noxfile.py|docs|tests
3636
args: ["-2"]
3737

3838
- repo: https://github.com/pre-commit/pygrep-hooks

docs/html/development/release-process.rst

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ Creating a new release
101101
setuptools) to ``Lib/ensurepip/_bundled``, removing the existing version, and
102102
adjusting the versions listed in ``Lib/ensurepip/__init__.py``.
103103

104+
105+
.. note::
106+
107+
Steps 3 to 6 are automated in ``nox -s release -- YY.N`` command.
108+
109+
104110
Creating a bug-fix release
105111
--------------------------
106112

noxfile.py

+56-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"common-wheels": "tools/requirements/tests-common_wheels.txt",
2424
}
2525

26+
AUTHORS_FILE = "AUTHORS.txt"
27+
VERSION_FILE = "src/pip/__init__.py"
28+
2629

2730
def get_author_list():
2831
"""Get the list of authors from Git commits.
@@ -78,6 +81,11 @@ def should_update_common_wheels():
7881
return need_to_repopulate
7982

8083

84+
def update_version_file(new_version):
85+
with open(VERSION_FILE, "w", encoding="utf-8") as f:
86+
f.write('__version__ = "{}"\n'.format(new_version))
87+
88+
8189
# -----------------------------------------------------------------------------
8290
# Development Commands
8391
# These are currently prototypes to evaluate whether we want to switch over
@@ -174,7 +182,7 @@ def generate_authors(session):
174182

175183
# Write our authors to the AUTHORS file
176184
session.log("Writing AUTHORS")
177-
with io.open("AUTHORS.txt", "w", encoding="utf-8") as fp:
185+
with io.open(AUTHORS_FILE, "w", encoding="utf-8") as fp:
178186
fp.write(u"\n".join(authors))
179187
fp.write(u"\n")
180188

@@ -186,3 +194,50 @@ def generate_news(session):
186194

187195
# You can pass 2 possible arguments: --draft, --yes
188196
session.run("towncrier", *session.posargs)
197+
198+
199+
@nox.session
200+
def release(session):
201+
assert len(session.posargs) == 1, "A version number is expected"
202+
new_version = session.posargs[0]
203+
parts = new_version.split('.')
204+
# Expect YY.N or YY.N.P
205+
assert 2 <= len(parts) <= 3, parts
206+
# Only integers
207+
parts = list(map(int, parts))
208+
session.log("Generating commits for version {}".format(new_version))
209+
210+
session.log("Checking that nothing is staged")
211+
# Non-zero exit code means that something is already staged
212+
session.run("git", "diff", "--staged", "--exit-code", external=True)
213+
214+
session.log(f"Updating {AUTHORS_FILE}")
215+
generate_authors(session)
216+
if subprocess.run(["git", "diff", "--exit-code"]).returncode:
217+
session.run("git", "add", AUTHORS_FILE, external=True)
218+
session.run(
219+
"git", "commit", "-m", f"Updating {AUTHORS_FILE}",
220+
external=True,
221+
)
222+
else:
223+
session.log(f"No update needed for {AUTHORS_FILE}")
224+
225+
session.log("Generating NEWS")
226+
session.install("towncrier")
227+
session.run("towncrier", "--yes", "--version", new_version)
228+
229+
session.log("Updating version")
230+
update_version_file(new_version)
231+
session.run("git", "add", VERSION_FILE, external=True)
232+
session.run("git", "commit", "-m", f"Release {new_version}", external=True)
233+
234+
session.log("Tagging release")
235+
session.run(
236+
"git", "tag", "-m", f"Release {new_version}", new_version,
237+
external=True,
238+
)
239+
240+
next_dev_version = f"{parts[0]}.{parts[1] + 1}.dev0"
241+
update_version_file(next_dev_version)
242+
session.run("git", "add", VERSION_FILE, external=True)
243+
session.run("git", "commit", "-m", "Back to development", external=True)

tests/conftest.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import fnmatch
33
import io
44
import os
5+
import re
56
import shutil
67
import subprocess
78
import sys
@@ -246,7 +247,10 @@ def virtualenv_template(request, tmpdir_factory, pip_src,
246247
install_egg_link(venv, 'setuptools', setuptools_install)
247248
pip_editable = Path(str(tmpdir_factory.mktemp('pip'))) / 'pip'
248249
shutil.copytree(pip_src, pip_editable, symlinks=True)
249-
assert compileall.compile_dir(str(pip_editable), quiet=1)
250+
# noxfile.py is Python 3 only
251+
assert compileall.compile_dir(
252+
str(pip_editable), quiet=1, rx=re.compile("noxfile.py$"),
253+
)
250254
subprocess.check_call([venv.bin / 'python', 'setup.py', '-q', 'develop'],
251255
cwd=pip_editable)
252256

0 commit comments

Comments
 (0)