Skip to content

Comments

[SP-3728] Fix scanoss-py inspect copyleft help display#184

Closed
descorchator wants to merge 1 commit intomainfrom
gepeto/SP-3728
Closed

[SP-3728] Fix scanoss-py inspect copyleft help display#184
descorchator wants to merge 1 commit intomainfrom
gepeto/SP-3728

Conversation

@descorchator
Copy link

@descorchator descorchator commented Feb 14, 2026

JIRA Ticket: SP-3728

Fix scanoss-py inspect copyleft help display

Changes

Confirmed safe — line 1341 is only reached when subparsercmd is raw/dt/glc/gitlab, which all define subparser_subcmd as a dest in their subparsers. Python evaluates and conditions left-to-right with short-circuit evaluation, so if the second condition is False, line 1341 is never evaluated.


Summary

Root cause: In v1.32.0, the inspect command was refactored to support nested command groups (raw, dt, gitlab) with a subparser_subcmd attribute. Legacy backward-compatible commands (scanoss-py inspect copyleft) were kept at the top level of inspect but their parser doesn't define subparser_subcmd. When any of the four inspect handler functions (inspect_copyleft, inspect_undeclared, inspect_license_summary, inspect_component_summary) tried to display help on missing input, they directly accessed args.subparser_subcmd, causing an AttributeError for legacy commands.

Fix applied in src/scanoss/cli.py — four handler functions modified (lines ~1809, ~1870, ~1929, ~1981):

Changed from:

parser.parse_args([args.subparser, args.subparsercmd, args.subparser_subcmd, '-h'])

To:

subcmd = getattr(args, 'subparser_subcmd', None)
help_args = [args.subparser, args.subparsercmd]
if subcmd:
    help_args.append(subcmd)
help_args.append('-h')
parser.parse_args(help_args)

This safely handles both paths:

  • Legacy path (scanoss-py inspect copyleft): subcmd is None, help args = ['inspect', 'copyleft', '-h']
  • Raw path (scanoss-py inspect raw copyleft): subcmd is 'copyleft', help args = ['inspect', 'raw', 'copyleft', '-h']

This PR was automatically generated by Gepeto Escalante.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling in inspect subcommands to provide contextually appropriate help information when required inputs are missing or invalid.

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

Modified error handling in four inspect subcommands to dynamically build help invocation paths based on available subcommands. When input is missing, the program now determines the appropriate help context instead of using a static help invocation sequence.

Changes

Cohort / File(s) Summary
CLI Error Handling
src/scanoss/cli.py
Modified error handling in copyleft, undeclared, license-summary, and component-summary subcommands to dynamically construct help invocation with subparser context when missing required input, replacing static argument sequences.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

bug

Suggested reviewers

  • isasmendiagus
  • eeisegn

Poem

🐰 The CLI paths now bloom so bright,
With dynamic help contexts set just right,
Four subcommands dance in harmony,
No more static routes—just flexibility! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the main bug fix - addressing help display for the scanoss-py inspect copyleft command, which aligns with the core change of fixing AttributeError in legacy inspect subcommands.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch gepeto/SP-3728

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/scanoss/cli.py (1)

1809-1814: Consider extracting the duplicated help-args logic into a small helper.

This exact 6-line pattern is repeated in all four inspect handlers. A helper would reduce duplication and make future changes easier.

♻️ Suggested helper
+def _print_inspect_help_and_exit(parser, args):
+    """Build context-aware help args and display help for inspect sub-commands."""
+    subcmd = getattr(args, 'subparser_subcmd', None)
+    help_args = [args.subparser, args.subparsercmd]
+    if subcmd:
+        help_args.append(subcmd)
+    help_args.append('-h')
+    parser.parse_args(help_args)
+    sys.exit(1)

Then each handler simplifies to:

     if args.input is None:
         print_stderr('ERROR: Input file is required for copyleft inspection')
-        subcmd = getattr(args, 'subparser_subcmd', None)
-        help_args = [args.subparser, args.subparsercmd]
-        if subcmd:
-            help_args.append(subcmd)
-        help_args.append('-h')
-        parser.parse_args(help_args)
-        sys.exit(1)
+        _print_inspect_help_and_exit(parser, args)

Also applies to: 1870-1875, 1929-1934, 1981-1986


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

SCANOSS SCAN Completed 🚀

  • Detected components: 3
  • Undeclared components: 0
  • Declared components: 3
  • Detected files: 106
  • Detected files undeclared: 0
  • Detected files declared: 106
  • Licenses detected: 2
  • Licenses detected with copyleft: 1
  • Policies: ✅ 1 pass (1 total)

View more details on SCANOSS Action Summary

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