-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathsetup.py
186 lines (160 loc) · 6.29 KB
/
setup.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env python3
# encoding: utf-8
from setuptools import setup, find_packages
import sys, os
import pip
from setuptools import setup, find_packages, dist
from setuptools.command.test import test as TestCommand
from distutils.core import Command
from distutils.core import setup
if sys.version_info.major < 3:
print('Please install with python version 3')
sys.exit(1)
# Use buildout's path for eggs
def get_egg_cache_dir(self):
egg_cache_dir = os.path.join(os.curdir, 'var', 'eggs')
if not os.path.exists(egg_cache_dir):
os.makedirs(egg_cache_dir, exist_ok=True)
return egg_cache_dir
dist.Distribution.get_egg_cache_dir = get_egg_cache_dir
class DistClean(Command):
description = 'Clean the repository from all buildout stuff'
user_options = []
def initialize_options(self): pass
def finalize_options(self): pass
def run(self):
import shutil, os
from glob import glob
path = os.path.split(__file__)[0]
shutil.rmtree(os.path.join(path, 'var'), ignore_errors=True)
shutil.rmtree(os.path.join(path, 'bin'), ignore_errors=True)
shutil.rmtree(os.path.join(path, '.tox'), ignore_errors=True)
for fname in glob('*.egg-info'):
shutil.rmtree(os.path.join(path, fname), ignore_errors=True)
shutil.rmtree(os.path.join(path, '.eggs'), ignore_errors=True)
shutil.rmtree(os.path.join(path, 'build'), ignore_errors=True)
shutil.rmtree(os.path.join(path, 'dist'), ignore_errors=True)
shutil.rmtree(os.path.join(path, '.installed.cfg'), ignore_errors=True)
print("Repository is now clean!")
class PyTest(TestCommand):
user_options = [
('exitfirst', 'x', "exit instantly on first error or failed test."),
('last-failed', 'l', "rerun only the tests that failed at the last run"),
('verbose', 'v', "increase verbosity"),
('pdb', 'p', "run pdb upon failure"),
('pep8', '8', "perform some pep8 sanity checks on .py files"),
('flakes', 'f', "run flakes on .py files"),
('pytest-args=', 'a', "Extra arguments to pass into py.test"),
]
default_options = [
'--cov=calenvite', '--cov-report', 'term-missing',
'--capture=sys', 'tests'
]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = set()
self.exitfirst = False
self.last_failed = False
self.verbose = 0
self.pdb = False
self.pep8 = False
self.flakes = False
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
import pytest
if isinstance(self.pytest_args, str):
self.pytest_args = set(self.pytest_args.split(' '))
if self.exitfirst: self.pytest_args.add('-x')
if self.pdb: self.pytest_args.add('--pdb')
if self.last_failed: self.pytest_args.add('--last-failed')
if self.pep8: self.pytest_args.add('--pep8')
if self.flakes: self.pytest_args.add('--flakes')
self.pytest_args = list(self.pytest_args)
if self.verbose:
for v in range(self.verbose):
self.pytest_args.append('-v')
errno = pytest.main(self.pytest_args + self.default_options)
sys.exit(errno)
class Buildout(Command):
description = 'Running buildout on the project'
user_options = []
def initialize_options(self): pass
def finalize_options(self): pass
def run(self):
try:
from zc.buildout.buildout import main
except ImportError:
print('Please install buildout!\n pip install zc.buildout')
sys.exit(1)
errno = main(sys.argv[sys.argv.index('buildout')+1:])
if errno == 0:
print('Now you can run tests using: bin/py.test')
print('Now you can test current code using: bin/git-repo')
print('Thank you 🍻')
sys.exit(errno)
requirements_links = []
def requirements(spec=None):
spec = '{}{}.txt'.format('requirements',
'-'+spec if spec else '')
requires = []
requirements = pip.req.parse_requirements(
spec, session=pip.download.PipSession())
for item in requirements:
if getattr(item, 'link', None):
requirements_links.append(str(item.link))
if item.req:
requires.append(str(item.req))
return requires
setup(name='git-repo',
description='Tool for managing repository services from your git CLI tool',
classifiers=[
# 'Development Status :: 2 - Pre-Alpha',
# 'Development Status :: 3 - Alpha',
'Development Status :: 4 - Beta',
# 'Development Status :: 5 - Production/Stable',
# 'Development Status :: 6 - Mature',
# 'Development Status :: 7 - Inactive',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Topic :: Software Development',
'Topic :: Software Development :: Version Control',
'Topic :: Utilities',
],
keywords='git',
url='https://github.com/guyzmo/git-repo',
author='Bernard `Guyzmo` Pratz',
author_email='[email protected]',
setup_requires=[
'setuptools_scm',
'setuptools-markdown',
'wheel>=0.25.0',
],
long_description_markdown_filename='README.md',
use_scm_version={'version_scheme':'guess-next-dev'},
include_package_data = True,
install_requires=requirements(),
tests_require=requirements('test'),
dependency_links=requirements_links,
cmdclass={
'buildout': Buildout,
'dist_clean': DistClean,
'test': PyTest,
},
entry_points="""
# -*- Entry points: -*-
[console_scripts]
git-repo = git_repo.repo:cli
""",
license='GPLv2',
packages=find_packages(exclude=['tests']),
test_suite='pytest',
zip_safe=False
)