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

Upgrade python to 3.11 #8434

Merged
merged 8 commits into from
Jan 22, 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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.11'
- name: Cache the .tox dir
uses: actions/cache@v3
with:
Expand All @@ -47,7 +47,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.11'
- name: Cache the .tox dir
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.11'
- name: Cache the .tox dir
uses: actions/cache@v3
with:
Expand All @@ -109,7 +109,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.11'
- name: Cache the .tox dir
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.11'
- name: Cache the .tox dir
uses: actions/cache@v3
with:
Expand Down
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ COPY h/static ./h/static
RUN yarn build

# Stage 2: Build the rest of the app using the build output from Stage 1.
FROM python:3.8.12-alpine3.13
FROM python:3.11.7-alpine3.19
LABEL maintainer="Hypothes.is Project and contributors"

# Install system build and runtime dependencies.
Expand Down
2 changes: 1 addition & 1 deletion h/accounts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import colander
import deform
from jinja2 import Markup
from markupsafe import Markup
Copy link
Member Author

Choose a reason for hiding this comment

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

Upgrading jinja requires some changes of imports.


from h import i18n, models
from h.models.user import (
Expand Down
4 changes: 2 additions & 2 deletions h/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
form templates in preference to the defaults.
"""
import deform
import jinja2
import pyramid_jinja2
from markupsafe import Markup
from pyramid import httpexceptions
from pyramid.path import AssetResolver

Expand Down Expand Up @@ -45,7 +45,7 @@ def __call__(self, template_name, **kwargs):
context = self._system.copy()
context.update(kwargs)

return jinja2.Markup(template.render(context))
return Markup(template.render(context))


def create_environment(base):
Expand Down
16 changes: 8 additions & 8 deletions h/presenters/annotation_html.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import jinja2
from dateutil import parser
from markupsafe import Markup, escape

from h.presenters.document_html import DocumentHTMLPresenter

Expand All @@ -16,7 +16,7 @@ def __init__(self, annotation):

@property
def uri(self):
return jinja2.escape(self.annotation.target_uri)
return escape(self.annotation.target_uri)

@property
def text_rendered(self):
Expand All @@ -28,15 +28,15 @@ def text_rendered(self):
care of all necessary escaping.
"""
if self.annotation.text_rendered:
return jinja2.Markup(self.annotation.text_rendered)
return jinja2.Markup("")
return Markup(self.annotation.text_rendered)
return Markup("")

@property
def quote(self):
"""Get the text in the document which this annotation refers to."""
selection = self._get_selection()
if selection:
return jinja2.escape(selection)
return escape(selection)

return ""

Expand All @@ -55,12 +55,12 @@ def description(self):

selection = self._get_selection()
if selection:
selection = jinja2.escape(selection)
selection = escape(selection)
description += f"<blockquote>{selection}</blockquote>"

text = self.annotation.text
if text:
text = jinja2.escape(text)
text = escape(text)
description += f"{text}"

return description
Expand All @@ -74,7 +74,7 @@ def created_day_string(self):
date.

"""
created_string = jinja2.escape(self.annotation.created)
created_string = escape(self.annotation.created)
return parser.parse(created_string).strftime("%Y-%m-%d")

@property
Expand Down
32 changes: 16 additions & 16 deletions h/presenters/document_html.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from urllib.parse import unquote, urlparse

import jinja2
import markupsafe


class DocumentHTMLPresenter:
Expand All @@ -24,7 +24,7 @@ def filename(self):

"""
if self.uri.lower().startswith("file:///"):
return jinja2.escape(self.uri.split("/")[-1])
return markupsafe.escape(self.uri.split("/")[-1])
return ""

@property
Expand All @@ -44,7 +44,7 @@ def href(self):

"""
if self.document.web_uri:
return jinja2.escape(self.document.web_uri)
return markupsafe.escape(self.document.web_uri)
return ""

@property
Expand All @@ -64,14 +64,14 @@ def hostname_or_filename(self):
object so that it doesn't get double-escaped.
"""
if self.filename:
return jinja2.escape(unquote(self.filename))
return markupsafe.escape(unquote(self.filename))

hostname = urlparse(self.uri).hostname

# urlparse()'s .hostname is sometimes None.
hostname = hostname or ""

return jinja2.escape(hostname)
return markupsafe.escape(hostname)

@property
def link(self):
Expand Down Expand Up @@ -129,7 +129,7 @@ def link_text(self):
Markup object so it doesn't get double-escaped.

"""
title = jinja2.escape(self.title)
title = markupsafe.escape(self.title)

# Sometimes self.title is the annotated document's URI (if the document
# has no title). In those cases we want to remove the http(s):// from
Expand Down Expand Up @@ -160,17 +160,17 @@ def title(self):
# Convert non-string titles into strings.
# We're assuming that title cannot be a byte string.
title = str(title)
return jinja2.escape(title)
return markupsafe.escape(title)

if self.filename:
return jinja2.escape(unquote(self.filename))
return markupsafe.escape(unquote(self.filename))

return jinja2.escape(unquote(self.uri))
return markupsafe.escape(unquote(self.uri))

@property
def uri(self):
if self.document.document_uris:
return jinja2.escape(self.document.document_uris[0].uri)
return markupsafe.escape(self.document.document_uris[0].uri)
return ""

@property
Expand Down Expand Up @@ -205,7 +205,7 @@ def truncate(content, length=55):
if len(content) <= length:
return content

return content[:length] + jinja2.Markup("&hellip;")
return content[:length] + markupsafe.Markup("&hellip;")

host_or_filename = truncate(host_or_filename)
link_text = truncate(link_text)
Expand All @@ -220,10 +220,10 @@ def truncate(content, length=55):
link += "<br>{host_or_filename}"

link = link.format(
href=jinja2.escape(href),
title=jinja2.escape(title),
link_text=jinja2.escape(link_text),
host_or_filename=jinja2.escape(host_or_filename),
href=markupsafe.escape(href),
title=markupsafe.escape(title),
link_text=markupsafe.escape(link_text),
host_or_filename=markupsafe.escape(host_or_filename),
)

return jinja2.Markup(link)
return markupsafe.Markup(link)
14 changes: 6 additions & 8 deletions h/views/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import colander
import deform
import jinja2
from markupsafe import Markup
from pyramid import httpexceptions, security
from pyramid.exceptions import BadCSRFToken
from pyramid.view import view_config, view_defaults
Expand Down Expand Up @@ -285,7 +285,7 @@ def _reset_password(self, user, password):
svc.update_password(user, password)

self.request.session.flash(
jinja2.Markup(
Markup(
_(
"Your password has been reset. You can now log in with "
"your new password."
Expand Down Expand Up @@ -321,7 +321,7 @@ def get_when_not_logged_in(self):
activation = models.Activation.get_by_code(self.request.db, code)
if activation is None:
self.request.session.flash(
jinja2.Markup(
Markup(
_(
"We didn't recognize that activation link. "
"Have you already activated your account? "
Expand All @@ -340,7 +340,7 @@ def get_when_not_logged_in(self):
user.activate()

self.request.session.flash(
jinja2.Markup(
Markup(
_(
"Your account has been activated! "
"You can now log in using the password you provided."
Expand Down Expand Up @@ -369,14 +369,12 @@ def get_when_logged_in(self):
# The user is already logged in to the account (so the account
# must already be activated).
self.request.session.flash(
jinja2.Markup(
_("Your account has been activated and you're logged in.")
),
Markup(_("Your account has been activated and you're logged in.")),
"success",
)
else:
self.request.session.flash(
jinja2.Markup(
Markup(
_(
"You're already logged in to a different account. "
'<a href="{url}">Log out</a> and open the activation link '
Expand Down
2 changes: 1 addition & 1 deletion h/views/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from urllib.parse import urlparse

from jinja2 import Markup
from markupsafe import Markup
from pyramid import httpexceptions
from pyramid.view import view_config, view_defaults

Expand Down
2 changes: 1 addition & 1 deletion h/views/admin/groups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jinja2 import Markup
from markupsafe import Markup
from pyramid.httpexceptions import HTTPFound
from pyramid.view import view_config, view_defaults

Expand Down
2 changes: 1 addition & 1 deletion h/views/admin/organizations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jinja2 import Markup
from markupsafe import Markup
from pyramid.httpexceptions import HTTPFound
from pyramid.view import view_config, view_defaults
from sqlalchemy import func
Expand Down
6 changes: 3 additions & 3 deletions h/views/admin/users.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jinja2
from markupsafe import Markup
from pyramid import httpexceptions
from pyramid.view import view_config

Expand Down Expand Up @@ -70,7 +70,7 @@ def users_activate(request):

request.session.flash(
# pylint:disable=consider-using-f-string
jinja2.Markup(_("User {name} has been activated!".format(name=user.username))),
Markup(_("User {name} has been activated!".format(name=user.username))),
"success",
)

Expand Down Expand Up @@ -145,7 +145,7 @@ def users_delete(request):

@view_config(context=UserNotFoundError)
def user_not_found(exc, request): # pragma: no cover
request.session.flash(jinja2.Markup(_(exc.message)), "error")
request.session.flash(Markup(_(exc.message)), "error")
return httpexceptions.HTTPFound(location=request.route_path("admin.users"))


Expand Down
Loading