1
- # Copyright (C) 2014 Yubico AB
1
+ # Copyright (c) 2013 Yubico AB
2
+ # All rights reserved.
2
3
#
3
- # This program is free software: you can redistribute it and/or modify
4
- # it under the terms of the GNU General Public License as published by
5
- # the Free Software Foundation, either version 3 of the License, or
6
- # (at your option) any later version.
4
+ # Redistribution and use in source and binary forms, with or
5
+ # without modification, are permitted provided that the following
6
+ # conditions are met:
7
7
#
8
- # This program is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- # GNU General Public License for more details.
8
+ # 1. Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # 2. Redistributions in binary form must reproduce the above
11
+ # copyright notice, this list of conditions and the following
12
+ # disclaimer in the documentation and/or other materials provided
13
+ # with the distribution.
12
14
#
13
- # You should have received a copy of the GNU General Public License
14
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
-
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18
+ # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19
+ # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25
+ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ # POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ from __future__ import absolute_import
29
+
30
+
31
+ from setuptools import setup as _setup , find_packages , Command
32
+ from setuptools .command .sdist import sdist
16
33
from distutils import log
17
- from distutils .core import Command
18
34
from distutils .errors import DistutilsSetupError
35
+ from datetime import date
36
+ from glob import glob
19
37
import os
20
38
import re
21
- from datetime import date
39
+
40
+ VERSION_PATTERN = re .compile (r"(?m)^__version__\s*=\s*['\"](.+)['\"]$" )
41
+
42
+ base_module = __name__ .rsplit ('.' , 1 )[0 ]
43
+
44
+
45
+ def get_version (module_name_or_file = None ):
46
+ """Return the current version as defined by the given module/file."""
47
+
48
+ if module_name_or_file is None :
49
+ parts = base_module .split ('.' )
50
+ module_name_or_file = parts [0 ] if len (parts ) > 1 else \
51
+ find_packages (exclude = ['test' , 'test.*' ])[0 ]
52
+
53
+ if os .path .isdir (module_name_or_file ):
54
+ module_name_or_file = os .path .join (module_name_or_file , '__init__.py' )
55
+
56
+ with open (module_name_or_file , 'r' ) as f :
57
+ match = VERSION_PATTERN .search (f .read ())
58
+ return match .group (1 )
59
+
60
+
61
+ def setup (** kwargs ):
62
+ if 'version' not in kwargs :
63
+ kwargs ['version' ] = get_version ()
64
+ kwargs .setdefault ('packages' , find_packages (exclude = ['test' , 'test.*' ]))
65
+ cmdclass = kwargs .setdefault ('cmdclass' , {})
66
+ cmdclass .setdefault ('release' , release )
67
+ cmdclass .setdefault ('build_man' , build_man )
68
+ cmdclass .setdefault ('sdist' , custom_sdist )
69
+ return _setup (** kwargs )
70
+
71
+
72
+ class custom_sdist (sdist ):
73
+ def run (self ):
74
+ self .run_command ('build_man' )
75
+
76
+ sdist .run (self )
77
+
78
+
79
+ class build_man (Command ):
80
+ description = "create man pages from asciidoc source"
81
+ user_options = []
82
+ boolean_options = []
83
+
84
+ def initialize_options (self ):
85
+ pass
86
+
87
+ def finalize_options (self ):
88
+ self .cwd = os .getcwd ()
89
+ self .fullname = self .distribution .get_fullname ()
90
+ self .name = self .distribution .get_name ()
91
+ self .version = self .distribution .get_version ()
92
+
93
+ def run (self ):
94
+ if os .getcwd () != self .cwd :
95
+ raise DistutilsSetupError ("Must be in package root!" )
96
+
97
+ for fname in glob (os .path .join ('man' , '*.adoc' )):
98
+ self .announce ("Converting: " + fname , log .INFO )
99
+ self .execute (os .system ,
100
+ ('a2x -d manpage -f manpage "%s"' % fname ,))
22
101
23
102
24
103
class release (Command ):
25
104
description = "create and release a new version"
26
105
user_options = [
27
- ('keyid= ' , None , "GPG key to sign with" ),
106
+ ('keyid' , None , "GPG key to sign with" ),
28
107
('skip-tests' , None , "skip running the tests" ),
29
108
('pypi' , None , "publish to pypi" ),
30
109
]
@@ -54,6 +133,10 @@ def _verify_tag(self):
54
133
raise DistutilsSetupError (
55
134
"Tag '%s' already exists!" % self .fullname )
56
135
136
+ def _verify_not_dirty (self ):
137
+ if os .system ('git diff --shortstat | grep -q "."' ) == 0 :
138
+ raise DistutilsSetupError ("Git has uncommitted changes!" )
139
+
57
140
def _sign (self ):
58
141
if os .path .isfile ('dist/%s.tar.gz.asc' % self .fullname ):
59
142
# Signature exists from upload, re-use it:
@@ -75,51 +158,26 @@ def _tag(self):
75
158
tag_opts [0 ] = '-u ' + self .keyid
76
159
self .execute (os .system , ('git tag ' + (' ' .join (tag_opts )),))
77
160
78
- def _do_call_publish (self , cmd ):
79
- self ._published = os .system (cmd ) == 0
80
-
81
- def _publish (self ):
82
- web_repo = os .getenv ('YUBICO_GITHUB_REPO' )
83
- if web_repo and os .path .isdir (web_repo ):
84
- artifacts = [
85
- 'dist/%s.tar.gz' % self .fullname ,
86
- 'dist/%s.tar.gz.sig' % self .fullname
87
- ]
88
- cmd = '%s/publish %s %s %s' % (
89
- web_repo , self .name , self .version , ' ' .join (artifacts ))
90
-
91
- self .execute (self ._do_call_publish , (cmd ,))
92
- if self ._published :
93
- self .announce ("Release published! Don't forget to:" , log .INFO )
94
- self .announce ("" )
95
- self .announce (" (cd %s && git push)" % web_repo , log .INFO )
96
- self .announce ("" )
97
- else :
98
- self .warn ("There was a problem publishing the release!" )
99
- else :
100
- self .warn ("YUBICO_GITHUB_REPO not set or invalid!" )
101
- self .warn ("This release will not be published!" )
102
-
103
161
def run (self ):
104
162
if os .getcwd () != self .cwd :
105
163
raise DistutilsSetupError ("Must be in package root!" )
106
164
107
165
self ._verify_version ()
108
166
self ._verify_tag ()
167
+ self ._verify_not_dirty ()
168
+ self .run_command ('check' )
109
169
110
170
self .execute (os .system , ('git2cl > ChangeLog' ,))
111
171
172
+ self .run_command ('sdist' )
173
+
112
174
if not self .skip_tests :
113
- self .run_command ('check' )
114
- # Nosetests calls sys.exit(status)
115
175
try :
116
- self .run_command ('nosetests ' )
176
+ self .run_command ('test ' )
117
177
except SystemExit as e :
118
178
if e .code != 0 :
119
179
raise DistutilsSetupError ("There were test failures!" )
120
180
121
- self .run_command ('sdist' )
122
-
123
181
if self .pypi :
124
182
cmd_obj = self .distribution .get_command_obj ('upload' )
125
183
cmd_obj .sign = True
@@ -130,8 +188,6 @@ def run(self):
130
188
self ._sign ()
131
189
self ._tag ()
132
190
133
- self ._publish ()
134
-
135
191
self .announce ("Release complete! Don't forget to:" , log .INFO )
136
192
self .announce ("" )
137
193
self .announce (" git push && git push --tags" , log .INFO )
0 commit comments