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 to python 3.12 #477

Merged
merged 10 commits into from
Nov 9, 2023
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
1 change: 1 addition & 0 deletions .flaskenv
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
FLASK_APP=sipa:create_app
FLASK_TEMPLATES_AUTO_RELOAD=true
4 changes: 2 additions & 2 deletions .github/workflows/sipa-ci .yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: "3.12"
- uses: pre-commit/[email protected]
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: '3.12'
cache: 'pip'
- name: print information about pip cache
run: pip cache info && pip cache list
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# see https://github.com/topics/pre-commit-hook for more
repos:
- repo: https://github.com/akaihola/darker
rev: 1.6.1
rev: 1.7.2
hooks:
- id: darker
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py310-plus"]
args: ["--py312-plus"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.241'
rev: 'v0.1.3'
hooks:
- id: ruff
7 changes: 3 additions & 4 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11
FROM python:3.12
MAINTAINER Lukas Juhrich der Große <[email protected]>


Expand All @@ -24,12 +24,11 @@ RUN addgroup --gid 9999 sipa && \
RUN mkdir /home/sipa/sipa
WORKDIR /home/sipa/sipa

ADD ./build /home/sipa/sipa/build/
COPY ./build /home/sipa/sipa/build/
ARG additional_requirements
RUN ./build/install_requirements.py $additional_requirements

ADD . /home/sipa/sipa
RUN chown -R sipa:sipa /home/sipa/sipa
COPY --chown=sipa:sipa . /home/sipa/sipa

EXPOSE 5000

Expand Down
12 changes: 6 additions & 6 deletions build/requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
flask~=2.2.2
flask~=3.0.0
flask-babel~=4.0.0
Flask-Login~=0.6.1
Babel~=2.10.3
Flask-Babel~=2.0.0
flask-wtf~=1.2.1
babel~=2.13.1
SQLAlchemy~=1.4.40
Markdown~=3.4.1
requests~=2.28.1
Flask-FlatPages~=0.8.1
pygal~=3.0.0
GitPython~=3.1.27
Flask-WTF~=1.0.1
PyMySQL~=1.0.2
blinker~=1.5
factory-boy~=3.2.1
psycopg2~=2.9.3
Flask-QRcode~=3.1.0
email_validator~=1.2.1
Werkzeug~=2.2.2
sentry-sdk[flask]~=1.9.5
Werkzeug~=3.0.1
sentry-sdk[flask]~=1.34.0
# Pin to avoid incompatibility
jinja2~=3.1.2
MarkupSafe~=2.1.1
Expand Down
4 changes: 2 additions & 2 deletions build/requirements/requirements_testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ profilehooks~=1.9.0
pycodestyle~=2.4.0
mypy~=0.960
sphinx~=1.8.4
pytest~=7.1.2
pytest-freezegun~=0.4.2
pytest~=7.4.3
time_machine~=2.13.0
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[tool.ruff]
line-length = 100
target-version = "py311"
target-version = "py312"
exclude = [
]
# to look up the meaning of specific rule IDs, use `ruff rule $id`
select = [
"E",
"F",
"B", # flake8-bugbear
"UP", # pyupgrade
]
ignore = [
"E741", # ambiguous variable names
Expand Down
10 changes: 4 additions & 6 deletions sipa/babel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ def get_user_locale_setting() -> Locale | None:
try:
locale = Locale.parse(locale_identifier)
except (UnknownLocaleError, ValueError):
logger.warning("Illegal locale {!r} stored in user session."
.format(locale_identifier))
session.pop('locale')
logger.warning(f"Illegal locale {locale_identifier!r} stored in user session.")
session.pop("locale")
return None

if locale not in possible_locales():
logger.warning("Unavailable locale {} stored in user session."
.format(locale))
session.pop('locale', None)
logger.warning(f"Unavailable locale {locale} stored in user session.")
session.pop("locale", None)
return None

return locale
Expand Down
5 changes: 1 addition & 4 deletions sipa/backends/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ def __eq__(self, other):
return compare_all_attributes(self, other, ['name'])

def __repr__(self):
return "<{cls} {name!r}>".format(
cls=type(self).__name__,
name=self.name,
)
return f"<{type(self).__name__} {self.name!r}>"

def __hash__(self):
return xor_hashes(self.name, self.user_class, self.support_mail, self.mail_server)
Expand Down
12 changes: 7 additions & 5 deletions sipa/flatpages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from babel.core import Locale, UnknownLocaleError, negotiate_locale
from flask import abort, request
from flask_babel import get_babel
from flask_flatpages import FlatPages, Page
from yaml.scanner import ScannerError

Expand Down Expand Up @@ -149,8 +150,8 @@ def __getattr__(self, attr: str) -> str:
return self.localized_page.meta[attr]
except KeyError as e:
raise AttributeError(
"{!r} object has no attribute {!r}"
.format(type(self).__name__, attr)) from e
f"{type(self).__name__!r} object has no attribute {attr!r}"
) from e

@cached_property
def available_locales(self) -> tuple[str]:
Expand Down Expand Up @@ -231,8 +232,8 @@ def __getattr__(self, attr):
index = self._articles['index']
except KeyError as e:
raise AttributeError(
"{!r} object has no attribute {!r}"
.format(type(self).__name__, attr)) from e
f"{type(self).__name__!r} object has no attribute {attr!r}"
) from e
return getattr(index, attr)

def add_child_category(self, id):
Expand Down Expand Up @@ -323,10 +324,11 @@ def init_app(self, app):
self.app = app
app.cf_pages = self
self.flat_pages.init_app(app)
babel = get_babel(app)
self.root_category = Category(
parent=None,
id="<root>",
default_locale=app.babel_instance.default_locale,
default_locale=babel.default_locale,
)
self._init_categories()

Expand Down
7 changes: 3 additions & 4 deletions sipa/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging.config
import os
import os.path
from datetime import datetime
from datetime import datetime, UTC

import sentry_sdk
from flask import g
Expand Down Expand Up @@ -54,8 +54,7 @@ def init_app(app, **kwargs):
logger.debug('Initializing app')
login_manager.init_app(app, add_context_processor=False)
babel = Babel()
babel.init_app(app)
babel.localeselector(select_locale)
babel.init_app(app, locale_selector=select_locale)
app.before_request(setup_request_locale_context)
app.after_request(ensure_csp)
app.session_interface = SeparateLocaleCookieSessionInterface()
Expand Down Expand Up @@ -97,7 +96,7 @@ def init_app(app, **kwargs):
form_input_width_class=f"col-sm-{form_input_width}",
form_input_offset_class=f"offset-sm-{form_label_width}",
url_self=url_self,
now=datetime.utcnow()
now=datetime.now(UTC),
)
app.add_template_filter(render_links)

Expand Down
6 changes: 1 addition & 5 deletions sipa/model/pycroft/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,7 @@ def payment_details(self) -> PaymentDetails:
bank="Ostsächsische Sparkasse Dresden",
iban="DE61 8505 0300 3120 2195 40",
bic="OSDD DE 81 XXX",
purpose="{id}, {name}, {address}".format(
id=self.user_data.user_id,
name=self.user_data.name,
address=self.user_data.room,
),
purpose=f"{self.user_data.user_id}, {self.user_data.name}, {self.user_data.room}",
)

def has_property(self, property: str) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions sipa/model/pycroft/userdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def change_password(self, password):
self.sql_query(
"GRANT SELECT, INSERT, UPDATE, DELETE, "
"ALTER, CREATE, DROP, INDEX, LOCK TABLES "
"ON `{}`.* "
"TO %s@%s".format(self.db_name()),
f"ON `{self.db_name()}`.* "
"TO %s@%s",
(self.db_name(), self.ip_mask),
)

Expand Down
5 changes: 1 addition & 4 deletions sipa/utils/link_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def absolute_path_replacer(match):
if prefix.endswith("/"):
prefix = prefix[:-1]

return "{key}=\"{path}\"".format(
key=match.group(1),
path=prefix + match.group(2)
)
return f'{match.group(1)}="{prefix + match.group(2)}"'


class LinkPostprocessor(Postprocessor):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def calendar(ical_data: str) -> icalendar.Calendar:
return icalendar.Calendar.from_ical(ical_data)


def test_ical_conversion(calendar: icalendar.Calendar, freezer):
freezer.move_to("2023-05-20")
def test_ical_conversion(calendar: icalendar.Calendar, time_machine):
time_machine.move_to("2023-05-20")
events = events_from_calendar(calendar)
assert len(events) == 1
[ev] = events
Expand Down
5 changes: 2 additions & 3 deletions tests/test_static_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ def app(static_file, documents_dir):


def test_static_view(app: Flask):
with app.test_client() as c:
resp = c.get("/documents/test.txt")
assert resp.text == "Test!"
with app.test_client() as c, c.get("/documents/test.txt") as resp:
assert resp.text == "Test!"