widgets.browse: Strip off NULL-bytes only
[git-cola.git] / setup.py
blob16a9b6c64174587b1c9f74f3f52bbfe1e34735a4
1 #!/usr/bin/env python
3 import os
4 import sys
5 import platform
6 from glob import glob
7 from distutils.core import setup
9 from extras import cmdclass
11 # Look for modules in the root and thirdparty directories
12 srcdir = os.path.dirname(os.path.abspath(__file__))
13 sys.path.insert(1, os.path.join(srcdir, 'thirdparty'))
14 sys.path.insert(1, srcdir)
16 from cola import version
18 # --standalone prevents installing thirdparty libraries
19 if '--standalone' in sys.argv:
20 sys.argv.remove('--standalone')
21 _standalone = True
22 else:
23 _standalone = False
26 def main():
27 # ensure readable files
28 old_mask = os.umask(0022)
30 _check_python_version()
31 _setup_environment()
32 _check_git_version()
33 _check_pyqt_version()
35 version.write_builtin_version()
37 _run_setup()
38 # restore the old mask
39 os.umask(old_mask)
41 def _setup_environment():
42 """Adds win32/ to our path for windows only"""
43 if sys.platform != 'win32':
44 return
45 path = os.environ['PATH']
46 win32 = os.path.join(srcdir, 'win32')
47 os.environ['PATH'] = win32 + os.pathsep + path
49 def _run_setup():
50 """Runs distutils.setup()"""
52 scripts = ['bin/git-cola']
54 if sys.platform == 'win32':
55 scripts.append('win32/cola')
56 scripts.append('win32/dirname')
57 scripts.append('win32/py2exe-setup.py')
58 scripts.append('win32/py2exe-setup.cmd')
60 setup(name = 'git-cola',
61 version = version.version(),
62 description = 'The highly caffeinated git GUI',
63 license = 'GPLv2',
64 author = 'The git-cola community',
65 author_email = 'git-cola@googlegroups.com',
66 url = 'http://git-cola.github.com/',
67 long_description = 'A sleek and powerful git GUI',
68 scripts = scripts,
69 cmdclass = cmdclass,
70 data_files = cola_data_files())
73 def cola_data_files(standalone=_standalone):
74 data = [
75 _app_path('share/git-cola/icons', '*.png'),
76 _app_path('share/git-cola/icons', '*.svg'),
77 _app_path('share/applications', '*.desktop'),
78 _app_path('share/doc/git-cola', '*.txt'),
79 _package('cola'),
80 _package('cola.classic'),
81 _package('cola.dag'),
82 _package('cola.main'),
83 _package('cola.merge'),
84 _package('cola.models'),
85 _package('cola.controllers'),
86 _package('cola.prefs'),
87 _package('cola.stash'),
88 _package('cola.views'),
89 _package('cola.widgets'),
92 data.extend([_app_path(localedir, 'git-cola.mo')
93 for localedir in glob('share/locale/*/LC_MESSAGES')])
95 if not standalone:
96 data.extend([_thirdparty_package('jsonpickle'),
97 _thirdparty_package('simplejson')])
99 if sys.platform == 'darwin':
100 data.append(_app_path('share/git-cola/bin', 'ssh-askpass-darwin'))
101 else:
102 data.append(_app_path('share/git-cola/bin', 'ssh-askpass'))
103 return data
106 def _package(package, subdir=None):
107 subdirs = package.split('.')
108 app_dir = os.path.join('share', 'git-cola', 'lib', *subdirs)
109 if subdir:
110 subdirs.insert(0, subdir)
111 src_dir = os.path.join(*subdirs)
112 return (app_dir, glob(os.path.join(src_dir, '*.py')))
115 def _thirdparty_package(package):
116 return _package(package, subdir='thirdparty')
119 def _app_path(dirname, entry):
120 return (dirname, glob(os.path.join(dirname, entry)))
123 def _check_python_version():
124 """Check the minimum Python version
126 pyver = platform.python_version()
127 if not version.check('python', pyver):
128 print >> sys.stderr, ('Python version %s or newer required. '
129 'Found %s' % (version.get('python'), pyver))
130 sys.exit(1)
133 def _check_git_version():
134 """Check the minimum GIT version
136 if not version.check('git', version.git_version()):
137 print >> sys.stderr, ('GIT version %s or newer required. '
138 'Found %s' % (version.get('git'),
139 version.git_version()))
140 sys.exit(1)
143 def _check_pyqt_version():
144 """Check the minimum PyQt version
146 has_pyqt = False
147 pyqtver = 'None'
148 try:
149 from PyQt4 import QtCore
150 pyqtver = QtCore.PYQT_VERSION_STR
151 if version.check('pyqt', pyqtver):
152 return
153 except ImportError:
154 pass
155 print >> sys.stderr, ('PyQt4 version %s or newer required. '
156 'Found %s' % (version.get('pyqt'), pyqtver))
157 sys.exit(1)
160 if __name__ == '__main__':
161 main()