sphinx-design icon indicating copy to clipboard operation
sphinx-design copied to clipboard

Add support for Python 3.11

Open tirthasheshpatel opened this issue 3 years ago • 2 comments

importlib.resorces.open_text has been deprecated in Python 3.11 in favor of importlib.resources.files. sphinx-design v0.3.0 doesn't work on Python 3.11:

SciPy doc build log
(scipy-dev) tirthasheshpatel@tirthap:~/oss/scipy/doc$ time PYTHONPATH=$PWD/../build-install/lib/python3.11/site-packages SPHINXOPTS='-j12' make -e html
fatal: bad revision '^v1.8.0'
fatal: bad revision '^v1.8.0'
fatal: bad revision '^v1.8.0'
# for testing
# @echo installed scipy 48c3dc8 matches git version 48c3dc8; exit 1
mkdir -p build/html build/doctrees
LANG=C python3 -msphinx -WT --keep-going  -b html -d build/doctrees -j12 source build/html 
Running Sphinx v5.3.0
SciPy (VERSION 1.10.0.dev0+0.48c3dc8)
/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx/util/images.py:4: DeprecationWarning: 'imghdr' is deprecated and slated for removal in Python 3.13
  import imghdr
/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx_design/icons.py:51: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
  content = resources.read_text(compiled, "octicons.json")

Traceback (most recent call last):
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx/cmd/build.py", line 276, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx/application.py", line 223, in __init__
    self.setup_extension(extension)
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx/application.py", line 398, in setup_extension
    self.registry.load_extension(self, extname)
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx/registry.py", line 472, in load_extension
    metadata = setup(app)
               ^^^^^^^^^^
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx_design/__init__.py", line 11, in setup
    from .extension import setup_extension
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx_design/extension.py", line 17, in <module>
    from .dropdown import setup_dropdown
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx_design/dropdown.py", line 55, in <module>
    class DropdownDirective(SphinxDirective):
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx_design/dropdown.py", line 78, in DropdownDirective
    "icon": make_choice(list_octicons()),
                        ^^^^^^^^^^^^^^^
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx_design/icons.py", line 57, in list_octicons
    return list(get_octicon_data().keys())
                ^^^^^^^^^^^^^^^^^^
  File "/home/tirthasheshpatel/oss/virtualenvs/scipy-dev/lib/python3.11/site-packages/sphinx_design/icons.py", line 51, in get_octicon_data
    content = resources.read_text(compiled, "octicons.json")
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/resources/_legacy.py", line 25, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/resources/_legacy.py", line 80, in read_text
    with open_text(package, resource, encoding, errors) as fp:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/resources/_legacy.py", line 18, in wrapper
    warnings.warn(
DeprecationWarning: open_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.

Exception occurred:
  File "/usr/lib/python3.11/importlib/resources/_legacy.py", line 18, in wrapper
    warnings.warn(
DeprecationWarning: open_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
The full traceback has been saved in /tmp/sphinx-err-_7hu10sy.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [Makefile:110: html-build] Error 2

real	0m2.088s
user	0m3.397s
sys	0m2.206s

This PR replaces all the uses of importlib.resources.open_text with the new interface importlib.resources.files. Does this need any tests?

tirthasheshpatel avatar Oct 28 '22 00:10 tirthasheshpatel

Thanks for submitting your first pull request! You are awesome! :hugs:
If you haven't done so already, check out EBP's Code of Conduct and our Contributing Guide, as this will greatly help the review process.
Welcome to the EBP community! :tada:

welcome[bot] avatar Oct 28 '22 00:10 welcome[bot]

Does sphinx-design want to continue to support Python 3.8 (starting from the next release)? If so, I can add a compatibility layer that supports both Python 3.8 and Python 3.11.

tirthasheshpatel avatar Oct 28 '22 00:10 tirthasheshpatel

I went ahead and added support for Python <= 3.8. I think this is ready from my side.

tirthasheshpatel avatar Oct 29 '22 21:10 tirthasheshpatel

LGTM but I am not a maintainer.

v0.3.0 doesn't work on Python 3.11

It works. The reason your build fails is because of:

LANG=C python3 -msphinx -WT --keep-going -b html -d build/doctrees -j12 source build/html

-W turns warnings into errors. Remove -W and it will build.

jpmckinney avatar Dec 08 '22 15:12 jpmckinney

Codecov Report

Base: 90.01% // Head: 89.97% // Decreases project coverage by -0.03% :warning:

Coverage data is based on head (e670b73) compared to base (42077cf). Patch coverage: 91.66% of modified lines in pull request are covered.

:exclamation: Current head e670b73 differs from pull request most recent head cd3c3cb. Consider uploading reports for the commit cd3c3cb to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #105      +/-   ##
==========================================
- Coverage   90.01%   89.97%   -0.04%     
==========================================
  Files          11       10       -1     
  Lines         941      938       -3     
==========================================
- Hits          847      844       -3     
  Misses         94       94              
Flag Coverage Δ
pytests 89.97% <91.66%> (-0.04%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
sphinx_design/_compat.py 90.00% <83.33%> (-10.00%) :arrow_down:
sphinx_design/extension.py 90.56% <100.00%> (-0.09%) :arrow_down:
sphinx_design/icons.py 79.64% <100.00%> (ø)
sphinx_design/__init__.py

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov-commenter avatar Dec 11 '22 03:12 codecov-commenter

Thanks for the review and the clarifying comment @jpmckinney! I have made the changes you suggested. It would be great if someone with write access could approve and merge this!

tirthasheshpatel avatar Dec 11 '22 03:12 tirthasheshpatel

Congrats on your first merged pull request in this project! :tada: congrats
Thank you for contributing, we are very proud of you! :heart:

welcome[bot] avatar Apr 06 '23 15:04 welcome[bot]