chiark / gitweb /
stgit.el: Forbid stgit-{delete,edit,mark,rename} on index and work tree
[stgit] / setup.py
CommitLineData
41a6d859
CM
1#!/usr/bin/env python
2
62d51320 3import sys, glob, os
41a6d859
CM
4from distutils.core import setup
5
a2ba4d54 6from stgit import version
453d47ae
CM
7
8def __version_to_list(version):
9 """Convert a version string to a list of numbers or strings
10 """
11 ver_list = []
12 for p in version.split('.'):
13 try:
14 n = int(p)
15 except ValueError:
16 n = p
17 ver_list.append(n)
18 return ver_list
19
20def __check_min_version(min_ver, ver):
21 """Check whether ver is greater or equal to min_ver
22 """
23 min_ver_list = __version_to_list(min_ver)
24 ver_list = __version_to_list(ver)
25 return min_ver_list <= ver_list
26
27def __check_python_version():
28 """Check the minimum Python version
29 """
5717401c 30 pyver = '.'.join(map(lambda x: str(x), sys.version_info))
a2ba4d54 31 if not __check_min_version(version.python_min_ver, pyver):
453d47ae 32 print >> sys.stderr, 'Python version %s or newer required. Found %s' \
a2ba4d54 33 % (version.python_min_ver, pyver)
453d47ae
CM
34 sys.exit(1)
35
36def __check_git_version():
37 """Check the minimum GIT version
38 """
003dccff 39 from stgit.run import Run
453d47ae 40 gitver = Run('git', '--version').output_one_line().split()[2]
a2ba4d54 41 if not __check_min_version(version.git_min_ver, gitver):
453d47ae 42 print >> sys.stderr, 'GIT version %s or newer required. Found %s' \
a2ba4d54 43 % (version.git_min_ver, gitver)
453d47ae
CM
44 sys.exit(1)
45
5c5234db
KH
46def __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']),
afddd62b 61 ('share/stgit/contrib', ['contrib/stgbashprompt.sh']),
6c8a90e1 62 ('share/stgit/completion', ['stgit-completion.bash'])
706c6fac 63 ])
5c5234db 64
453d47ae
CM
65# Check the minimum versions required
66if sys.argv[1] in ['install', 'build']:
67 __check_python_version()
68 __check_git_version()
41a6d859 69
62d51320
CM
70# ensure readable template files
71old_mask = os.umask(0022)
72
5c5234db
KH
73try:
74 version.write_builtin_version()
75 __run_setup()
76finally:
77 version.delete_builtin_version()
62d51320
CM
78
79# restore the old mask
80os.umask(old_mask)