Skip to content

version_option module name and package name are not equivalent #2331

Description

@ice-tong

Environment:

  • Python version: 3.8
  • Click version: 8.1

The click.version_option uses the module name to get the package version :

if f_globals is not None:
package_name = f_globals.get("__name__")
if package_name == "__main__":
package_name = f_globals.get("__package__")
if package_name:
package_name = package_name.partition(".")[0]

But module name and package name are not always equivalent. This could be crash when the module name not the same as the package name, eg. open-mmlab/mim#152

Activity

  1. changed the title [-][BUG] [click.version_option()] Module name and package name are not equivalent[/-] [+]version_option module name and package name are not equivalent[/+] on Aug 2, 2022
  2. kdeldycke commented on Sep 4, 2023

    @kdeldycke
    Collaborator

    FYI, I fixed this in Click Extra, where you can use the {module_name} and {package_name} variables independently to form the version string printed by the --version option.

    For more details, see: https://kdeldycke.github.io/click-extra/version.html

  3. Rowlando13 commented on Jan 5, 2025

    @Rowlando13
    Member

    @AndreasBackx This seems like a good candidate to be upstreamed to us. What do you think?

  4. luminexo commented on Mar 14, 2026

    @luminexo
  5. AndreasBackx commented on Mar 15, 2026

    @AndreasBackx
    Collaborator

    Kind of feels like an AI comment. Regardless, you can look at pyproject.toml and you'll see the minimum Python version.

  6. changed the title [-]version_option module name and package name are not equivalent[/-] [+]`version_option` module name and package name are not equivalent[/+] on May 28, 2026
  7. Rowlando13 commented on May 29, 2026

    @Rowlando13
    Member

    Based on #3527, I am going to close this.

  8. kdeldycke commented on May 29, 2026

    @kdeldycke
    Collaborator

    As discussed in #3527 , we will not extend the @version_option decorator.

    If you need something different than the default, you have to produce your own message. Or use the full-featured @click_extra.version_option decorator from the Click Extra project.

  9. kdeldycke commented on Jun 11, 2026

    @kdeldycke
    Collaborator

    As discussed in #3527 , we will not extend the @version_option decorator.

    Revisiting this issue, fixing it does not requires a new slot/field as I initially suggested a couple of years ago. So a fix has been proposed at: #3582 . Can you test it?

  10. added this to the 8.4.2 milestone on Jun 11, 2026
  11. locked as resolved and limited conversation to collaborators on Jul 24, 2026
  12. added
    parsingParsing, parameters, commands, chaining, context
    and removed on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    parsingParsing, parameters, commands, chaining, context

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions