Call setup() directly in setup.py
[stgit.git] / setup.py
blob737b6f760dce5554ac1040bbbc93a1628ed6b1f9
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 from __future__ import (absolute_import, division, print_function,
4 unicode_literals)
5 from distutils.core import setup
6 from glob import glob
7 import os
8 import sys
10 from stgit import version
11 from stgit import commands, completion
14 def __version_to_list(version):
15 """Convert a version string to a list of numbers or strings
16 """
17 ver_list = []
18 for p in version.split('.'):
19 try:
20 n = int(p)
21 except ValueError:
22 n = p
23 ver_list.append(n)
24 return ver_list
27 def __check_min_version(min_ver, ver):
28 """Check whether ver is greater or equal to min_ver
29 """
30 min_ver_list = __version_to_list(min_ver)
31 ver_list = __version_to_list(ver)
32 return min_ver_list <= ver_list
35 def __check_python_version():
36 """Check the minimum Python version
37 """
38 pyver = '.'.join(map(str, sys.version_info))
39 if not __check_min_version(version.python_min_ver, pyver):
40 print('Python version %s or newer required. Found %s'
41 % (version.python_min_ver, pyver), file=sys.stderr)
42 sys.exit(1)
45 def __check_git_version():
46 """Check the minimum GIT version
47 """
48 from stgit.run import Run
49 gitver = Run('git', '--version').output_one_line().split()[2]
50 if not __check_min_version(version.git_min_ver, gitver):
51 print('GIT version %s or newer required. Found %s'
52 % (version.git_min_ver, gitver), file=sys.stderr)
53 sys.exit(1)
56 # Check the minimum versions required
57 __check_python_version()
58 __check_git_version()
60 # ensure readable template files
61 old_mask = os.umask(0o022)
63 version.write_builtin_version()
65 # generate the python command list
66 with open('stgit/commands/cmdlist.py', 'w') as f:
67 commands.py_commands(commands.get_commands(allow_cached=False), f)
69 # generate the bash completion script
70 with open('stgit-completion.bash', 'w') as f:
71 completion.write_completion(f)
73 setup(
74 name='stgit',
75 version=version.version,
76 license='GPLv2',
77 author='Catalin Marinas',
78 author_email='catalin.marinas@gmail.com',
79 url='http://www.procode.org/stgit/',
80 download_url='http://repo.or.cz/stgit.git',
81 description='Stacked GIT',
82 long_description='Push/pop utility on top of GIT',
83 scripts=['stg'],
84 packages=list(map(str, ['stgit', 'stgit.commands', 'stgit.lib'])),
85 data_files=[
86 ('share/stgit/templates', glob('templates/*.tmpl')),
87 ('share/stgit/examples', glob('examples/*.tmpl')),
88 ('share/stgit/examples', ['examples/gitconfig']),
89 ('share/stgit/contrib', ['contrib/stgbashprompt.sh']),
90 ('share/stgit/completion', ['stgit-completion.bash']),
92 classifiers=[
93 'Development Status :: 5 - Production/Stable',
94 'Environment :: Console',
95 'Intended Audience :: Developers',
96 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)'
97 'Natural Language :: English',
98 'Operating System :: OS Independent',
99 'Programming Language :: Python',
100 'Programming Language :: Python :: 2',
101 'Programming Language :: Python :: 2.6',
102 'Programming Language :: Python :: 2.7',
103 'Programming Language :: Python :: 3',
104 'Programming Language :: Python :: 3.3',
105 'Programming Language :: Python :: 3.4',
106 'Programming Language :: Python :: 3.5',
107 'Programming Language :: Python :: 3.6',
108 'Programming Language :: Python :: Implementation :: CPython',
109 'Programming Language :: Python :: Implementation :: PyPy',
110 'Topic :: Software Development :: Version Control',
114 # restore the old mask
115 os.umask(old_mask)