chiark / gitweb /
Try the built-in version string before git-describe
[stgit] / setup.py
1 #!/usr/bin/env python
2
3 import sys, glob, os
4 from distutils.core import setup
5
6 from stgit import version
7 from stgit.run import Run
8
9 def __version_to_list(version):
10     """Convert a version string to a list of numbers or strings
11     """
12     ver_list = []
13     for p in version.split('.'):
14         try:
15             n = int(p)
16         except ValueError:
17             n = p
18         ver_list.append(n)
19     return ver_list
20
21 def __check_min_version(min_ver, ver):
22     """Check whether ver is greater or equal to min_ver
23     """
24     min_ver_list = __version_to_list(min_ver)
25     ver_list = __version_to_list(ver)
26     return min_ver_list <= ver_list
27
28 def __check_python_version():
29     """Check the minimum Python version
30     """
31     pyver = '.'.join(str(n) for n in sys.version_info)
32     if not __check_min_version(version.python_min_ver, pyver):
33         print >> sys.stderr, 'Python version %s or newer required. Found %s' \
34               % (version.python_min_ver, pyver)
35         sys.exit(1)
36
37 def __check_git_version():
38     """Check the minimum GIT version
39     """
40     gitver = Run('git', '--version').output_one_line().split()[2]
41     if not __check_min_version(version.git_min_ver, gitver):
42         print >> sys.stderr, 'GIT version %s or newer required. Found %s' \
43               % (version.git_min_ver, gitver)
44         sys.exit(1)
45
46 def __run_setup():
47     setup(name = 'stgit',
48           version = version.version,
49           license = 'GPLv2',
50           author = 'Catalin Marinas',
51           author_email = 'catalin.marinas@gmail.com',
52           url = 'http://www.procode.org/stgit/',
53           description = 'Stacked GIT',
54           long_description = 'Push/pop utility on top of GIT',
55           scripts = ['stg'],
56           packages = ['stgit', 'stgit.commands', 'stgit.lib'],
57           data_files = [
58             ('share/stgit/templates', glob.glob('templates/*.tmpl')),
59             ('share/stgit/examples', glob.glob('examples/*.tmpl')),
60             ('share/stgit/examples', ['examples/gitconfig']),
61             ('share/stgit/contrib', ['contrib/diffcol.sh',
62                                      'contrib/stgbashprompt.sh',
63                                      'contrib/stgit-completion.bash']),
64             ('share/doc/stgit', glob.glob('doc/*.txt'))])
65
66 # Check the minimum versions required
67 if sys.argv[1] in ['install', 'build']:
68     __check_python_version()
69     __check_git_version()
70
71 # ensure readable template files
72 old_mask = os.umask(0022)
73
74 try:
75     version.write_builtin_version()
76     __run_setup()
77 finally:
78     version.delete_builtin_version()
79
80 # restore the old mask
81 os.umask(old_mask)