62 lines
2.4 KiB
Python
62 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Fix coverage paths for Coverage Gutters extension.
|
|
This script modifies the coverage.xml file to use relative paths instead of absolute paths.
|
|
"""
|
|
|
|
import xml.etree.ElementTree as ET
|
|
import os
|
|
|
|
|
|
def fix_coverage_paths():
|
|
"""Fix the paths in coverage.xml to be relative to the workspace root."""
|
|
|
|
# Read the coverage.xml file
|
|
tree = ET.parse('coverage.xml')
|
|
root = tree.getroot()
|
|
|
|
# Get the current working directory
|
|
current_dir = os.getcwd()
|
|
print(f"Current directory: {current_dir}")
|
|
|
|
# Find and update the source element
|
|
sources = root.find('sources')
|
|
if sources is not None:
|
|
for source in sources.findall('source'):
|
|
old_path = source.text
|
|
print(f"Old source path: {old_path}")
|
|
|
|
# Convert absolute path to relative path
|
|
if old_path.startswith(current_dir):
|
|
# Remove the current directory part and the extra 'pyWebLayout' part
|
|
relative_path = old_path.replace(current_dir + '/pyWebLayout', './pyWebLayout')
|
|
# Or just use current directory
|
|
relative_path = '.'
|
|
source.text = relative_path
|
|
print(f"New source path: {relative_path}")
|
|
|
|
# Update all filename attributes in class elements to be relative
|
|
for package in root.findall('.//package'):
|
|
for cls in package.findall('classes/class'):
|
|
filename = cls.get('filename')
|
|
if filename:
|
|
# Ensure filename is relative to project root
|
|
if not filename.startswith('./') and not filename.startswith('pyWebLayout/'):
|
|
# Add pyWebLayout/ prefix if it's just a bare filename
|
|
if '/' not in filename:
|
|
# This is a top-level file
|
|
new_filename = f"pyWebLayout/{filename}"
|
|
else:
|
|
# This already has a path, just prefix with pyWebLayout/
|
|
new_filename = f"pyWebLayout/{filename}"
|
|
cls.set('filename', new_filename)
|
|
print(f"Updated filename: {filename} -> {new_filename}")
|
|
|
|
# Save the modified XML
|
|
tree.write('coverage.xml', encoding='utf-8', xml_declaration=True)
|
|
print("Coverage paths fixed successfully!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
fix_coverage_paths()
|