Skip to content

feat(cli): model comparison CLI + comparison docs fixes#158

Merged
villelaitila merged 1 commit into
softagram:mainfrom
villelaitila:feature/model-compare-cli
Jun 18, 2026
Merged

feat(cli): model comparison CLI + comparison docs fixes#158
villelaitila merged 1 commit into
softagram:mainfrom
villelaitila:feature/model-compare-cli

Conversation

@villelaitila

Copy link
Copy Markdown
Contributor

Summary

Adds a CLI for comparing two sgraph models from the shell, and fixes the comparison documentation, which described an API that does not exist.

What's new

python -m sgraph.cli.compare MODEL_A MODEL_B [options] — diff two models (MODEL_A = before, MODEL_B = after):

  • -f, --format {text,json} — human-readable summary (reuses ModelCompare.printCompareInfos()) or pretty-printed JSON
  • -o, --output FILE — write to a file instead of stdout
  • --rename-detection — collapse an add+remove into a changed element annotated with old_name
  • --exclude-attrs a,b,c — ignore the given attributes during comparison

Exit codes follow git diff (0 = no differences, 1 = differences, 2 = error), so it works as a change gate in CI.

The CLI mirrors the existing sgraph.cypher CLI conventions (argparse, progress to stderr, results to stdout). No packaging change — it runs via python -m, like the other tools.

Docs

docs/api-reference.md and docs/examples.md documented an API that does not exist (compare() returning a dict, a calculateSimilarity() method, and an Example 9 that called .get() on the result). They now match the real API: compare()/compareModels() return an SGraph, and getCompareInfos()/printCompareInfos() extract structured results. README.md gains a short "Comparing models" section, and the new command is documented in the CLI Tools reference.

Testing

  • tests/cli/test_compare_cli.py — 7 tests: text + JSON output, the three exit codes, --exclude-attrs suppression, and --rename-detection collapsing add+remove into a change.
  • flake8 src/sgraph/cli/compare.py clean (max line length 100).
  • Full suite green except 6 pre-existing, unrelated failures in tests/test_release_automation.py (module 'release' has no attribute 'time'), which fail identically on main.

Add a shell entry point for comparing two sgraph models:

    python -m sgraph.cli.compare MODEL_A MODEL_B [options]

Modeled on the existing sgraph.cypher CLI (argparse, status to stderr).
Options: -f/--format {text,json}, -o/--output FILE, --rename-detection,
--exclude-attrs a,b,c. Output is either the human-readable
printCompareInfos() summary (text) or pretty-printed JSON listing added,
removed and changed elements and dependencies.

Exit codes follow git diff conventions so the command is usable as a
change gate in scripts/CI:
    0  no differences
    1  differences found
    2  error (bad path, parse failure, usage error)

Also correct the comparison documentation, which described an API that
does not exist (compare() returning a dict, a calculateSimilarity()
method, and an Example 9 that called .get() on the result). The docs now
match the real ModelCompare API: compare()/compareModels() return an
SGraph, and getCompareInfos()/printCompareInfos() extract structured
results.

Implementation is split into a testable run(argv) -> int core and a thin
main(); 7 tests cover both output formats, the three exit codes,
--exclude-attrs and --rename-detection.
@softagram-bot

Copy link
Copy Markdown

Softagram Impact Report for pull/158 (head commit: 910c308)

TL;DR Changed code files: 3 | Directly impacted code files: 0

⭐ Change Overview

Showing the changed files, dependency changes and the impact - click for full size
(Open in Softagram Desktop for full details)

⭐ Details of Dependency Changes

details of dependency changes - click for full size
(Open in Softagram Desktop for full details)

[]

📄 Full report

Impact Report explained. Give feedback on this report to support@softagram.com

@villelaitila villelaitila merged commit 6be2bd4 into softagram:main Jun 18, 2026
1 check passed
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.

2 participants