gearbox-macros 0.0.1

Support library for Gearbox adding proc macros
Documentation
import subprocess
from bs4 import BeautifulSoup

def generate_readme():
    try:
        # Run the `cargo readme` command and capture its output
        result = subprocess.run(['cargo', 'readme'], capture_output=True, text=True, check=True)

        # Write the output to README.md
        with open('README.md', 'w') as file:
            file.write(result.stdout)

        print("README.md has been generated successfully.")
    except subprocess.CalledProcessError as e:
        print(f"An error occurred while running 'cargo readme': {e}")
        print(f"Error output: {e.stderr}")

# Function to generate the markdown table header
def generate_header():
    return ("| File | Coverage Bar | Line Coverage | Lines Covered | Lines Total |\n"
            "|------|--------------|---------------|---------------|-------------|\n")

# Function to generate the markdown table row for each record
def generate_row(file_name, line_coverage, lines_covered, lines_total):
    coverage_bar = generate_bar(line_coverage)
    return f"| {file_name} | {coverage_bar} | {line_coverage}% | {lines_covered} | {lines_total} |\n"

# Function to generate the coverage bar as an image
def generate_bar(coverage):
    coverage_int = int(round(coverage))
    return f"![](https://geps.dev/progress/{coverage_int})"

# File path to the HTML report
html_file = ".artifacts/coverage/html/index.html"

# Generate the markdown report
markdown_report = generate_header()

# Parse the HTML file
with open(html_file, "r") as file:
    soup = BeautifulSoup(file, "html.parser")

# Parse the HTML file and generate rows
rows = soup.find_all("tr")

for row in rows[1:]:
    cells = row.find_all("td")
    if len(cells) >= 6:
        file_name = row.find("th").text.strip()
        line_coverage = float(cells[1].text.strip().strip('%'))
        lines_covered, lines_total = map(int, cells[2].text.strip().split('/'))
        branch_coverage = cells[5].text.strip().strip('%')
        branches_covered, branches_total = map(int, cells[6].text.strip().split('/'))

        markdown_report += generate_row(file_name, line_coverage, lines_covered, lines_total)

# Generate the README.md content with the test status included
def replace_test_status(readme_content, test_status_content):
    return readme_content.replace('[See Test Status](./TEST_STATUS.md)', test_status_content)

# Run the function to generate README.md from cargo readme
generate_readme()

# Read the generated README.md content
with open('README.md', 'r') as file:
    readme_content = file.read()

# Replace the placeholder with the markdown report
updated_readme_content = replace_test_status(readme_content, markdown_report)

# Write the updated content back to README.md
with open('README.md', 'w') as file:
    file.write(updated_readme_content)

# Output the markdown report to TEST_STATUS.md
file_path = "TEST_STATUS.md"
with open(file_path, "w") as file:
    file.write(markdown_report)