1
+ import os
1
2
from pathlib import Path
2
- from subprocess import check_output
3
+ from subprocess import check_output , check_call
3
4
4
5
import invoke
5
6
9
10
})
10
11
def announce (ctx , version ):
11
12
"""Generates a new release announcement entry in the docs."""
12
- print ("[generate.announce] Generating Announce" )
13
-
14
13
# Get our list of authors
15
- print ("[generate.announce] Collecting author names" )
16
-
17
14
stdout = check_output (["git" , "describe" , "--abbrev=0" , '--tags' ])
18
15
stdout = stdout .decode ('utf-8' )
19
16
last_version = stdout .strip ()
@@ -29,12 +26,12 @@ def announce(ctx, version):
29
26
contributors_text = '\n ' .join ('* {}' .format (name ) for name in sorted (contributors )) + '\n '
30
27
text = template_text .format (version = version , contributors = contributors_text )
31
28
32
- target = Path (__file__ ).joinpath ('../ ../doc/en/announce/release-{}.rst' .format (version ))
29
+ target = Path (__file__ ).parent . joinpath ('../doc/en/announce/release-{}.rst' .format (version ))
33
30
target .write_text (text , encoding = 'UTF-8' )
34
31
print ("[generate.announce] Generated {}" .format (target .name ))
35
32
36
33
# Update index with the new release entry
37
- index_path = Path (__file__ ).joinpath ('../ ../doc/en/announce/index.rst' )
34
+ index_path = Path (__file__ ).parent . joinpath ('../doc/en/announce/index.rst' )
38
35
lines = index_path .read_text (encoding = 'UTF-8' ).splitlines ()
39
36
indent = ' '
40
37
for index , line in enumerate (lines ):
@@ -48,9 +45,68 @@ def announce(ctx, version):
48
45
print ("[generate.announce] Skip {} (already contains release)" .format (index_path .name ))
49
46
break
50
47
51
- print ()
52
- print ('Please review the generated files and commit with:' )
53
- print (' git commit -a -m "Generate new release announcement for {}' .format (version ))
48
+ check_call (['git' , 'add' , str (target )])
49
+
50
+
51
+ @invoke .task ()
52
+ def regen (ctx ):
53
+ """Call regendoc tool to update examples and pytest output in the docs."""
54
+ print ("[generate.regen] Updating docs" )
55
+ check_call (['tox' , '-e' , 'regen' ])
56
+
57
+
58
+ @invoke .task ()
59
+ def make_tag (ctx , version ):
60
+ """Create a new (local) tag for the release, only if the repository is clean."""
61
+ from git import Repo
62
+
63
+ repo = Repo ('.' )
64
+ if repo .is_dirty ():
65
+ print ('Current repository is dirty. Please commit any changes and try again.' )
66
+ raise invoke .Exit (code = 2 )
67
+
68
+ tag_names = [x .name for x in repo .tags ]
69
+ if version in tag_names :
70
+ print ("[generate.make_tag] Delete existing tag {}" .format (version ))
71
+ repo .delete_tag (version )
72
+
73
+ print ("[generate.make_tag] Create tag {}" .format (version ))
74
+ repo .create_tag (version )
54
75
55
76
77
+ @invoke .task ()
78
+ def devpi_upload (ctx , version , user , password = None ):
79
+ """Creates and uploads a package to devpi for testing."""
80
+ if password :
81
+ print ("[generate.devpi_upload] devpi login {}" .format (user ))
82
+ check_call (['devpi' , 'login' , user , '--password' , password ])
83
+
84
+ check_call (['devpi' , 'use' , 'https://devpi.net/{}/dev' .format (user )])
85
+
86
+ env = os .environ .copy ()
87
+ env ['SETUPTOOLS_SCM_PRETEND_VERSION' ] = version
88
+ check_call (['devpi' , 'upload' , '--formats' , 'sdist,bdist_wheel' ], env = env )
89
+ print ("[generate.devpi_upload] package uploaded" )
90
+
91
+
92
+ @invoke .task (help = {
93
+ 'version' : 'version being released' ,
94
+ 'user' : 'name of the user on devpi to stage the generated package' ,
95
+ 'password' : 'user password on devpi to stage the generated package '
96
+ '(if not given assumed logged in)' ,
97
+ })
98
+ def pre_release (ctx , version , user , password = None ):
99
+ """Generates new docs, release announcements and uploads a new release to devpi for testing."""
100
+ announce (ctx , version )
101
+ regen (ctx )
102
+
103
+ msg = 'Preparing release version {}' .format (version )
104
+ check_call (['git' , 'commit' , '-a' , '-m' , msg ])
105
+
106
+ make_tag (ctx , version )
107
+
108
+ devpi_upload (ctx , version = version , user = user , password = password )
109
+
110
+ print ()
111
+ print ('[generate.pre_release] Please push your branch and open a PR.' )
56
112
0 commit comments