3 from __future__
import print_function
13 is_python3
= bool(sys
.version_info
.major
== 3)
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
):
23 print(' '.join(args
[0]))
24 ret
= subprocess
.call(*args
, **kwargs
)
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',
77 subp
.set_defaults(func
=run_tests
)
79 args
= parser
.parse_args(argv
)
87 ver
= subprocess
.check_output(['python3', '--version'])
88 has_python34
= ver
.split()[1] >= '3.4'
95 call([sys
.executable
, 'setup.py', 'build', '--quiet'])
99 call(['git', 'clean', '-fxd'])
102 def run_coverage(args
):
104 args
.path
= [repo_dir
]
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
)
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)
124 main([args
.subcommand
, '--help'])
128 def run_install(args
):
133 call([sys
.executable
, 'setup.py', 'install'] + argv
)
137 call('pylint --rcfile=pylintrc */*.py */*/*.py', shell
=True)
138 call('pep8 *.py */*.py */*/*.py', shell
=True)
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'],
150 # Now run all the tests under Python2 and Python3.
151 call(['python', path_to_runner
])
153 call(['python3', path_to_runner
])
156 if __name__
== '__main__':
157 sys
.exit(main(sys
.argv
[1:]))