Skip to content

Commit 44e13ac

Browse files
committed
Updated setup file, added VERSION file, added requirements
- added bump, buildout, test commands to setup.py - added VERSION file for version number - added requirements files, to be nice with *env people - added support for requirements in setup and buildout Signed-off-by: Guyzmo <[email protected]>
1 parent 5315631 commit 44e13ac

File tree

6 files changed

+204
-43
lines changed

6 files changed

+204
-43
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ To use your own credentials, you can setup the following environment variables:
243243
* [ ] gitlab support (cf [#12](https://github.com/guyzmo/git-repo/issues/12))
244244
* [ ] bitbucket support (cf [#13](https://github.com/guyzmo/git-repo/issues/13))
245245
* [ ] add support for handling pull requests
246-
* [x] list them
247-
* [x] fetch them as local branches
248246
* [x] github support
249247
* [ ] gitlab support (cf [#10](https://github.com/guyzmo/git-repo/issues/10))
250248
* [ ] bitbucket support (cf [#11](https://github.com/guyzmo/git-repo/issues/11))

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.6.0

buildout.cfg

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ develop = .
77
eggs-directory = ${buildout:directory}/var/eggs
88
develop-eggs-directory = ${buildout:directory}/var/develop-eggs
99
parts-directory = ${buildout:directory}/var/parts
10-
develop-dir = ${buildout:directory}/var/clone/
11-
#extensions=gp.vcsdevelop
12-
#vcs-extend-develop=git+https://github.com/gitpython-developers/GitPython#egg=GitPython
10+
# develop-dir = ${buildout:directory}/var/clone/
11+
# extensions=gp.vcsdevelop
12+
# vcs-extend-develop=git+https://github.com/gitpython-developers/GitPython#egg=GitPython
1313

1414
[git_repo]
1515
recipe = zc.recipe.egg
1616
eggs =
17+
${git_repo-pip:eggs}
1718
git_repo
1819
interpreter = python3
1920

2021
[pytest]
2122
recipe = zc.recipe.egg
2223
arguments = ['--cov=git_repo', '--cov-report', 'term-missing', '--capture=sys', 'tests']+sys.argv[1:]
23-
eggs = pytest
24-
pytest-cov
25-
pytest-xdist
26-
pytest-sugar
27-
pytest-catchlog
28-
pytest-datadir-ng
29-
testfixtures
30-
mock
31-
betamax==0.5.1
32-
betamax-serializers
33-
git_repo
24+
eggs = ${pytest-pip:eggs}
3425
interpreter = python3
3526

27+
[git_repo-pip]
28+
recipe = collective.recipe.pip
29+
configs = ${buildout:directory}/requirements.txt
30+
31+
[pytest-pip]
32+
recipe = collective.recipe.pip
33+
configs = ${buildout:directory}/requirements-test.txt
34+
35+

requirements-test.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-r requirements.txt
2+
pytest
3+
pytest-cov
4+
pytest-sugar
5+
pytest-catchlog
6+
pytest-datadir-ng
7+
testfixtures
8+
mock
9+
betamax==0.5.1
10+
betamax-serializers
11+
git_repo

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
docopt
2+
GitPython==2.0.6
3+
progress==1.2
4+
python-gitlab==0.13
5+
github3.py==0.9.5
6+
bitbucket-api==0.5.0

setup.py

Lines changed: 172 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1+
#!/usr/bin/env python3
2+
# encoding: utf-8
13
from setuptools import setup, find_packages
24

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
413

514
if sys.version_info.major < 3:
615
print('Please install with python version 3')
716
sys.exit(1)
817

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+
1126

12-
class dist_clean(Command):
27+
class DistClean(Command):
1328
description = 'Clean the repository from all buildout stuff'
1429
user_options = []
1530

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
2233

2334
def run(self):
2435
import shutil, os
@@ -35,8 +46,149 @@ def run(self):
3546
shutil.rmtree(os.path.join(path, '.installed.cfg'), ignore_errors=True)
3647
print("Repository is now clean!")
3748

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+
38190
setup(name='git-repo',
39-
version='1.6.0',
191+
version=str(Version),
40192
description='Tool for managing remote repositories from your git CLI!',
41193
classifiers=[
42194
# 'Development Status :: 2 - Pre-Alpha',
@@ -65,15 +217,15 @@ def run(self):
65217
],
66218
long_description_markdown_filename='README.md',
67219
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+
},
77229
entry_points="""
78230
# -*- Entry points: -*-
79231
[console_scripts]
@@ -82,12 +234,5 @@ def run(self):
82234
license='GPLv2',
83235
packages=find_packages(exclude=['tests']),
84236
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-
],
92237
zip_safe=False
93238
)

0 commit comments

Comments
 (0)