@@ -59,14 +59,15 @@ def file_exists(rootdir, filename):
59
59
return False
60
60
61
61
62
- def generate_filename (sources , filename ):
62
+ def generate_filename (sources , filename , git_directory ):
63
63
def strip_prefix (line , prefix ):
64
64
if line .startswith (prefix ):
65
65
return line [len (prefix ):]
66
66
else :
67
67
return line
68
68
69
- git_directory = get_git_directory ()
69
+ if not git_directory :
70
+ git_directory = get_git_directory ()
70
71
71
72
for source in sources :
72
73
if file_exists (source , filename ):
@@ -75,7 +76,7 @@ def strip_prefix(line, prefix):
75
76
return filename
76
77
77
78
78
- def parse_report_file (report_file ):
79
+ def parse_report_file (report_file , git_directory ):
79
80
"""Parse XML file and POST it to the Codacy API
80
81
:param report_file:
81
82
"""
@@ -97,7 +98,7 @@ def percent(s):
97
98
classes = report_xml .getElementsByTagName ('class' )
98
99
for cls in classes :
99
100
file_report = {
100
- 'filename' : generate_filename (sources , cls .attributes ['filename' ].value ),
101
+ 'filename' : generate_filename (sources , cls .attributes ['filename' ].value , git_directory ),
101
102
'total' : percent (cls .attributes ['line-rate' ].value ),
102
103
'coverage' : {},
103
104
}
@@ -141,6 +142,7 @@ def run():
141
142
parser = argparse .ArgumentParser (description = 'Codacy coverage reporter for Python.' )
142
143
parser .add_argument ("-r" , "--report" , type = str , help = "coverage report file" , default = DEFAULT_REPORT_FILE )
143
144
parser .add_argument ("-c" , "--commit" , type = str , help = "git commit hash" )
145
+ parser .add_argument ("-d" , "--directory" , type = str , help = "git top level directory" )
144
146
parser .add_argument ("-v" , "--verbose" , help = "show debug information" , action = "store_true" )
145
147
146
148
args = parser .parse_args ()
@@ -160,7 +162,7 @@ def run():
160
162
exit (1 )
161
163
162
164
logging .info ("Parsing report file..." )
163
- report = parse_report_file (args .report )
165
+ report = parse_report_file (args .report , args . directory )
164
166
165
167
logging .info ("Uploading report..." )
166
168
upload_report (report , CODACY_PROJECT_TOKEN , args .commit )
0 commit comments