toolbar: guard against missing actions
[git-cola.git] / setup.py
blob069e0b100482bc2286473c3e92d2dc825844776b
1 #!/usr/bin/env python
2 # git-cola installer
3 # usage: use the Makefile instead of invoking this script directly.
4 # pylint: disable=import-error,no-name-in-module
5 from __future__ import absolute_import, division, unicode_literals
6 from glob import glob
7 from distutils.command import build_scripts
8 from distutils.core import setup
9 import os
10 import re
11 import sys
13 from extras import cmdclass
15 # Hack: prevent python2's ascii default encoding from breaking inside
16 # distutils when installing from utf-8 paths.
17 if sys.version_info[0] < 3:
18 # pylint: disable=reload-builtin,undefined-variable
19 reload(sys) # noqa
20 # pylint: disable=no-member
21 sys.setdefaultencoding('utf-8')
23 # Prevent distutils from changing "#!/usr/bin/env python" when
24 # --use-env-python is specified.
25 try:
26 sys.argv.remove('--use-env-python')
27 use_env_python = True
28 except ValueError:
29 use_env_python = False
30 if use_env_python:
31 if sys.version_info[0] < 3:
32 # Python2 accepts the r'' unicode literal.
33 pattern = re.compile(r'^should not match$')
34 else:
35 # Python3 reads files as bytes and requires that the regex pattern is
36 # specified as bytes.
37 pattern = re.compile(b'^should not match$')
38 build_scripts.first_line_re = pattern
40 # Disable installation of the private cola package by passing --no-private-libs or
41 # by setting GIT_COLA_NO_PRIVATE_LIBS=1 in th environment.
42 try:
43 sys.argv.remove('--no-private-libs')
44 private_libs = False
45 except ValueError:
46 private_libs = not os.getenv('GIT_COLA_NO_PRIVATE_LIBS', '')
48 # Disable vendoring of qtpy and friends by passing --no-vendor-libs to setup.py or
49 # by setting GIT_COLA_NO_VENDOR_LIBS=1 in the environment.
50 try:
51 sys.argv.remove('--no-vendor-libs')
52 vendor_libs = False
53 except ValueError:
54 vendor_libs = not os.getenv('GIT_COLA_NO_VENDOR_LIBS', '')
56 here = os.path.dirname(__file__)
57 version = os.path.join(here, 'cola', '_version.py')
58 scope = {}
59 exec(open(version).read(), scope) # pylint: disable=exec-used
60 version = scope['VERSION']
63 def main():
64 """Runs distutils.setup()"""
65 scripts = [
66 'bin/git-cola',
67 'bin/git-cola-sequence-editor',
68 'bin/git-dag',
71 if sys.platform == 'win32':
72 scripts.append('contrib/win32/cola')
74 packages = [str('cola'), str('cola.models'), str('cola.widgets')]
76 setup(
77 name='git-cola',
78 version=version,
79 description='The highly caffeinated git GUI',
80 long_description='A sleek and powerful git GUI',
81 license='GPLv2',
82 author='David Aguilar',
83 author_email='davvid@gmail.com',
84 url='https://git-cola.github.io/',
85 scripts=scripts,
86 cmdclass=cmdclass,
87 packages=packages,
88 platforms='any',
89 data_files=_data_files(),
93 def _data_files():
94 """Return the list of data files"""
95 data = [
96 _app_path('share/git-cola/bin', '*'),
97 _app_path('share/git-cola/icons', '*.png'),
98 _app_path('share/git-cola/icons', '*.svg'),
99 _app_path('share/git-cola/icons/dark', '*.png'),
100 _app_path('share/git-cola/icons/dark', '*.svg'),
101 _app_path('share/metainfo', '*.xml'),
102 _app_path('share/applications', '*.desktop'),
103 _app_path('share/doc/git-cola', '*.rst'),
104 _app_path('share/doc/git-cola', '*.html'),
107 if private_libs:
108 data.extend(
109 [_package('cola'), _package('cola.models'), _package('cola.widgets')]
112 if vendor_libs:
113 data.extend([_package('qtpy'), _package('qtpy._patch')])
115 data.extend(
117 _app_path(localedir, 'git-cola.mo')
118 for localedir in glob('share/locale/*/LC_MESSAGES')
121 return data
124 def _package(package, subdirs=None):
125 """Collect python files for a given python "package" name"""
126 dirs = package.split('.')
127 app_dir = _lib_path(*dirs)
128 if subdirs:
129 dirs = list(subdirs) + dirs
130 src_dir = os.path.join(*dirs)
131 return (app_dir, glob(os.path.join(src_dir, '*.py')))
134 def _lib_path(*dirs):
135 return os.path.join('share', 'git-cola', 'lib', *dirs)
138 def _app_path(dirname, entry):
139 """Construct (dirname, [glob-expanded-entries relative to dirname])"""
140 return (dirname, glob(os.path.join(dirname, entry)))
143 if __name__ == '__main__':
144 main()