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

Update to Python 3.11 #662

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.12
3.11.7
Copy link
Member

Choose a reason for hiding this comment

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

Not that important but this is a minor version lower than the version in Dockerfile

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied this from h. Dependabot updates the Dockerfile but it doesn't know about .python-version, so we'll have this minor skew across our projects.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we've ever seen problems due to Python minor version differences between what we use in dev and what the Docker container uses, but perhaps this could be bumped periodically by the cookiecutter or something? CC @seanh .

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8.12-alpine3.13
FROM python:3.11.8-alpine3.19
LABEL maintainer="Hypothes.is Project and contributors"

# Install nginx & supervisor
Expand Down
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ filterwarnings =
ignore:^pkg_resources is deprecated as an API:DeprecationWarning:gevent
ignore:^pkg_resources is deprecated as an API:DeprecationWarning:pywb

# https://github.com/webpy/webpy/issues/732
ignore:^'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning:webob
ignore:^'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning:pywb

# importlib warning triggered by py3amf
ignore:ModuleFinder\.find_spec\(\) not found; falling back to find_module\(\):ImportWarning:importlib

xfail_strict=true

[tox]
Expand Down
37 changes: 0 additions & 37 deletions viahtml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
"""Setup environment before loading app."""

import ctypes.util
import sys
from ctypes import CDLL


def patch_ctypes_on_macos_11(): # pragma: no cover
"""Work around a problem loading pywb under macOS 11.

pywb has a dependency on an old version of fakeredis which fails to load
when using Python <= 3.8 under macOS 11. This function patches `ctypes.util.find_library`
to work around the issue.

See https://github.com/hypothesis/viahtml/issues/55.
"""

if sys.platform != "darwin":
return

def _find_library_patched(name):
path = f"lib{name}.dylib"
try:
# In macOS 11, some system libraries don't exist on disk. Instead you test
# the validity of a library path by trying to load it.
# See https://bugs.python.org/issue41179.
CDLL(path)
except OSError:
# Fall back to the un-patched version.
path = ctypes.util.find_library(name)
return path

ctypes.util.find_library = _find_library_patched


# Apply ctypes patch before pywb is imported.
patch_ctypes_on_macos_11()
2 changes: 1 addition & 1 deletion viahtml/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _patch_url_rewriter(hooks: Hooks):
UrlRewriter.NO_REWRITE_URI_PREFIX = tuple(prefixes)


class _PatchedHTMLRewriter(HTMLRewriter): # pylint: disable=abstract-method
class _PatchedHTMLRewriter(HTMLRewriter):
hooks: Optional[Hooks] = None

@classmethod
Expand Down
Loading