Enterprise policy: Ignore the deprecated ForceSafeSearch if ForceGoogleSafeSearch...
[chromium-blink-merge.git] / third_party / typ / run
blob62558a630fdd22f4f91345d438c8938439b9be02
1 #!/usr/bin/env python
3 from __future__ import print_function
5 import argparse
6 import os
7 import subprocess
8 import sys
10 from tools import cov
13 is_python3 = bool(sys.version_info.major == 3)
14 has_python34 = False
15 verbose = False
16 repo_dir = os.path.abspath(os.path.dirname(__file__))
17 path_to_cov = os.path.join(repo_dir, 'tools', 'cov.py')
18 path_to_runner = os.path.join(repo_dir, 'typ', 'runner.py')
21 def call(*args, **kwargs):
22 if verbose:
23 print(' '.join(args[0]))
24 ret = subprocess.call(*args, **kwargs)
25 if ret != 0:
26 sys.exit(ret)
29 def main(argv):
30 parser = argparse.ArgumentParser()
31 parser.add_argument('--no3', action='store_true',
32 help='Do not run the tests under Python 3.')
33 parser.add_argument('-v', '--verbose', action='store_true')
34 subps = parser.add_subparsers()
36 subp = subps.add_parser('build', help='build the package')
37 subp.set_defaults(func=run_build)
39 subp = subps.add_parser('clean', help='Remove any local files.')
40 subp.set_defaults(func=run_clean)
42 subp = subps.add_parser('coverage',
43 help='Run the tests and report code coverage.')
44 subp.set_defaults(func=run_coverage)
45 cov.add_arguments(subp)
47 subp = subps.add_parser('develop',
48 help='Install a symlinked package locally.')
49 subp.set_defaults(func=run_develop)
50 subp.add_argument('--system', action='store_true',
51 help=('Install to the system site-package dir '
52 'rather than the user\'s (requires root).'))
54 subp = subps.add_parser('format',
55 help='Reformat the source code.')
56 subp.set_defaults(func=run_format)
58 subp = subps.add_parser('help',
59 help='Get help on a subcommand.')
60 subp.add_argument(nargs='?', action='store', dest='subcommand',
61 help='The command to get help for.')
62 subp.set_defaults(func=run_help)
64 subp = subps.add_parser('install',
65 help='build the package and install locally.')
66 subp.set_defaults(func=run_install)
67 subp.add_argument('--system', action='store_true',
68 help=('Install to the system site-package dir '
69 'rather than the user\'s (requires root).'))
71 subp = subps.add_parser('lint',
72 help='run lint over the source')
73 subp.set_defaults(func=run_lint)
75 subp = subps.add_parser('tests',
76 help='run the tests')
77 subp.set_defaults(func=run_tests)
79 args = parser.parse_args(argv)
81 global verbose
82 if args.verbose:
83 verbose = True
84 global has_python34
85 if not args.no3:
86 try:
87 ver = subprocess.check_output(['python3', '--version'])
88 has_python34 = ver.split()[1] >= '3.4'
89 except:
90 pass
91 args.func(args)
94 def run_build(args):
95 call([sys.executable, 'setup.py', 'build', '--quiet'])
98 def run_clean(args):
99 call(['git', 'clean', '-fxd'])
102 def run_coverage(args):
103 if not args.path:
104 args.path = [repo_dir]
105 if not args.source:
106 args.source = [os.path.join(repo_dir, 'typ')]
107 argv = cov.argv_from_args(args)
108 cov_args = [path_to_runner, '-j', '1']
109 call(['python', path_to_cov] + argv + cov_args)
110 if has_python34:
111 call(['python3', path_to_cov] + argv + cov_args)
114 def run_develop(args):
115 call([sys.executable, 'setup.py', 'develop'])
118 def run_format(args):
119 call('autopep8 --in-place *.py */*.py */*/*.py', shell=True)
122 def run_help(args):
123 if args.subcommand:
124 main([args.subcommand, '--help'])
125 main(['--help'])
128 def run_install(args):
129 if args.system:
130 argv = []
131 else:
132 argv = ['--user']
133 call([sys.executable, 'setup.py', 'install'] + argv)
136 def run_lint(args):
137 call('pylint --rcfile=pylintrc */*.py */*/*.py', shell=True)
138 call('pep8 *.py */*.py */*/*.py', shell=True)
141 def run_tests(args):
142 # Test that we can run the module directly if typ is in sys.path.
143 call(['python', '-m', 'typ', 'typ.tests.main_test.TestMain.test_basic'])
145 # Test that we can run the command line directly if typ is not in sys.path.
146 home_dir = os.environ['HOME']
147 call(['python', path_to_runner, 'typ.tests.main_test.TestMain.test_basic'],
148 cwd=home_dir)
150 # Now run all the tests under Python2 and Python3.
151 call(['python', path_to_runner])
152 if has_python34:
153 call(['python3', path_to_runner])
156 if __name__ == '__main__':
157 sys.exit(main(sys.argv[1:]))