Merge pull request #1200 from living180/track_browser_windows
[git-cola.git] / setup.py
blobb8d8c395a34d1a2b7393cf87bea16f2a600d33eb
1 #!/usr/bin/env python
2 # usage: use the Makefile instead of invoking this script directly.
3 # pylint: disable=import-error,no-name-in-module
4 from __future__ import absolute_import, division, print_function, unicode_literals
5 from glob import glob
6 from distutils.command import build_scripts
7 from distutils.core import setup
8 import os
9 import re
10 import sys
12 sys.path.insert(1, os.path.dirname(__file__))
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 # fmt: off
57 here = os.path.dirname(__file__)
58 version = os.path.join(here, 'cola', '_version.py')
59 scope = {}
60 # flake8: noqa
61 exec(open(version).read(), scope) # pylint: disable=exec-used
62 version = scope['VERSION']
63 # fmt: on
66 def main():
67 """Runs distutils.setup()"""
68 scripts = [
69 'bin/git-cola',
70 'bin/git-cola-sequence-editor',
71 'bin/git-dag',
74 if sys.platform == 'win32':
75 scripts.append('contrib/win32/cola')
77 packages = [str('cola'), str('cola.models'), str('cola.widgets')]
79 setup(
80 name='git-cola',
81 version=version,
82 description='The highly caffeinated git GUI',
83 long_description='A sleek and powerful git GUI',
84 license='GPLv2',
85 author='David Aguilar',
86 author_email='davvid@gmail.com',
87 url='https://git-cola.github.io/',
88 scripts=scripts,
89 cmdclass=cmdclass,
90 packages=packages,
91 platforms='any',
92 data_files=_data_files(),
96 def _data_files():
97 """Return the list of data files"""
98 data = [
99 _app_path('share/git-cola/bin', '*'),
100 _app_path('share/git-cola/icons', '*.png'),
101 _app_path('share/git-cola/icons', '*.svg'),
102 _app_path('share/git-cola/icons/dark', '*.png'),
103 _app_path('share/git-cola/icons/dark', '*.svg'),
104 _app_path('share/metainfo', '*.xml'),
105 _app_path('share/applications', '*.desktop'),
106 _app_path('share/doc/git-cola', '*.rst'),
107 _app_path('share/doc/git-cola', '*.html'),
110 if private_libs:
111 data.extend(
112 [_package('cola'), _package('cola.models'), _package('cola.widgets')]
115 if vendor_libs:
116 data.extend([_package('qtpy'), _package('qtpy._patch')])
118 data.extend(
120 _app_path(localedir, 'git-cola.mo')
121 for localedir in glob('share/locale/*/LC_MESSAGES')
124 return data
127 def _package(package, subdirs=None):
128 """Collect python files for a given python "package" name"""
129 dirs = package.split('.')
130 app_dir = _lib_path(*dirs)
131 if subdirs:
132 dirs = list(subdirs) + dirs
133 src_dir = os.path.join(*dirs)
134 return (app_dir, glob(os.path.join(src_dir, '*.py')))
137 def _lib_path(*dirs):
138 return os.path.join('share', 'git-cola', 'lib', *dirs)
141 def _app_path(dirname, entry):
142 """Construct (dirname, [glob-expanded-entries relative to dirname])"""
143 return (dirname, glob(os.path.join(dirname, entry)))
146 if __name__ == '__main__':
147 main()