executablebooks / jupyter-book

Create beautiful, publication-quality books and documents from computational content.
http://jupyterbook.org
BSD 3-Clause "New" or "Revised" License
3.76k stars 652 forks source link

AttributeError: 'EntryPoints' object has no attribute 'get' #2146

Open parmentelat opened 2 months ago

parmentelat commented 2 months ago

Describe the bug

context When I do

jupyter book toc migrate _toc.yml
# but also
jupyter book --help

bug I am consistently getting a stack dump ending with

  File "/some/path/lib/python3.12/site-packages/click/core.py", line 1325, in get_help
    self.format_help(ctx, formatter)
  File "/some/path/lib/python3.12/site-packages/click/core.py", line 1358, in format_help
    self.format_options(ctx, formatter)
  File "/some/path/lib/python3.12/site-packages/click/core.py", line 1564, in format_options
    self.format_commands(ctx, formatter)
  File "/some/path/lib/python3.12/site-packages/click/core.py", line 1616, in format_commands
    for subcommand in self.list_commands(ctx):
                      ^^^^^^^^^^^^^^^^^^^^^^^
  File "/some/path/lib/python3.12/site-packages/jupyter_book/cli/pluggable.py", line 38, in list_commands
    subcommands.extend(get_entry_point_names(self._entry_point_group))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/some/path/lib/python3.12/site-packages/jupyter_book/cli/pluggable.py", line 13, in get_entry_point_names
    return [ep.name for ep in metadata.entry_points().get(group, [])]
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'EntryPoints' object has no attribute 'get'

problem obviously the command is having problems displaying its own help...?

note that running a valid command like jupyter book build . works fine

Reproduce the bug

just run the above commands

List your environment

this is on MacOS sonoma 14.4.1

$ jupyter book --version
Jupyter Book      : 1.0.0
External ToC      : 1.0.1
MyST-Parser       : 3.0.1
MyST-NB           : 1.1.0
Sphinx Book Theme : 1.1.2
Jupyter-Cache     : 1.0.0
NbClient          : 0.10.0

$ python --version
Python 3.12.3
mango-matt commented 2 months ago

I have a similar problem. Not sure what the root cause is but downgrading to python3.11 provided a temporary workaround

iso2013 commented 1 month ago

I have the same issue, running the same configuration except with MyST-Parser version 2.0.0.

iso2013 commented 1 month ago

This appears to be because the SelectableGroups class, which implemented a dictionary-like interface for the result of entry_points is deprecated and was removed in Python 3.12.

Here's the class in Python 3.11., and here's the file in 3.12.

The removal of this class means that the function entry_points() in 3.12 can no longer return a dictionary-like object like it did in 3.11.

Unfortunately I think these API changes are to be expected between 3.8 and 3.12, since importlib's metadata functionality was new in 3.8 and only considered to be provisional.

I would suggest either checking to see first if entry_points(group=group) gives an error, and if it does, fall back to the current implementation. I can open a PR soon, although I'm not sure if the suggested fix would be to add this sort of edge case handling, or instead just update the whole project to 3.12 - it seems like from these lines there's some kind of handling of multiple versions.

Edit: From what I can tell, import importlib.metadata would only throw an error before Python 3.8, so those lines can probably be removed outright, since the project seems to require at least 3.9.