guicmds: Replace repobrowser with the simpler browse dialog
[git-cola.git] / setup.py
blob5def60900272e264152084a36839c140e186aa40
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 = 'A highly caffeinated git GUI',
63 license = 'GPLv2',
64 author = 'The git-cola community',
65 author_email = 'git-cola@googlegroups.com',
66 url = 'http://cola.tuxfamily.org/',
67 long_description = 'A highly caffeinated 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/git-cola/styles', '*.qss'),
78 _app_path('share/git-cola/styles/images', '*.png'),
79 _app_path('share/applications', '*.desktop'),
80 _app_path('share/doc/git-cola', '*.txt'),
81 _package('cola'),
82 _package('cola.classic'),
83 _package('cola.dag'),
84 _package('cola.main'),
85 _package('cola.merge'),
86 _package('cola.models'),
87 _package('cola.controllers'),
88 _package('cola.prefs'),
89 _package('cola.stash'),
90 _package('cola.views'),
91 _package('cola.widgets'),
94 data.extend([_app_path(localedir, 'git-cola.mo')
95 for localedir in glob('share/locale/*/LC_MESSAGES')])
97 if not standalone:
98 data.extend([_thirdparty_package('jsonpickle'),
99 _thirdparty_package('simplejson')])
101 if sys.platform == 'darwin':
102 data.append(_app_path('share/git-cola/bin', 'ssh-askpass-darwin'))
103 else:
104 data.append(_app_path('share/git-cola/bin', 'ssh-askpass'))
105 return data
108 def _package(package, subdir=None):
109 subdirs = package.split('.')
110 app_dir = os.path.join('share', 'git-cola', 'lib', *subdirs)
111 if subdir:
112 subdirs.insert(0, subdir)
113 src_dir = os.path.join(*subdirs)
114 return (app_dir, glob(os.path.join(src_dir, '*.py')))
117 def _thirdparty_package(package):
118 return _package(package, subdir='thirdparty')
121 def _app_path(dirname, entry):
122 return (dirname, glob(os.path.join(dirname, entry)))
125 def _check_python_version():
126 """Check the minimum Python version
128 pyver = platform.python_version()
129 if not version.check('python', pyver):
130 print >> sys.stderr, ('Python version %s or newer required. '
131 'Found %s' % (version.get('python'), pyver))
132 sys.exit(1)
135 def _check_git_version():
136 """Check the minimum GIT version
138 if not version.check('git', version.git_version()):
139 print >> sys.stderr, ('GIT version %s or newer required. '
140 'Found %s' % (version.get('git'),
141 version.git_version()))
142 sys.exit(1)
145 def _check_pyqt_version():
146 """Check the minimum PyQt version
148 has_pyqt = False
149 pyqtver = 'None'
150 try:
151 from PyQt4 import QtCore
152 pyqtver = QtCore.PYQT_VERSION_STR
153 if version.check('pyqt', pyqtver):
154 return
155 except ImportError:
156 pass
157 print >> sys.stderr, ('PyQt4 version %s or newer required. '
158 'Found %s' % (version.get('pyqt'), pyqtver))
159 sys.exit(1)
162 if __name__ == '__main__':
163 main()