Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINT] Add support for Python 3.11 #105

Merged
merged 12 commits into from Apr 6, 2023

Conversation

tirthasheshpatel
Copy link
Contributor

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?

@welcome
Copy link

welcome bot commented Oct 28, 2022

Thanks for submitting your first pull request! You are awesome! 🤗

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! 🎉

@tirthasheshpatel
Copy link
Contributor Author

tirthasheshpatel commented Oct 28, 2022

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
Copy link
Contributor Author

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

@tirthasheshpatel tirthasheshpatel changed the title Add support for Python 3.11 [MAINT] Add support for Python 3.11 Oct 29, 2022
sphinx_design/_compat.py Outdated Show resolved Hide resolved
@jpmckinney
Copy link
Contributor

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.

Co-authored-by: James McKinney <26463+jpmckinney@users.noreply.github.com>
@codecov-commenter
Copy link

Codecov Report

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

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

❗ 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%) ⬇️

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%) ⬇️
sphinx_design/extension.py 90.56% <100.00%> (-0.09%) ⬇️
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.

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

@tirthasheshpatel
Copy link
Contributor Author

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!

Copy link
Member

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the extra 3.8 support, I added a comment to note when we can deprecate the extra check. I think the failing test is just because of codecov being broken!

@choldgraf choldgraf merged commit 3d0db63 into executablebooks:main Apr 6, 2023
13 of 15 checks passed
@welcome
Copy link

welcome bot commented Apr 6, 2023

Congrats on your first merged pull request in this project! 🎉
congrats

Thank you for contributing, we are very proud of you! ❤️

@tirthasheshpatel tirthasheshpatel deleted the support-py311 branch April 12, 2023 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants