views.dag: Improve the graph layout algorithm
[git-cola.git] / setup.py
blobefad3aa95b0cac1bbc5f03df1f674c3fed67eb83
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/icons', '*.png'),
98 _app_path('share/git-cola/icons', '*.svg'),
99 _app_path('share/git-cola/styles', '*.qss'),
100 _app_path('share/git-cola/styles/images', '*.png'),
101 _app_path('share/applications', '*.desktop'),
102 _app_path('share/doc/git-cola', '*.txt'),
103 _app_path('share/locale', '*/LC_MESSAGES/git-cola.mo'),
104 _package('cola'),
105 _package('cola.models'),
106 _package('cola.controllers'),
107 _package('cola.views')]
109 if not standalone:
110 data.extend([_thirdparty_package('jsonpickle'),
111 _thirdparty_package('simplejson')])
113 if sys.platform == 'darwin':
114 data.append(_app_path('share/git-cola/bin', 'ssh-askpass-darwin'))
115 else:
116 data.append(_app_path('share/git-cola/bin', 'ssh-askpass'))
117 return data
120 def _package(package, subdir=None):
121 subdirs = package.split('.')
122 app_dir = os.path.join('share', 'git-cola', 'lib', *subdirs)
123 if subdir:
124 subdirs.insert(0, subdir)
125 src_dir = os.path.join(*subdirs)
126 return (app_dir, glob(os.path.join(src_dir, '*.py')))
129 def _thirdparty_package(package):
130 return _package(package, subdir='thirdparty')
133 def _app_path(dirname, entry):
134 return (dirname, glob(os.path.join(dirname, entry)))
137 def _check_python_version():
138 """Check the minimum Python version
140 pyver = platform.python_version()
141 if not version.check('python', pyver):
142 print >> sys.stderr, ('Python version %s or newer required. '
143 'Found %s' % (version.get('python'), pyver))
144 sys.exit(1)
147 def _check_git_version():
148 """Check the minimum GIT version
150 if not version.check('git', version.git_version()):
151 print >> sys.stderr, ('GIT version %s or newer required. '
152 'Found %s' % (version.get('git'),
153 version.git_version()))
154 sys.exit(1)
157 def _check_pyqt_version():
158 """Check the minimum PyQt version
160 has_pyqt = False
161 pyqtver = 'None'
162 try:
163 from PyQt4 import QtCore
164 pyqtver = QtCore.PYQT_VERSION_STR
165 if version.check('pyqt', pyqtver):
166 return
167 except ImportError:
168 pass
169 print >> sys.stderr, ('PyQt4 version %s or newer required. '
170 'Found %s' % (version.get('pyqt'), pyqtver))
171 sys.exit(1)
174 if __name__ == '__main__':
175 main()