Skip to content

Compatibility Issue: ScanCode fails with Click 8.3.0 - "Secondary flag is not valid for non-boolean flag"ย #4573

@karthiknew07

Description

@karthiknew07

Description

ScanCode 32.4.1 fails to start when Click 8.3.0 is installed, throwing a TypeError: Secondary flag is not valid for non-boolean flag. This appears to be a compatibility issue between ScanCode's CLI option definitions and stricter validation introduced in Click 8.3.0.

Error Message

Traceback (most recent call last):
  File "/tmp/scancode-env/bin/scancode", line 5, in <module>
    from scancode.cli import scancode
  File "/tmp/scancode-env/lib/python3.10/site-packages/scancode/cli.py", line 383, in <module>
    def scancode(
  File "/tmp/scancode-env/lib/python3.10/site-packages/click/decorators.py", line 374, in decorator
    _param_memo(f, cls(param_decls, **attrs))
  File "/tmp/scancode-env/lib/python3.10/site-packages/commoncode/cliutils.py", line 454, in __init__
    super(PluggableCommandLineOption, self).__init__(
  File "/tmp/scancode-env/lib/python3.10/site-packages/click/core.py", line 2793, in __init__
    raise TypeError("Secondary flag is not valid for non-boolean flag.")
TypeError: Secondary flag is not valid for non-boolean flag.

How To Reproduce

  1. Install scancode-toolkit 32.4.1 via pip:
  2. pip install scancode-toolkit==32.4.1

  3. This will automatically install Click 8.3.0 (latest version)
  4. Try to run any scancode command:
  5. scancode --license <repo-path>

  6. Observe the error above

Environment Information

  • ScanCode Version: 32.4.1
  • Click Version: 8.3.0 (problematic), 8.2.1 (works)
  • Python Version: 3.10 (but likely affects other versions)
  • OS: Linux x64 (but likely affects other platforms)
  • Installation Method: pip install

Root Cause Analysis

The issue appears to be in commoncode/cliutils.pyline 454, where PluggableCommandLineOption is trying to create CLI options that Click 8.3.0 considers invalid. Specifically, Click 8.3.0 introduced stricter validation that prohibits secondary flags (like --flag/--no-flag) for non-boolean options.

Current Workaround

Downgrade Click to the previously working version:

pip install click==8.2.1 --upgrade

Suggested Solution

Update ScanCode's CLI option definitions to be compatible with Click 8.3.0's stricter validation rules. This likely involves:

  1. Reviewing all CLI options defined in ```commoncode/cliutils.py``` and related files
  2. Ensuring that only boolean flags use secondary flag patterns
  3. Updating any non-boolean options that incorrectly use secondary flags
  4. Testing with both Click 8.2.1 and 8.3.0 to ensure backward compatibility

Additional Context

  • The pre-built ScanCode release archive (TAR) works because it includes its own venv with Click 8.2.1
  • This affects users who install via pip, as they get the latest Click version automatically
  • Multiple users have reported this issue independently

Dependency Version Information

Working combination (from release archive):

  • scancode-toolkit: 32.4.1
  • click: 8.2.1

Failing combination (from pip install):

  • scancode-toolkit: 32.4.1
  • click: 8.3.0

Request

Could the maintainers please:

  1. Update the code to be compatible with Click 8.3.0
  2. Consider pinning Click to a specific version range in requirements until compatibility is ensured
  3. Update the installation documentation to mention this compatibility issue as a temporary workaround
  4. Thank you for maintaining this valuable tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions