Added TODO list for treeview branch
[git-cola.git] / setup.py
blob4b88bb02e648424eceb2d2790e147564cb5f420d
1 #!/usr/bin/env python
2 import re
3 import os
4 import sys
5 import stat
6 import shutil
7 import platform
8 from glob import glob
10 from distutils.core import setup
11 from distutils.command import build_scripts
13 try:
14 from extras import cmdclass
15 except ImportError:
16 cmdclass = {}
18 # Prevent distuils from changing "#!/usr/bin/env python"
19 build_scripts.first_line_re = re.compile('^should not match$')
21 # Look for modules in the root and thirdparty directories
22 srcdir = os.path.dirname(os.path.abspath(__file__))
23 sys.path.insert(0, os.path.join(srcdir, 'thirdparty'))
24 sys.path.insert(0, srcdir)
26 from cola import version
28 # --standalone prevents installing thirdparty libraries
29 if '--standalone' in sys.argv:
30 sys.argv.remove('--standalone')
31 _standalone = True
32 else:
33 _standalone = False
36 def main():
37 # ensure readable files
38 old_mask = os.umask(0022)
40 _check_python_version()
41 _setup_environment()
42 _check_git_version()
43 _check_pyqt_version()
45 # First see if there is a version file (included in release tarballs),
46 # then try git-describe, then default.
47 builtin_version = os.path.join('cola', 'builtin_version.py')
48 if os.path.exists('version') and not os.path.exists(builtin_version):
49 shutil.copy('version', builtin_version)
51 elif os.path.exists('.git'):
52 version.write_builtin_version()
54 _run_setup()
55 # restore the old mask
56 os.umask(old_mask)
58 def _setup_environment():
59 """Adds win32/ to our path for windows only"""
60 if sys.platform != 'win32':
61 return
62 path = os.environ['PATH']
63 win32 = os.path.join(srcdir, 'win32')
64 os.environ['PATH'] = win32 + os.pathsep + path
66 def _run_setup():
67 """Runs distutils.setup()"""
69 scripts = ['bin/git-cola']
71 # git-difftool first moved out of git.git's contrib area in git 1.6.3
72 if (os.environ.get('INSTALL_GIT_DIFFTOOL', '') or
73 not version.check('difftool-builtin', version.git_version())):
74 scripts.append('bin/difftool/git-difftool')
75 scripts.append('bin/difftool/git-difftool--helper')
77 if sys.platform == 'win32':
78 scripts.append('win32/cola')
79 scripts.append('win32/dirname')
80 scripts.append('win32/py2exe-setup.py')
81 scripts.append('win32/py2exe-setup.cmd')
83 setup(name = 'git-cola',
84 version = version.version(),
85 description = 'A highly caffeinated git GUI',
86 license = 'GPLv2',
87 author = 'The git-cola community',
88 author_email = 'git-cola@googlegroups.com',
89 url = 'http://cola.tuxfamily.org/',
90 long_description = 'A highly caffeinated git GUI',
91 scripts = scripts,
92 cmdclass = cmdclass,
93 data_files = cola_data_files())
96 def cola_data_files(standalone=_standalone):
97 data = [_app_path('share/git-cola/qm', '*.qm'),
98 _app_path('share/git-cola/icons', '*.png'),
99 _app_path('share/git-cola/icons', '*.svg'),
100 _app_path('share/git-cola/styles', '*.qss'),
101 _app_path('share/git-cola/styles/images', '*.png'),
102 _app_path('share/applications', '*.desktop'),
103 _app_path('share/doc/git-cola', '*.txt'),
104 _app_path('share/locale', '*/LC_MESSAGES/git-cola.mo'),
105 _package('cola'),
106 _package('cola.models'),
107 _package('cola.controllers'),
108 _package('cola.views')]
110 if not standalone:
111 data.extend([_thirdparty_package('jsonpickle'),
112 _thirdparty_package('simplejson')])
114 if sys.platform == 'darwin':
115 data.append(_app_path('share/git-cola/bin', 'ssh-askpass-darwin'))
116 else:
117 data.append(_app_path('share/git-cola/bin', 'ssh-askpass'))
118 return data
121 def _package(package, subdir=None):
122 subdirs = package.split('.')
123 app_dir = os.path.join('share', 'git-cola', 'lib', *subdirs)
124 if subdir:
125 subdirs.insert(0, subdir)
126 src_dir = os.path.join(*subdirs)
127 return (app_dir, glob(os.path.join(src_dir, '*.py')))
130 def _thirdparty_package(package):
131 return _package(package, subdir='thirdparty')
134 def _app_path(dirname, entry):
135 return (dirname, glob(os.path.join(dirname, entry)))
138 def _check_python_version():
139 """Check the minimum Python version
141 pyver = platform.python_version()
142 if not version.check('python', pyver):
143 print >> sys.stderr, ('Python version %s or newer required. '
144 'Found %s' % (version.get('python'), pyver))
145 sys.exit(1)
148 def _check_git_version():
149 """Check the minimum GIT version
151 if not version.check('git', version.git_version()):
152 print >> sys.stderr, ('GIT version %s or newer required. '
153 'Found %s' % (version.get('git'),
154 version.git_version()))
155 sys.exit(1)
158 def _check_pyqt_version():
159 """Check the minimum PyQt version
161 has_pyqt = False
162 pyqtver = 'None'
163 try:
164 from PyQt4 import QtCore
165 pyqtver = QtCore.PYQT_VERSION_STR
166 if version.check('pyqt', pyqtver):
167 return
168 except ImportError:
169 pass
170 print >> sys.stderr, ('PyQt4 version %s or newer required. '
171 'Found %s' % (version.get('pyqt'), pyqtver))
172 sys.exit(1)
175 if __name__ == '__main__':
176 main()