Remove unneeded imports
[stgit.git] / setup.py
blobf51f64141391f157b0fb9033a658e3df787fdaef
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 commands, completion, version
13 def __version_to_list(version):
14 """Convert a version string to a list of numbers or strings
15 """
16 ver_list = []
17 for p in version.split('.'):
18 try:
19 n = int(p)
20 except ValueError:
21 n = p
22 ver_list.append(n)
23 return ver_list
26 def __check_min_version(min_ver, ver):
27 """Check whether ver is greater or equal to min_ver
28 """
29 min_ver_list = __version_to_list(min_ver)
30 ver_list = __version_to_list(ver)
31 return min_ver_list <= ver_list
34 def __check_python_version():
35 """Check the minimum Python version
36 """
37 pyver = '.'.join(map(str, sys.version_info))
38 if not __check_min_version(version.python_min_ver, pyver):
39 print('Python version %s or newer required. Found %s'
40 % (version.python_min_ver, pyver), file=sys.stderr)
41 sys.exit(1)
44 def __check_git_version():
45 """Check the minimum GIT version
46 """
47 from stgit.run import Run
48 gitver = Run('git', '--version').output_one_line().split()[2]
49 if not __check_min_version(version.git_min_ver, gitver):
50 print('GIT version %s or newer required. Found %s'
51 % (version.git_min_ver, gitver), file=sys.stderr)
52 sys.exit(1)
55 # Check the minimum versions required
56 __check_python_version()
57 __check_git_version()
59 # ensure readable template files
60 old_mask = os.umask(0o022)
62 try:
63 ver = version.git_describe_version()
64 except version.VersionUnavailable:
65 ver = version.git_archival_version()
66 with open('stgit/builtin_version.py', 'w') as f:
67 print(
68 '# This file is automatically generated. Do not edit.',
69 'version = {ver!r}'.format(ver=ver),
70 sep='\n',
71 file=f,
74 # generate the python command list
75 with open('stgit/commands/cmdlist.py', 'w') as f:
76 commands.py_commands(commands.get_commands(allow_cached=False), f)
78 # generate the bash completion script
79 with open('stgit-completion.bash', 'w') as f:
80 completion.write_completion(f)
82 setup(
83 name='stgit',
84 version=ver,
85 license='GPLv2',
86 author='Catalin Marinas',
87 author_email='catalin.marinas@gmail.com',
88 url='http://www.procode.org/stgit/',
89 download_url='https://repo.or.cz/stgit.git',
90 description='Stacked GIT',
91 long_description='Push/pop utility on top of GIT',
92 scripts=['stg'],
93 packages=list(map(str, ['stgit', 'stgit.commands', 'stgit.lib'])),
94 data_files=[
95 ('share/stgit/templates', glob('templates/*.tmpl')),
96 ('share/stgit/examples', glob('examples/*.tmpl')),
97 ('share/stgit/examples', ['examples/gitconfig']),
98 ('share/stgit/contrib', ['contrib/stgbashprompt.sh']),
99 ('share/stgit/completion', ['stgit-completion.bash']),
101 classifiers=[
102 'Development Status :: 5 - Production/Stable',
103 'Environment :: Console',
104 'Intended Audience :: Developers',
105 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)'
106 'Natural Language :: English',
107 'Operating System :: OS Independent',
108 'Programming Language :: Python',
109 'Programming Language :: Python :: 2',
110 'Programming Language :: Python :: 2.6',
111 'Programming Language :: Python :: 2.7',
112 'Programming Language :: Python :: 3',
113 'Programming Language :: Python :: 3.3',
114 'Programming Language :: Python :: 3.4',
115 'Programming Language :: Python :: 3.5',
116 'Programming Language :: Python :: 3.6',
117 'Programming Language :: Python :: 3.7',
118 'Programming Language :: Python :: Implementation :: CPython',
119 'Programming Language :: Python :: Implementation :: PyPy',
120 'Topic :: Software Development :: Version Control',
124 # restore the old mask
125 os.umask(old_mask)