Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: packagerChrome.py

Issue 29756673: Noissue - Adapt best practices for trailing commas (buildtools) (Closed)
Patch Set: Re-run script on Python 2, added flake8-commas extension Created April 19, 2018, 2:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « localeTools.py ('k') | packagerEdge.py » ('j') | tox.ini » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import errno 5 import errno
6 import glob 6 import glob
7 import io 7 import io
8 import json 8 import json
9 import os 9 import os
10 import re 10 import re
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if width != height: 57 if width != height:
58 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be squar e' % (filename, width, height) 58 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be squar e' % (filename, width, height)
59 icons[width] = filename 59 icons[width] = filename
60 return icons 60 return icons
61 61
62 62
63 def createScriptPage(params, template_name, script_option): 63 def createScriptPage(params, template_name, script_option):
64 template = getTemplate(template_name, autoEscape=True) 64 template = getTemplate(template_name, autoEscape=True)
65 return template.render( 65 return template.render(
66 basename=params['metadata'].get('general', 'basename'), 66 basename=params['metadata'].get('general', 'basename'),
67 scripts=params['metadata'].get(*script_option).split() 67 scripts=params['metadata'].get(*script_option).split(),
68 ).encode('utf-8') 68 ).encode('utf-8')
69 69
70 70
71 def createManifest(params, files): 71 def createManifest(params, files):
72 template = getTemplate('manifest.json.tmpl') 72 template = getTemplate('manifest.json.tmpl')
73 templateData = dict(params) 73 templateData = dict(params)
74 74
75 baseDir = templateData['baseDir'] 75 baseDir = templateData['baseDir']
76 metadata = templateData['metadata'] 76 metadata = templateData['metadata']
77 77
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 metadata.serialize_section_if_present('manifest', data) 138 metadata.serialize_section_if_present('manifest', data)
139 manifest = json.dumps(data, sort_keys=True, indent=2) 139 manifest = json.dumps(data, sort_keys=True, indent=2)
140 140
141 return manifest.encode('utf-8') 141 return manifest.encode('utf-8')
142 142
143 143
144 def toJson(data): 144 def toJson(data):
145 return json.dumps( 145 return json.dumps(
146 data, ensure_ascii=False, sort_keys=True, 146 data, ensure_ascii=False, sort_keys=True,
147 indent=2, separators=(',', ': ') 147 indent=2, separators=(',', ': '),
148 ).encode('utf-8') + '\n' 148 ).encode('utf-8') + '\n'
149 149
150 150
151 def create_bundles(params, files, bundle_tests): 151 def create_bundles(params, files, bundle_tests):
152 base_extension_path = params['baseDir'] 152 base_extension_path = params['baseDir']
153 info_templates = { 153 info_templates = {
154 'chrome': 'chromeInfo.js.tmpl', 154 'chrome': 'chromeInfo.js.tmpl',
155 'edge': 'edgeInfo.js.tmpl', 155 'edge': 'edgeInfo.js.tmpl',
156 'gecko': 'geckoInfo.js.tmpl' 156 'gecko': 'geckoInfo.js.tmpl',
157 } 157 }
158 158
159 # Historically we didn't use relative paths when requiring modules, so in 159 # Historically we didn't use relative paths when requiring modules, so in
160 # order for webpack to know where to find them we need to pass in a list of 160 # order for webpack to know where to find them we need to pass in a list of
161 # resolve paths. Going forward we should always use relative paths, once we 161 # resolve paths. Going forward we should always use relative paths, once we
162 # do that consistently this can be removed. See issues 5760, 5761 and 5762. 162 # do that consistently this can be removed. See issues 5760, 5761 and 5762.
163 resolve_paths = [os.path.join(base_extension_path, dir, 'lib') 163 resolve_paths = [os.path.join(base_extension_path, dir, 'lib')
164 for dir in ['', 'adblockpluscore', 'adblockplusui']] 164 for dir in ['', 'adblockpluscore', 'adblockplusui']]
165 165
166 info_template = getTemplate(info_templates[params['type']]) 166 info_template = getTemplate(info_templates[params['type']])
167 info_module = info_template.render( 167 info_module = info_template.render(
168 basename=params['metadata'].get('general', 'basename'), 168 basename=params['metadata'].get('general', 'basename'),
169 version=params['version'] 169 version=params['version'],
170 ).encode('utf-8') 170 ).encode('utf-8')
171 171
172 configuration = { 172 configuration = {
173 'bundles': [], 173 'bundles': [],
174 'extension_path': base_extension_path, 174 'extension_path': base_extension_path,
175 'info_module': info_module, 175 'info_module': info_module,
176 'resolve_paths': resolve_paths, 176 'resolve_paths': resolve_paths,
177 } 177 }
178 178
179 for item in params['metadata'].items('bundles'): 179 for item in params['metadata'].items('bundles'):
180 name, value = item 180 name, value = item
181 base_item_path = os.path.dirname(item.source) 181 base_item_path = os.path.dirname(item.source)
182 182
183 bundle_file = os.path.relpath(os.path.join(base_item_path, name), 183 bundle_file = os.path.relpath(os.path.join(base_item_path, name),
184 base_extension_path) 184 base_extension_path)
185 entry_files = [os.path.join(base_item_path, module_path) 185 entry_files = [os.path.join(base_item_path, module_path)
186 for module_path in value.split()] 186 for module_path in value.split()]
187 configuration['bundles'].append({ 187 configuration['bundles'].append({
188 'bundle_name': bundle_file, 188 'bundle_name': bundle_file,
189 'entry_points': entry_files, 189 'entry_points': entry_files,
190 }) 190 })
191 191
192 if bundle_tests: 192 if bundle_tests:
193 qunit_path = os.path.join(base_extension_path, 'qunit') 193 qunit_path = os.path.join(base_extension_path, 'qunit')
194 qunit_files = ([os.path.join(qunit_path, 'common.js')] + 194 qunit_files = ([os.path.join(qunit_path, 'common.js')] +
195 glob.glob(os.path.join(qunit_path, 'tests', '*.js'))) 195 glob.glob(os.path.join(qunit_path, 'tests', '*.js')))
196 configuration['bundles'].append({ 196 configuration['bundles'].append({
197 'bundle_name': 'qunit/tests.js', 197 'bundle_name': 'qunit/tests.js',
198 'entry_points': qunit_files 198 'entry_points': qunit_files,
199 }) 199 })
200 200
201 cmd = ['node', os.path.join(os.path.dirname(__file__), 'webpack_runner.js')] 201 cmd = ['node', os.path.join(os.path.dirname(__file__), 'webpack_runner.js')]
202 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 202 process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
203 stdin=subprocess.PIPE) 203 stdin=subprocess.PIPE)
204 output = process.communicate(input=toJson(configuration))[0] 204 output = process.communicate(input=toJson(configuration))[0]
205 if process.returncode != 0: 205 if process.returncode != 0:
206 raise subprocess.CalledProcessError(process.returncode, cmd=cmd) 206 raise subprocess.CalledProcessError(process.returncode, cmd=cmd)
207 output = json.loads(output) 207 output = json.loads(output)
208 208
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 332
333 def add_devenv_requirements(files, metadata, params): 333 def add_devenv_requirements(files, metadata, params):
334 files.read( 334 files.read(
335 os.path.join(os.path.dirname(__file__), 'chromeDevenvPoller__.js'), 335 os.path.join(os.path.dirname(__file__), 'chromeDevenvPoller__.js'),
336 relpath='devenvPoller__.js', 336 relpath='devenvPoller__.js',
337 ) 337 )
338 files['devenvVersion__'] = str(random.random()) 338 files['devenvVersion__'] = str(random.random())
339 339
340 if metadata.has_option('general', 'testScripts'): 340 if metadata.has_option('general', 'testScripts'):
341 files['qunit/index.html'] = createScriptPage( 341 files['qunit/index.html'] = createScriptPage(
342 params, 'testIndex.html.tmpl', ('general', 'testScripts') 342 params, 'testIndex.html.tmpl', ('general', 'testScripts'),
343 ) 343 )
344 344
345 345
346 def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuil d=False, keyFile=None, devenv=False): 346 def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuil d=False, keyFile=None, devenv=False):
347 metadata = readMetadata(baseDir, type) 347 metadata = readMetadata(baseDir, type)
348 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) 348 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum)
349 349
350 if outFile == None: 350 if outFile == None:
351 file_extension = get_extension(type, keyFile is not None) 351 file_extension = get_extension(type, keyFile is not None)
352 outFile = getDefaultFileName(metadata, version, file_extension) 352 outFile = getDefaultFileName(metadata, version, file_extension)
(...skipping 14 matching lines...) Expand all
367 files.readMappedFiles(mapped) 367 files.readMappedFiles(mapped)
368 files.read(baseDir, skip=[opt for opt, _ in mapped]) 368 files.read(baseDir, skip=[opt for opt, _ in mapped])
369 369
370 if metadata.has_section('bundles'): 370 if metadata.has_section('bundles'):
371 bundle_tests = devenv and metadata.has_option('general', 'testScripts') 371 bundle_tests = devenv and metadata.has_option('general', 'testScripts')
372 create_bundles(params, files, bundle_tests) 372 create_bundles(params, files, bundle_tests)
373 373
374 if metadata.has_section('preprocess'): 374 if metadata.has_section('preprocess'):
375 files.preprocess( 375 files.preprocess(
376 [f for f, _ in metadata.items('preprocess')], 376 [f for f, _ in metadata.items('preprocess')],
377 {'needsExt': True} 377 {'needsExt': True},
378 ) 378 )
379 379
380 if metadata.has_section('import_locales'): 380 if metadata.has_section('import_locales'):
381 import_locales(params, files) 381 import_locales(params, files)
382 382
383 files['manifest.json'] = createManifest(params, files) 383 files['manifest.json'] = createManifest(params, files)
384 if type == 'chrome': 384 if type == 'chrome':
385 fix_translations_for_chrome(files) 385 fix_translations_for_chrome(files)
386 386
387 if devenv: 387 if devenv:
388 add_devenv_requirements(files, metadata, params) 388 add_devenv_requirements(files, metadata, params)
389 389
390 zipdata = files.zipToString() 390 zipdata = files.zipToString()
391 signature = None 391 signature = None
392 pubkey = None 392 pubkey = None
393 if keyFile != None: 393 if keyFile != None:
394 signature = signBinary(zipdata, keyFile) 394 signature = signBinary(zipdata, keyFile)
395 pubkey = getPublicKey(keyFile) 395 pubkey = getPublicKey(keyFile)
396 writePackage(outFile, pubkey, signature, zipdata) 396 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW
« no previous file with comments | « localeTools.py ('k') | packagerEdge.py » ('j') | tox.ini » ('J')

Powered by Google App Engine
This is Rietveld