py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2015-10-26 17:11:44 +01:00
|
|
|
|
2016-08-29 01:02:03 +02:00
|
|
|
import argparse
|
2015-10-26 17:11:44 +01:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2017-05-25 20:12:33 +02:00
|
|
|
import json
|
2015-10-26 17:11:44 +01:00
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
2015-10-26 17:11:44 +01:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
os.chdir(settings.DEPLOY_ROOT)
|
|
|
|
STATIC_PATH = 'static/'
|
|
|
|
|
2017-05-25 20:12:33 +02:00
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def run():
|
|
|
|
# type: () -> None
|
2016-10-16 07:27:55 +02:00
|
|
|
"""Builds for production, writing the output to disk"""
|
2016-11-25 09:08:38 +01:00
|
|
|
subprocess.check_call(['node', 'node_modules/.bin/webpack'] +
|
2017-07-28 23:13:58 +02:00
|
|
|
['--config', 'tools/webpack.config.ts', '-p'] +
|
2017-07-28 22:53:37 +02:00
|
|
|
['--env', 'production'])
|
2015-10-26 17:11:44 +01:00
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def run_watch(host, port, minify):
|
|
|
|
# type: (str, str, bool) -> None
|
2016-10-16 07:27:55 +02:00
|
|
|
"""watches and rebuilds on changes, serving files from memory via webpack-dev-server"""
|
2017-06-10 20:28:48 +02:00
|
|
|
webpack_args = ['node', 'node_modules/.bin/webpack-dev-server']
|
2017-07-28 23:13:58 +02:00
|
|
|
webpack_args += ['--config', 'tools/webpack.config.ts', '--watch-poll', '--port', port, "--host", host]
|
2017-06-10 20:28:48 +02:00
|
|
|
if minify:
|
|
|
|
webpack_args.append('--optimize-minimize')
|
|
|
|
subprocess.Popen(webpack_args)
|
2015-10-26 17:11:44 +01:00
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def run_test():
|
|
|
|
# type: () -> None
|
2017-05-25 20:12:33 +02:00
|
|
|
"""Generates a stub asset stat file for django so backend test can render a page"""
|
|
|
|
entries = {}
|
|
|
|
with open('tools/webpack.assets.json') as json_data:
|
|
|
|
for entry in json.load(json_data).keys():
|
|
|
|
entries[entry] = [{
|
|
|
|
"name": "%s.js" % (entry,),
|
|
|
|
"publicPath": "http://localhost:3000/webpack-stub/%s-stubentry.js" % (entry,),
|
|
|
|
"path": "/stubfolder/%s-stubfile.js" % (entry,)
|
|
|
|
}]
|
|
|
|
stat_data = {
|
|
|
|
"status": "done",
|
|
|
|
"chunks": entries
|
|
|
|
}
|
2017-07-18 21:47:47 +02:00
|
|
|
directory = 'var'
|
2017-05-25 20:12:33 +02:00
|
|
|
if not os.path.exists(directory):
|
|
|
|
os.makedirs(directory)
|
|
|
|
with open(os.path.join(directory, 'webpack-stats-test.json'), 'w') as outfile:
|
|
|
|
json.dump(stat_data, outfile)
|
|
|
|
|
|
|
|
|
2016-08-29 01:02:03 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
2017-05-25 20:12:33 +02:00
|
|
|
parser.add_argument('--test',
|
|
|
|
action='store_true', dest='test', default=False,
|
|
|
|
help='generate a stub webpack-stats.json file (for backend testing)')
|
2016-08-29 01:02:03 +02:00
|
|
|
parser.add_argument('--watch',
|
2016-12-11 14:30:45 +01:00
|
|
|
action='store_true', dest='watch', default=False,
|
|
|
|
help='watch for changes to source files (for development)')
|
2017-07-16 21:14:03 +02:00
|
|
|
parser.add_argument('--host',
|
|
|
|
action='store', dest='host',
|
|
|
|
default='127.0.0.1', help='set the host for the webpack server to run on')
|
2016-08-29 01:02:03 +02:00
|
|
|
parser.add_argument('--port',
|
2016-12-11 14:30:45 +01:00
|
|
|
action='store', dest='port',
|
|
|
|
default='9994', help='set the port for the webpack server to run on')
|
2017-06-10 20:28:48 +02:00
|
|
|
parser.add_argument('--minify',
|
|
|
|
action='store_true', dest='minify', default=False,
|
|
|
|
help='Minify and optimize the assets (for development)')
|
2016-04-13 04:19:56 +02:00
|
|
|
|
2017-05-25 20:12:33 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
if args.test:
|
|
|
|
run_test()
|
|
|
|
elif args.watch:
|
2017-07-16 21:14:03 +02:00
|
|
|
run_watch(args.host, args.port, args.minify)
|
2016-04-13 04:19:56 +02:00
|
|
|
else:
|
|
|
|
run()
|