README: document "brew reinstall pyqt@5
[git-cola.git] / setup.py
blob08c219436f0aa047ccb8f22b51580bc7233da3ee
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 sys.path.insert(1, os.path.dirname(__file__))
14 from extras import cmdclass
16 # Hack: prevent python2's ascii default encoding from breaking inside
17 # distutils when installing from utf-8 paths.
18 if sys.version_info[0] < 3:
19 # pylint: disable=reload-builtin,undefined-variable
20 reload(sys) # noqa
21 # pylint: disable=no-member
22 sys.setdefaultencoding('utf-8')
24 # Prevent distutils from changing "#!/usr/bin/env python" when
25 # --use-env-python is specified.
26 try:
27 sys.argv.remove('--use-env-python')
28 use_env_python = True
29 except ValueError:
30 use_env_python = False
31 if use_env_python:
32 if sys.version_info[0] < 3:
33 # Python2 accepts the r'' unicode literal.
34 pattern = re.compile(r'^should not match$')
35 else:
36 # Python3 reads files as bytes and requires that the regex pattern is
37 # specified as bytes.
38 pattern = re.compile(b'^should not match$')
39 build_scripts.first_line_re = pattern
41 # Disable installation of the private cola package by passing --no-private-libs or
42 # by setting GIT_COLA_NO_PRIVATE_LIBS=1 in th environment.
43 try:
44 sys.argv.remove('--no-private-libs')
45 private_libs = False
46 except ValueError:
47 private_libs = not os.getenv('GIT_COLA_NO_PRIVATE_LIBS', '')
49 # Disable vendoring of qtpy and friends by passing --no-vendor-libs to setup.py or
50 # by setting GIT_COLA_NO_VENDOR_LIBS=1 in the environment.
51 try:
52 sys.argv.remove('--no-vendor-libs')
53 vendor_libs = False
54 except ValueError:
55 vendor_libs = not os.getenv('GIT_COLA_NO_VENDOR_LIBS', '')
57 # fmt: off
58 here = os.path.dirname(__file__)
59 version = os.path.join(here, 'cola', '_version.py')
60 scope = {}
61 # flake8: noqa
62 exec(open(version).read(), scope) # pylint: disable=exec-used
63 version = scope['VERSION']
64 # fmt: on
67 def main():
68 """Runs distutils.setup()"""
69 scripts = [
70 'bin/git-cola',
71 'bin/git-cola-sequence-editor',
72 'bin/git-dag',
75 if sys.platform == 'win32':
76 scripts.append('contrib/win32/cola')
78 packages = [str('cola'), str('cola.models'), str('cola.widgets')]
80 setup(
81 name='git-cola',
82 version=version,
83 description='The highly caffeinated git GUI',
84 long_description='A sleek and powerful git GUI',
85 license='GPLv2',
86 author='David Aguilar',
87 author_email='davvid@gmail.com',
88 url='https://git-cola.github.io/',
89 scripts=scripts,
90 cmdclass=cmdclass,
91 packages=packages,
92 platforms='any',
93 data_files=_data_files(),
97 def _data_files():
98 """Return the list of data files"""
99 data = [
100 _app_path('share/git-cola/bin', '*'),
101 _app_path('share/git-cola/icons', '*.png'),
102 _app_path('share/git-cola/icons', '*.svg'),
103 _app_path('share/git-cola/icons/dark', '*.png'),
104 _app_path('share/git-cola/icons/dark', '*.svg'),
105 _app_path('share/metainfo', '*.xml'),
106 _app_path('share/applications', '*.desktop'),
107 _app_path('share/doc/git-cola', '*.rst'),
108 _app_path('share/doc/git-cola', '*.html'),
111 if private_libs:
112 data.extend(
113 [_package('cola'), _package('cola.models'), _package('cola.widgets')]
116 if vendor_libs:
117 data.extend([_package('qtpy'), _package('qtpy._patch')])
119 data.extend(
121 _app_path(localedir, 'git-cola.mo')
122 for localedir in glob('share/locale/*/LC_MESSAGES')
125 return data
128 def _package(package, subdirs=None):
129 """Collect python files for a given python "package" name"""
130 dirs = package.split('.')
131 app_dir = _lib_path(*dirs)
132 if subdirs:
133 dirs = list(subdirs) + dirs
134 src_dir = os.path.join(*dirs)
135 return (app_dir, glob(os.path.join(src_dir, '*.py')))
138 def _lib_path(*dirs):
139 return os.path.join('share', 'git-cola', 'lib', *dirs)
142 def _app_path(dirname, entry):
143 """Construct (dirname, [glob-expanded-entries relative to dirname])"""
144 return (dirname, glob(os.path.join(dirname, entry)))
147 if __name__ == '__main__':
148 main()