@@ -59,14 +59,15 @@ def file_exists(rootdir, filename):
5959 return False
6060
6161
62- def generate_filename (sources , filename ):
62+ def generate_filename (sources , filename , git_directory ):
6363 def strip_prefix (line , prefix ):
6464 if line .startswith (prefix ):
6565 return line [len (prefix ):]
6666 else :
6767 return line
6868
69- git_directory = get_git_directory ()
69+ if not git_directory :
70+ git_directory = get_git_directory ()
7071
7172 for source in sources :
7273 if file_exists (source , filename ):
@@ -75,7 +76,7 @@ def strip_prefix(line, prefix):
7576 return filename
7677
7778
78- def parse_report_file (report_file ):
79+ def parse_report_file (report_file , git_directory ):
7980 """Parse XML file and POST it to the Codacy API
8081 :param report_file:
8182 """
@@ -97,7 +98,7 @@ def percent(s):
9798 classes = report_xml .getElementsByTagName ('class' )
9899 for cls in classes :
99100 file_report = {
100- 'filename' : generate_filename (sources , cls .attributes ['filename' ].value ),
101+ 'filename' : generate_filename (sources , cls .attributes ['filename' ].value , git_directory ),
101102 'total' : percent (cls .attributes ['line-rate' ].value ),
102103 'coverage' : {},
103104 }
@@ -141,6 +142,7 @@ def run():
141142 parser = argparse .ArgumentParser (description = 'Codacy coverage reporter for Python.' )
142143 parser .add_argument ("-r" , "--report" , type = str , help = "coverage report file" , default = DEFAULT_REPORT_FILE )
143144 parser .add_argument ("-c" , "--commit" , type = str , help = "git commit hash" )
145+ parser .add_argument ("-d" , "--directory" , type = str , help = "git top level directory" )
144146 parser .add_argument ("-v" , "--verbose" , help = "show debug information" , action = "store_true" )
145147
146148 args = parser .parse_args ()
@@ -160,7 +162,7 @@ def run():
160162 exit (1 )
161163
162164 logging .info ("Parsing report file..." )
163- report = parse_report_file (args .report )
165+ report = parse_report_file (args .report , args . directory )
164166
165167 logging .info ("Uploading report..." )
166168 upload_report (report , CODACY_PROJECT_TOKEN , args .commit )
0 commit comments