11import argparse
2- import inspect
32from os .path import dirname
3+ import pathlib
44import subprocess
55import sys
6+ import typing
67
78
89class PyFrcCoverage :
910 """
10- Wraps other commands by running them via the coverage module. Requires
11- the coverage module to be installed.
11+ Wraps other commands by running them via the coverage module.
12+
13+ Requires the coverage module to be installed.
1214 """
1315
1416 def __init__ (self , parser : argparse .ArgumentParser ):
@@ -19,7 +21,13 @@ def __init__(self, parser: argparse.ArgumentParser):
1921 "args" , nargs = argparse .REMAINDER , help = "Arguments to pass to robot.py"
2022 )
2123
22- def run (self , options , robot_class , ** static_options ):
24+ def run (
25+ self ,
26+ main_file : pathlib .Path ,
27+ project_path : pathlib .Path ,
28+ parallel_mode : bool ,
29+ args : typing .List [str ],
30+ ):
2331 try :
2432 import coverage
2533 except ImportError :
@@ -30,13 +38,11 @@ def run(self, options, robot_class, **static_options):
3038 )
3139 return 1
3240
33- if len (options . args ) == 0 :
41+ if len (args ) == 0 :
3442 print ("ERROR: Coverage command requires arguments to run other commands" )
3543 return 1
3644
37- file_location = inspect .getfile (robot_class )
38-
39- option_args = list (options .args )
45+ option_args = args
4046 if option_args [0 ] == "test" :
4147 option_args .insert (1 , "--coverage-mode" )
4248
@@ -47,19 +53,20 @@ def run(self, options, robot_class, **static_options):
4753 "coverage" ,
4854 "run" ,
4955 "--source" ,
50- dirname ( file_location ),
56+ str ( project_path ),
5157 ]
52- if options . parallel_mode :
58+ if parallel_mode :
5359 args .append ("--parallel-mode" )
5460
55- args . append ( file_location )
61+ args += [ "-m" , "robotpy" , "--main" , main_file ]
5662 args += option_args
5763
64+ print ("+" , * args , file = sys .stderr )
5865 retval = subprocess .call (args )
5966 if retval != 0 :
6067 return retval
6168
62- if options . parallel_mode :
69+ if parallel_mode :
6370 subprocess .call ([sys .executable , "-m" , "coverage" , "combine" ])
6471
6572 args = [sys .executable , "-m" , "coverage" , "report" , "-m" ]
0 commit comments