Index: third_party/typ/run |
diff --git a/third_party/typ/run b/third_party/typ/run |
new file mode 100755 |
index 0000000000000000000000000000000000000000..22ea7ad82e1605fcab8e82cf0d40d6961acab66b |
--- /dev/null |
+++ b/third_party/typ/run |
@@ -0,0 +1,149 @@ |
+#!/usr/bin/env python |
+ |
+from __future__ import print_function |
+ |
+import argparse |
+import os |
+import subprocess |
+import sys |
+ |
+from tools import cov |
+ |
+ |
+is_python3 = bool(sys.version_info.major == 3) |
+has_python34 = False |
+ |
+ |
+def call(*args, **kwargs): |
+ ret = subprocess.call(*args, **kwargs) |
+ if ret != 0: |
+ sys.exit(ret) |
+ |
+ |
+def main(argv): |
+ parser = argparse.ArgumentParser() |
+ subps = parser.add_subparsers() |
+ |
+ subp = subps.add_parser('build', help='build the package') |
+ subp.set_defaults(func=run_build) |
+ |
+ subp = subps.add_parser('clean', help='Remove any local files.') |
+ subp.set_defaults(func=run_clean) |
+ |
+ subp = subps.add_parser('coverage', |
+ help='Run the tests and report code coverage.') |
+ subp.set_defaults(func=run_coverage) |
+ cov.add_arguments(subp) |
+ |
+ subp = subps.add_parser('develop', |
+ help='Install a symlinked package locally.') |
+ subp.set_defaults(func=run_develop) |
+ subp.add_argument('--system', action='store_true', |
+ help=('Install to the system site-package dir ' |
+ 'rather than the user\'s (requires root).')) |
+ |
+ subp = subps.add_parser('format', |
+ help='Reformat the source code.') |
+ subp.set_defaults(func=run_format) |
+ |
+ subp = subps.add_parser('help', |
+ help='Get help on a subcommand.') |
+ subp.add_argument(nargs='?', action='store', dest='subcommand', |
+ help='The command to get help for.') |
+ subp.set_defaults(func=run_help) |
+ |
+ subp = subps.add_parser('install', |
+ help='build the package and install locally.') |
+ subp.set_defaults(func=run_install) |
+ subp.add_argument('--system', action='store_true', |
+ help=('Install to the system site-package dir ' |
+ 'rather than the user\'s (requires root).')) |
+ |
+ subp = subps.add_parser('lint', |
+ help='run lint over the source') |
+ subp.set_defaults(func=run_lint) |
+ |
+ subp = subps.add_parser('tests', |
+ help='run the tests') |
+ subp.set_defaults(func=run_tests) |
+ |
+ args = parser.parse_args(argv) |
+ |
+ global has_python34 |
+ try: |
+ if subprocess.checkout(['python3', '--version']).startswith( |
+ 'Python 3.4'): |
+ has_python34 = True |
+ except: |
+ pass |
+ args.func(args) |
+ |
+ |
+def run_build(args): |
+ call([sys.executable, 'setup.py', 'build', '--quiet']) |
+ |
+ |
+def run_clean(args): |
+ call(['git', 'clean', '-fxd']) |
+ |
+ |
+def run_coverage(args): |
+ repo_dir = os.path.abspath(os.path.dirname(__file__)) |
+ path_to_cov = os.path.join(repo_dir, 'tools', 'cov.py') |
+ if not args.path: |
+ args.path = [repo_dir] |
+ if not args.source: |
+ args.source = [os.path.join(repo_dir, 'typ')] |
+ argv = cov.argv_from_args(args) |
+ cov_args = ['-m', 'typ', '-q', '-j', '1'] |
+ call(['python', path_to_cov] + argv + cov_args) |
+ if has_python34: |
+ call(['python3', path_to_cov] + argv + cov_args) |
+ |
+ |
+def run_develop(args): |
+ call([sys.executable, 'setup.py', 'develop']) |
+ |
+ |
+def run_format(args): |
+ call('autopep8 --in-place *.py */*.py */*/*.py', shell=True) |
+ |
+ |
+def run_help(args): |
+ if args.subcommand: |
+ main([args.subcommand, '--help']) |
+ main(['--help']) |
+ |
+ |
+def run_install(args): |
+ if args.system: |
+ argv = [] |
+ else: |
+ argv = ['--user'] |
+ call([sys.executable, 'setup.py', 'install'] + argv) |
+ |
+ |
+def run_lint(args): |
+ call('pylint --rcfile=pylintrc */*.py */*/*.py', shell=True) |
+ call('pep8 *.py */*.py */*/*.py', shell=True) |
+ |
+ |
+def run_tests(args): |
+ # Tests that we can run the command line directly if typ is in sys.path. |
+ call(['python', os.path.join('typ', 'cmdline.py'), '-q', |
+ 'typ.tests.main_test.TestMain.test_basic']) |
+ |
+ # Test that we can run the command line directly if typ is not in sys.path. |
+ repo_dir = os.path.abspath(os.path.dirname(__file__)) |
+ home_dir = os.environ['HOME'] |
+ call(['python', os.path.join(repo_dir, 'typ', 'cmdline.py'), '-q', |
+ 'typ.tests.main_test.TestMain.test_basic'], cwd=home_dir) |
+ |
+ # Now run all the tests under Python2 and Python3. |
+ call(['python', '-m', 'typ', '-q']) |
+ if has_python34: |
+ call(['python3', '-m', 'typ', '-q']) |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main(sys.argv[1:])) |