1
+ #!/usr/bin/env python3
2
+ # encoding: utf-8
1
3
from setuptools import setup , find_packages
2
4
3
- import sys
5
+ import sys , os
6
+
7
+ import pip
8
+
9
+ from setuptools import setup , find_packages , dist
10
+ from setuptools .command .test import test as TestCommand
11
+ from distutils .core import Command
12
+ from distutils .core import setup
4
13
5
14
if sys .version_info .major < 3 :
6
15
print ('Please install with python version 3' )
7
16
sys .exit (1 )
8
17
9
- from distutils .core import Command
10
- from distutils .core import setup
18
+ # Use buildout's path for eggs
19
+ def get_egg_cache_dir (self ):
20
+ egg_cache_dir = os .path .join (os .curdir , 'var' , 'eggs' )
21
+ if not os .path .exists (egg_cache_dir ):
22
+ os .makedirs (egg_cache_dir , exist_ok = True )
23
+ return egg_cache_dir
24
+ dist .Distribution .get_egg_cache_dir = get_egg_cache_dir
25
+
11
26
12
- class dist_clean (Command ):
27
+ class DistClean (Command ):
13
28
description = 'Clean the repository from all buildout stuff'
14
29
user_options = []
15
30
16
- def initialize_options (self ):
17
- pass
18
-
19
- def finalize_options (self ):
20
- pass
21
-
31
+ def initialize_options (self ): pass
32
+ def finalize_options (self ): pass
22
33
23
34
def run (self ):
24
35
import shutil , os
@@ -35,8 +46,149 @@ def run(self):
35
46
shutil .rmtree (os .path .join (path , '.installed.cfg' ), ignore_errors = True )
36
47
print ("Repository is now clean!" )
37
48
49
+ class VersionInfo (type ):
50
+ @property
51
+ def info (cls ):
52
+ if not cls ._info :
53
+ try :
54
+ cls ._info = list (int (x ) for x in open (cls .path , 'r' ).read ().strip ().split ('.' ))
55
+ except ValueError :
56
+ print ('Version parts shall all be integers' )
57
+ sys .exit (1 )
58
+ if len (cls ._info ) != 3 :
59
+ print ('Version number is not conform, there should be exactly three parts' )
60
+ sys .exit (1 )
61
+ return cls ._info
62
+
63
+ def __str__ (cls ):
64
+ return '.' .join (map (str , cls .info ))
65
+
66
+
67
+ class Version (Command , metaclass = VersionInfo ):
68
+ description = 'Bump version number'
69
+ user_options = [
70
+ ('major' , 'M' , 'Bump major part of version number' ),
71
+ ('minor' , 'm' , 'Bump minor part of version number' ),
72
+ ('patch' , 'p' , 'Bump patch part of version number' )]
73
+ path = os .path .join (os .path .dirname (__file__ ), 'VERSION' )
74
+ _info = None
75
+
76
+ def finalize_options (self , * args , ** kwarg ): pass
77
+ def initialize_options (self , * args , ** kwarg ):
78
+ self .major = None
79
+ self .minor = None
80
+ self .patch = None
81
+
82
+ def run (self ):
83
+ MAJOR , MINOR , PATCH = (0 ,1 ,2 )
84
+ prev = str (Version )
85
+ if self .major :
86
+ Version .info [MAJOR ] += 1
87
+ Version .info [MINOR ] = 0
88
+ Version .info [PATCH ] = 0
89
+ if self .minor :
90
+ Version .info [MINOR ] += 1
91
+ Version .info [PATCH ] = 0
92
+ if self .patch :
93
+ Version .info [PATCH ] += 1
94
+ if self .major or self .minor or self .patch :
95
+ with open (self .path , 'w' ) as f :
96
+ f .write (str (Version ))
97
+ print ("Bumped version from {} to {}" .format (prev , str (Version )))
98
+ else :
99
+ print ("Please choose at least one part to bump: --major, --minor or --patch!" )
100
+ sys .exit (1 )
101
+
102
+
103
+ class PyTest (TestCommand ):
104
+ user_options = [
105
+ ('exitfirst' , 'x' , "exit instantly on first error or failed test." ),
106
+ ('last-failed' , 'l' , "rerun only the tests that failed at the last run" ),
107
+ ('verbose' , 'v' , "increase verbosity" ),
108
+ ('pdb' , 'p' , "run pdb upon failure" ),
109
+ ('pep8' , '8' , "perform some pep8 sanity checks on .py files" ),
110
+ ('flakes' , 'f' , "run flakes on .py files" ),
111
+ ('pytest-args=' , 'a' , "Extra arguments to pass into py.test" ),
112
+ ]
113
+ default_options = [
114
+ '--cov=calenvite' , '--cov-report' , 'term-missing' ,
115
+ '--capture=sys' , 'tests'
116
+ ]
117
+
118
+ def initialize_options (self ):
119
+ TestCommand .initialize_options (self )
120
+ self .pytest_args = set ()
121
+ self .exitfirst = False
122
+ self .last_failed = False
123
+ self .verbose = 0
124
+ self .pdb = False
125
+ self .pep8 = False
126
+ self .flakes = False
127
+
128
+ def finalize_options (self ):
129
+ TestCommand .finalize_options (self )
130
+ self .test_args = []
131
+ self .test_suite = True
132
+
133
+ def run_tests (self ):
134
+ import pytest
135
+ if isinstance (self .pytest_args , str ):
136
+ self .pytest_args = set (self .pytest_args .split (' ' ))
137
+ if self .exitfirst : self .pytest_args .add ('-x' )
138
+ if self .pdb : self .pytest_args .add ('--pdb' )
139
+ if self .last_failed : self .pytest_args .add ('--last-failed' )
140
+ if self .pep8 : self .pytest_args .add ('--pep8' )
141
+ if self .flakes : self .pytest_args .add ('--flakes' )
142
+ self .pytest_args = list (self .pytest_args )
143
+ if self .verbose :
144
+ for v in range (self .verbose ):
145
+ self .pytest_args .append ('-v' )
146
+ errno = pytest .main (self .pytest_args + self .default_options )
147
+ sys .exit (errno )
148
+
149
+
150
+ class Buildout (Command ):
151
+ description = 'Running buildout on the project'
152
+ user_options = []
153
+
154
+ def initialize_options (self ): pass
155
+ def finalize_options (self ): pass
156
+
157
+ def run (self ):
158
+ try :
159
+ from zc .buildout .buildout import main
160
+ except ImportError :
161
+ print ('Please install buildout!\n pip install zc.buildout' )
162
+ sys .exit (1 )
163
+ errno = main (sys .argv [sys .argv .index ('buildout' )+ 1 :])
164
+ if errno == 0 :
165
+ print ('Now you can run tests using: bin/py.test' )
166
+ print ('Now you can test current code using: bin/git-repo' )
167
+ print ('Thank you 🍻' )
168
+ sys .exit (errno )
169
+
170
+
171
+ requirements_links = []
172
+
173
+ def requirements (spec = None ):
174
+ spec = '{}{}.txt' .format ('requirements' ,
175
+ '-' + spec if spec else '' )
176
+ requires = []
177
+
178
+ requirements = pip .req .parse_requirements (
179
+ spec , session = pip .download .PipSession ())
180
+
181
+ for item in requirements :
182
+ if getattr (item , 'link' , None ):
183
+ requirements_links .append (str (item .link ))
184
+ if item .req :
185
+ requires .append (str (item .req ))
186
+
187
+ return requires
188
+
189
+
38
190
setup (name = 'git-repo' ,
39
- version = '1.6.0' ,
191
+ version = str ( Version ) ,
40
192
description = 'Tool for managing remote repositories from your git CLI!' ,
41
193
classifiers = [
42
194
# 'Development Status :: 2 - Pre-Alpha',
@@ -65,15 +217,15 @@ def run(self):
65
217
],
66
218
long_description_markdown_filename = 'README.md' ,
67
219
include_package_data = True ,
68
- install_requires = [
69
- 'docopt' ,
70
- 'GitPython==2.0.4' ,
71
- 'progress==1.2' ,
72
- 'python-gitlab==0.13' ,
73
- 'github3.py==0.9.5' ,
74
- 'bitbucket-api==0.5.0' ,
75
- ] ,
76
- cmdclass = { 'dist_clean' : dist_clean },
220
+ install_requires = requirements (),
221
+ tests_require = requirements ( 'test' ) ,
222
+ dependency_links = requirements_links ,
223
+ cmdclass = {
224
+ 'buildout' : Buildout ,
225
+ 'dist_clean' : DistClean ,
226
+ 'test' : PyTest ,
227
+ 'bump' : Version ,
228
+ },
77
229
entry_points = """
78
230
# -*- Entry points: -*-
79
231
[console_scripts]
@@ -82,12 +234,5 @@ def run(self):
82
234
license = 'GPLv2' ,
83
235
packages = find_packages (exclude = ['tests' ]),
84
236
test_suite = 'pytest' ,
85
- tests_require = [
86
- 'pytest==2.9.1' ,
87
- 'pytest-cov' ,
88
- 'pytest-sugar' ,
89
- 'pytest-catchlog' ,
90
- 'pytest-datadir-ng' ,
91
- ],
92
237
zip_safe = False
93
238
)
0 commit comments