Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

setup.py: add PyQt support.

Changeset 04b0a5411e88

Parent 8fcd84b6ed1a

by Toshi MARUYAMA

Changes to one file · Browse files at 04b0a5411e88 Showing diff from parent 8fcd84b6ed1a Diff from another changeset...

Change 1 of 3 Show Changes Only setup.py Stacked
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
51
52
53
 
 
 
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
 
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
 # setup.py  # A distutils setup script to install TortoiseHg in Windows and Posix  # environments.  #  # On Windows, this script is mostly used to build a stand-alone  # TortoiseHg package. See installer\build.txt for details. The other  # use is to report the current version of the TortoiseHg source.      import time  import sys  import os  import subprocess  from distutils.core import setup  from distutils.command.build import build  from distutils.spawn import spawn, find_executable +from os.path import isdir, exists, join, walk, splitext    thgcopyright = 'Copyright (C) 2010 Steve Borho and others'  hgcopyright = 'Copyright (C) 2005-2010 Matt Mackall and others'    class build_mo(build):     description = "build translations (.mo files)"     def run(self):   if not find_executable('msgfmt'):   self.warn("could not find msgfmt executable, no translations "   "will be built")   return     podir = 'i18n/tortoisehg'   if not os.path.isdir(podir):   self.warn("could not find %s/ directory" % podir)   return     join = os.path.join   for po in os.listdir(podir):   if not po.endswith('.po'):   continue   pofile = join(podir, po)   modir = join('locale', po[:-3], 'LC_MESSAGES')   mofile = join(modir, 'tortoisehg.mo')   cmd = ['msgfmt', '-v', '-o', mofile, pofile]   if sys.platform != 'sunos5':   # msgfmt on Solaris does not know about -c   cmd.append('-c')   self.mkpath(modir)   self.make_file([pofile], mofile, spawn, (cmd,))   +class build_qt(build): + def compile_ui(self, ui_file, py_file=None): + # Search for pyuic4 in python bin dir, then in the $Path. + if py_file is None: + py_file = splitext(ui_file)[0] + "_ui.py" + try: + from PyQt4 import uic + fp = open(py_file, 'w') + uic.compileUi(ui_file, fp) + fp.close() + print "compiled", ui_file, "into", py_file + except Exception, e: + print 'Unable to compile user interface', e + return + + def compile_rc(self, qrc_file, py_file=None): + # Search for pyuic4 in python bin dir, then in the $Path. + if py_file is None: + py_file = splitext(qrc_file)[0] + "_rc.py" + if os.system('pyrcc4 "%s" -o "%s"' % (qrc_file, py_file)) > 0: + print "Unable to generate python module for resource file", qrc_file + + def run(self): + for dirpath, _, filenames in os.walk(join('tortoisehg', 'hgqt')): + for filename in filenames: + if filename.endswith('.ui'): + self.compile_ui(join(dirpath, filename)) + elif filename.endswith('.qrc'): + self.compile_rc(join(dirpath, filename)) + build.run(self) + +  build.sub_commands.append(('build_mo', None))    cmdclass = { - 'build_mo': build_mo} + 'build': build_qt , + 'build_mo': build_mo , + }    def setup_windows(version):   # Specific definitios for Windows NT-alike installations   _scripts = []   _data_files = []   _packages = ['tortoisehg.hgtk', 'tortoisehg.hgtk.logview',   'tortoisehg.hgqt',   'tortoisehg.util', 'tortoisehg']   extra = {}   hgextmods = []     # py2exe needs to be installed to work   try:   import py2exe     # Help py2exe to find win32com.shell   try:   import modulefinder   import win32com   for p in win32com.__path__[1:]: # Take the path to win32comext   modulefinder.AddPackagePath("win32com", p)   pn = "win32com.shell"   __import__(pn)   m = sys.modules[pn]   for p in m.__path__[1:]:   modulefinder.AddPackagePath(pn, p)   except ImportError:   pass     except ImportError:   if '--version' not in sys.argv:   raise     if 'py2exe' in sys.argv:   import hgext   hgextdir = os.path.dirname(hgext.__file__)   hgextmods = set(["hgext." + os.path.splitext(f)[0]   for f in os.listdir(hgextdir)])   _data_files = [(root, [os.path.join(root, file_) for file_ in files])   for root, dirs, files in os.walk('icons')]     # add library files to support PyGtk-based dialogs/windows   includes = ['dbhash', 'pango', 'atk', 'pangocairo', 'cairo', 'gobject']     # Manually include other modules py2exe can't find by itself.   if 'hgext.highlight' in hgextmods:   includes += ['pygments.*', 'pygments.lexers.*', 'pygments.formatters.*',   'pygments.filters.*', 'pygments.styles.*']   if 'hgext.patchbomb' in hgextmods:   includes += ['email.*', 'email.mime.*']     extra['options'] = {   "py2exe" : {   "skip_archive" : 0,     # Don't pull in all this MFC stuff used by the makepy UI.   "excludes" : "pywin,pywin.dialogs,pywin.dialogs.list",   "includes" : includes,   "optimize" : 1   }   }   extra['console'] = [   {'script':'contrib/hg',   'icon_resources':[(0,'icons/hg.ico')],   'description':'Mercurial Distributed SCM',   'copyright':hgcopyright,   'product_version':version},   {'script':'hgtk',   'icon_resources':[(0,'icons/thg_logo.ico')],   'description':'TortoiseHg GUI tools for Mercurial SCM',   'copyright':thgcopyright,   'product_version':version},   {'script':'thg',   'icon_resources':[(0,'icons/thg_logo.ico')],   'description':'TortoiseHg GUI tools for Mercurial SCM',   'copyright':thgcopyright,   'product_version':version},   {'script':'contrib/docdiff.py',   'icon_resources':[(0,'icons/TortoiseMerge.ico')],   'copyright':thgcopyright,   'product_version':version}   ]   extra['windows'] = [   {'script':'TortoiseHgOverlayServer.py',   'icon_resources':[(0,'icons/thg_logo.ico')],   'description':'TortoiseHg Overlay Icon Server',   'copyright':thgcopyright,   'product_version':version}   ]     return _scripts, _packages, _data_files, extra      def setup_posix():   # Specific definitios for Posix installations   _extra = {}   _scripts = ['thg', 'hgtk']   _packages = ['tortoisehg', 'tortoisehg.hgtk', + 'tortoisehg.hgqt',   'tortoisehg.hgtk.logview', 'tortoisehg.util']   _data_files = [(os.path.join('share/pixmaps/tortoisehg', root),   [os.path.join(root, file_) for file_ in files])   for root, dirs, files in os.walk('icons')]   _data_files += [(os.path.join('share', root),   [os.path.join(root, file_) for file_ in files])   for root, dirs, files in os.walk('locale')]   _data_files += [('lib/nautilus/extensions-2.0/python',   ['contrib/nautilus-thg.py'])]     # Create a config.py. Distributions will need to supply their own   cfgfile = os.path.join('tortoisehg', 'util', 'config.py')   if not os.path.exists(cfgfile) and not os.path.exists('.hg/requires'):   f = open(cfgfile, "w")   f.write('bin_path = "/usr/bin"\n')   f.write('license_path = "/usr/share/doc/tortoisehg/Copying.txt.gz"\n')   f.write('locale_path = "/usr/share/locale"\n')   f.write('icon_path = "/usr/share/pixmaps/tortoisehg/icons"\n')   f.write('nofork = True\n')   f.close()     return _scripts, _packages, _data_files, _extra    def runcmd(cmd, env):   p = subprocess.Popen(cmd, stdout=subprocess.PIPE,   stderr=subprocess.PIPE, env=env)   out, err = p.communicate()   # If root is executing setup.py, but the repository is owned by   # another user (as in "sudo python setup.py install") we will get   # trust warnings since the .hg/hgrc file is untrusted. That is   # fine, we don't want to load it anyway.   err = [e for e in err.splitlines()   if not e.startswith('Not trusting file')]   if err:   return ''   return out    version = ''    if os.path.isdir('.hg'):   from tortoisehg.util import version as _version   branch, version = _version.liveversion()   if version.endswith('+'):   version += time.strftime('%Y%m%d')  elif os.path.exists('.hg_archival.txt'):   kw = dict([t.strip() for t in l.split(':', 1)]   for l in open('.hg_archival.txt'))   if 'tag' in kw:   version = kw['tag']   elif 'latesttag' in kw:   version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw   else:   version = kw.get('node', '')[:12]    if version:   f = open("tortoisehg/util/__version__.py", "w")   f.write('# this file is autogenerated by setup.py\n')   f.write('version = "%s"\n' % version)   f.close()    try:   import tortoisehg.util.__version__   version = tortoisehg.util.__version__.version  except ImportError:   version = 'unknown'    if os.name == "nt":   (scripts, packages, data_files, extra) = setup_windows(version)   desc = 'Windows shell extension for Mercurial VCS'   # Windows binary file versions for exe/dll files must have the   # form W.X.Y.Z, where W,X,Y,Z are numbers in the range 0..65535   from tortoisehg.util.version import package_version   setupversion = package_version()   productname = 'TortoiseHg'  else:   (scripts, packages, data_files, extra) = setup_posix()   desc = 'TortoiseHg dialogs for Mercurial VCS'   setupversion = version   productname = 'tortoisehg'    setup(name=productname,   version=setupversion,   author='Steve Borho',   author_email='steve@borho.org',   url='http://tortoisehg.org',   description=desc,   license='GNU GPL2',   scripts=scripts,   packages=packages,   data_files=data_files,   cmdclass=cmdclass,   **extra   )