Skip to content

Commit f931473

Browse files
committed
made the a callable module
1 parent 229e9d1 commit f931473

File tree

5 files changed

+73
-44
lines changed

5 files changed

+73
-44
lines changed

.coveragerc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[run]
2+
omit =
3+
# Don't complain if non-runnable code isn't run:
4+
*/__main__.py
5+
6+
[report]
7+
exclude_lines =
8+
# Have to re-enable the standard pragma
9+
\#\s*pragma: no cover
10+
11+
# Don't complain if non-runnable code isn't run:
12+
^if __name__ == ['"]__main__['"]:$
13+
^\s*if False:

bin/junitparser

-43
This file was deleted.

junitparser/__main__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sys
2+
3+
from .cli import main
4+
5+
sys.exit(main(prog_name=__package__))

junitparser/cli.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from argparse import ArgumentParser
2+
3+
from . import JUnitXml, version
4+
5+
6+
def merge(paths, output):
7+
"""Merge xml report.
8+
"""
9+
result = sum((JUnitXml.fromfile(path) for path in paths), JUnitXml())
10+
result.update_statistics()
11+
result.write(output)
12+
return 0
13+
14+
15+
def _parser(prog_name=None): # pragma: no cover
16+
"""Create the CLI arg parser.
17+
"""
18+
parser = ArgumentParser(
19+
description='Junitparser CLI helper.',
20+
prog=prog_name)
21+
22+
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + version)
23+
24+
command_parser = parser.add_subparsers(
25+
dest='command',
26+
help='command')
27+
command_parser.required = True
28+
29+
# command: merge
30+
merge_parser = command_parser.add_parser(
31+
'merge',
32+
help='Merge Junit XML format reports with junitparser.')
33+
merge_parser.add_argument(
34+
'paths',
35+
nargs='+',
36+
help='Original XML path(s).')
37+
merge_parser.add_argument(
38+
'output',
39+
help='Merged XML Path.')
40+
41+
return parser
42+
43+
44+
def main(args=None, prog_name=None):
45+
"""CLI's main runner.
46+
"""
47+
args = args or _parser(prog_name=prog_name).parse_args()
48+
if args.command == 'merge':
49+
return merge(args.paths, args.output)
50+
return 255

setup.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@ def read(fname):
3636
install_requires=['future'],
3737
keywords='junit xunit xml parser',
3838
packages=find_packages(),
39-
scripts=['bin/junitparser'],
39+
entry_points={
40+
'console_scripts': [
41+
'junitparser=junitparser.cli:main'
42+
]
43+
},
4044
zip_safe=False)

0 commit comments

Comments
 (0)