Skip to content

install importlib_metadata on Python < 3.8 #1889

@vphilippon

Description

@vphilippon

click 8.0.0 now relies on importlib.metadata under certain conditions.
On Python 3.8, click will raise an error and ask the user to install the importlib_metadata backport package.

Ex:

Traceback (most recent call last):
  File "/path_to_my_venv/bin/myexecutable", line 8, in <module>
    sys.exit(cli())
  File "/path_to_my_venv/lib/python3.6/site-packages/click/core.py", line 1134, in __call__
    return self.main(*args, **kwargs)
  File "/path_to_my_venv/lib/python3.6/site-packages/click/core.py", line 1058, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/path_to_my_venv/lib/python3.6/site-packages/click/core.py", line 927, in make_context
    self.parse_args(ctx, args)
  File "/path_to_my_venv/lib/python3.6/site-packages/click/core.py", line 1621, in parse_args
    rest = super().parse_args(ctx, args)
  File "/path_to_my_venv/lib/python3.6/site-packages/click/core.py", line 1376, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/path_to_my_venv/lib/python3.6/site-packages/click/core.py", line 2352, in handle_parse_result
    value = self.process_value(ctx, value)
  File "/path_to_my_venv/lib/python3.6/site-packages/click/core.py", line 2314, in process_value
    value = self.callback(ctx, self, value)
  File "/path_to_my_venv/lib/python3.6/site-packages/click/decorators.py", line 380, in callback
    "Install 'importlib_metadata' to get the version on Python < 3.8."
RuntimeError: Install 'importlib_metadata' to get the version on Python < 3.8.

The user can install importlib_metadata, but I think Click could use environment markers to install the importlib_metadata backport package on Python 3.8, in the same manner that colorama is installed on Windows.

I will send a PR soon. Feel free to express any concerns, doubts or considerations to the project context that I've missed.

Environment:

  • Python version: 3.6
  • Click version: 8.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions