Skip to content

Conversation

@igorostrowskiq
Copy link

Add script for crate structure analysis and comparison with older results

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new Python script for analyzing and comparing Rust crate structure, specifically focusing on coverage checking. The script can parse crate structure data, filter by visibility and item types, and compare results with reference data to track coverage progress.

Key changes:

  • Added comprehensive crate structure analysis functionality with tree-based data representation
  • Implemented filtering capabilities for visibility levels and item types (functions, structs, enums, etc.)
  • Added reference comparison feature to track coverage changes over time
Comments suppressed due to low confidence (1)

scripts/coverage_checker.py:345

  • Variable name 'all' shadows the built-in function. Consider using 'total' or 'total_nodes' instead.
    all = tree.count_leaf_nodes()

Copy link
Collaborator

@PiotrKorkus PiotrKorkus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look into copilot comments. They aren't that bad and even caught a bug.
I would suggest following structure:

  • create an extra directory coverage_checker in scripts and place script there
  • add bash script with command to generate input file
    We will need some docstrings for sure.
    Let's have a call, as when I try to run it I get quite messy tabs in the output.

with open(args.input, "r") as f:
input_lines = f.readlines()
else:
input_lines = sys.stdin.readlines()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets stop using stdin. Arguments are all we need

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


self.data = line_parts[0]
self.comment = line_parts[-1] if len(line_parts) > 1 else None
self.tab_count = line.count("\t") if self.comment is not None else None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if self.comment else None is enough

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if token.startswith("pub"):
return Visibility(token)

raise RuntimeError("Visibility not detected for: " + data_line)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it f-string

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if found != -1:
return Entry(line, item_type, found)

raise RuntimeError("No known item type found for parsed line: " + line)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string here as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@arkjedrz arkjedrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I don't think parsing languages using scripts is a good idea. In my experience - it is working shabby at best, and causing unsustainable burden to maintain at worst.
  • I feel there might be an overlap with what is expected with https://github.com/cargo-public-api/cargo-public-api
  • I'm missing any kind of rationale or example what's this script for.
  • I was unable to find one file from Persistency repo that will work with this scripts.

@@ -0,0 +1,346 @@
import argparse
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing shebang and docstring.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still to check

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still to check

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Added exe rights
  2. Fixed or suppressed issues found by ruff



class TreeNode:
def __init__(self, entries: list[Entry], ndx: Indexer, parent: Union["TreeNode", None] = None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Union["TreeNode", None] -> "TreeNode" | None

Copy link
Author

@igorostrowskiq igorostrowskiq Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried that initially, but looks that incomplete type is not supported in this syntax:

  File "/home/igor/repos/testing_tools/scripts/coverage_checker.py", line 132, in TreeNode
    def __init__(self, entries: list[Entry], ndx: Indexer, parent: "TreeNode" | None = None):
                                                                   ~~~~~~~~~~~^~~~~~
TypeError: unsupported operand type(s) for |: 'str' and 'NoneType'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it won't work since we are referring to the type through string literal. You can leave it as it is, or use Optional["TreeNode"] but | wont work

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used Optional

@igorostrowskiq igorostrowskiq force-pushed the igorostrowskiq-add-module-coverage-script branch 2 times, most recently from f81630a to 95da068 Compare August 11, 2025 11:48
@igorostrowskiq
Copy link
Author

Take a look into copilot comments. They aren't that bad and even caught a bug. I would suggest following structure:

* create an extra directory `coverage_checker` in scripts and place script there

* add bash script with command to generate input file
  We will need some docstrings for sure.
  Let's have a call, as when I try to run it I get quite messy tabs in the output.
  1. Moved to directory coverage_checker
  2. Added readme with commandline
  3. Added docstrings

@igorostrowskiq igorostrowskiq force-pushed the igorostrowskiq-add-module-coverage-script branch from 95da068 to d795ea1 Compare August 11, 2025 12:42
Copy link
Collaborator

@PiotrKorkus PiotrKorkus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add information about setting tabs 4 for best output representation

Comment on lines 30 to 32
`cd <inc_orchestrator_repo>`
`cargo modules structure --package orchestration | sed 's/\x1b\[[0-9;]*m//g' > input_report.txt` - sed is required to remove colored output
`python3 scripts/coverage_checker.py -r <older_orchestration_report> input_report.txt`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Added double spaces at the end to force new lines. Do not switched to block to avoid having there also explanation for the command.
  2. Fixed
  3. Done



class TreeNode:
def __init__(self, entries: list[Entry], ndx: Indexer, parent: Union["TreeNode", None] = None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it won't work since we are referring to the type through string literal. You can leave it as it is, or use Optional["TreeNode"] but | wont work

@igorostrowskiq
Copy link
Author

  • I don't think parsing languages using scripts is a good idea. In my experience - it is working shabby at best, and causing unsustainable burden to maintain at worst.

    • I feel there might be an overlap with what is expected with https://github.com/cargo-public-api/cargo-public-api

    • I'm missing any kind of rationale or example what's this script for.

    • I was unable to find one file from Persistency repo that will work with this scripts.

  1. It is intermediate solution for our coverage reporting. Once requirements are available we will switch to this metric and abandon the script. There should be no issues with the maintenance.
  2. Similar functionality, also needs filtering and visualization is less human user friendly
  3. Added info in the readme
  4. Should also work with persistency. For now only runtime and orchestrator is checked (https://github.com/qorix-group/inc_orchestrator_internal/discussions/212)

@igorostrowskiq igorostrowskiq force-pushed the igorostrowskiq-add-module-coverage-script branch from d795ea1 to e76683e Compare August 11, 2025 13:26
@igorostrowskiq
Copy link
Author

Please add information about setting tabs 4 for best output representation

Added in the readme

@igorostrowskiq igorostrowskiq marked this pull request as ready for review August 11, 2025 13:30
@igorostrowskiq igorostrowskiq force-pushed the igorostrowskiq-add-module-coverage-script branch from e76683e to fe727ed Compare August 12, 2025 06:47
@igorostrowskiq igorostrowskiq merged commit c658427 into main Aug 12, 2025
@igorostrowskiq igorostrowskiq deleted the igorostrowskiq-add-module-coverage-script branch August 12, 2025 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants