Skip to content

Commit

Permalink
Merge pull request #2300 from liberapay/python-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco authored Dec 4, 2023
2 parents f978adf + b56a767 commit 32294eb
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 136 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: Install Python 3.9
- name: Install Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.11'
- name: Cache the .tox directory to speed things up
uses: actions/cache@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions cli/check-python-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
print("Liberapay requires Python >= 3.8, but %s is version %s.%s" %
(sys.executable, sys.version_info[0], sys.version_info[1]))
sys.exit(1)
if sys.version_info >= (3, 10, 0):
print("Warning: Liberapay hasn't been tested with Python >= 3.10, you might encounter bugs.")
if sys.version_info >= (3, 13, 0):
print("Warning: Liberapay hasn't been tested with Python >= 3.13, you might encounter bugs.")
4 changes: 2 additions & 2 deletions liberapay/elsewhere/_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from datetime import datetime
from datetime import datetime, timezone
import hashlib
import json
import logging
Expand Down Expand Up @@ -218,7 +218,7 @@ def log_ratelimit_headers(self, domain, limit, remaining, reset):
return
percent_remaining = remaining/limit
if percent_remaining < 0.5:
reset_delta = reset - datetime.utcnow().replace(tzinfo=utc)
reset_delta = reset - datetime.now(timezone.utc)
reset_delta = format_timedelta(reset_delta, add_direction=True, locale='en')
log_lvl = logging.WARNING
if percent_remaining < 0.2:
Expand Down
8 changes: 0 additions & 8 deletions liberapay/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,6 @@ def check_payin_allowed(website, request, user, method=None):
Website.check_payin_allowed = check_payin_allowed


# Monkey patch python's stdlib
# ============================

from http.cookies import Morsel

Morsel._reserved['samesite'] = 'SameSite'


# Monkey patch aspen and pando
# ============================

Expand Down
368 changes: 260 additions & 108 deletions requirements_base.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/py/test_state_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_i18n_subdomains_work(self):
html = r.html_tree
assert html.attrib["lang"] == "zh-hant-tw"
statement_section = html.find(".//{*}section[@lang='zh']")
assert statement_section, r.text
assert len(statement_section) > 0, r.text
assert statement_section[0].text == "歡迎,"
r = self.client.GET(
'/alice',
Expand All @@ -91,7 +91,7 @@ def test_i18n_subdomains_work(self):
html = r.html_tree
assert html.attrib["lang"] == "zh-hans"
statement_section = html.find(".//{*}section[@lang='zh-hans']")
assert statement_section, r.text
assert len(statement_section) > 0, r.text
assert statement_section[0].text == "欢迎,"

def test_i18n_subdomain_is_redirected_to_https(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/py/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal

from markupsafe import escape
Expand Down Expand Up @@ -92,11 +92,11 @@ def test_get_participant_redirects_after_username_change(self):
# ===============

def test_is_expired(self):
expiration = datetime.utcnow() - timedelta(days=40)
expiration = datetime.now(timezone.utc) - timedelta(days=40)
assert utils.is_card_expired(expiration.year, expiration.month)

def test_not_expired(self):
expiration = datetime.utcnow() + timedelta(days=100)
expiration = datetime.now(timezone.utc) + timedelta(days=100)
assert not utils.is_card_expired(expiration.year, expiration.month)

# Markdown
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py38,py39
envlist = py38,py311
skipsdist = True

[testenv]
Expand Down
4 changes: 2 additions & 2 deletions www/%username/ledger/index.spt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from liberapay.utils import get_participant
from liberapay.utils.history import get_payin_ledger
Expand Down Expand Up @@ -32,7 +32,7 @@ translated_status = {
'suspended': _('suspended'),
}

current_year = datetime.utcnow().year
current_year = datetime.now(timezone.utc).year
year = request.qs.get_int('year', 0, minimum=2018, maximum=current_year)
if not year:
# Try to detect the year of the last transaction
Expand Down
4 changes: 2 additions & 2 deletions www/%username/wallet/export.spt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from liberapay.utils import get_participant
from liberapay.utils.history import export_history
Expand All @@ -9,7 +9,7 @@ participant = get_participant(state, restrict=True)
title = participant.username
subhead = _("Export History")

current_year = datetime.utcnow().year
current_year = datetime.now(timezone.utc).year
year = request.qs.get_int('year', current_year)

key = request.qs.get('key')
Expand Down
4 changes: 2 additions & 2 deletions www/%username/wallet/index.html.spt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from liberapay.utils import get_participant
from liberapay.utils.history import get_wallet_ledger
Expand All @@ -25,7 +25,7 @@ translated_status = {
'succeeded': _('succeeded')
}

current_year = datetime.utcnow().year
current_year = datetime.now(timezone.utc).year
year = request.qs.get_int('year', 0, minimum=2016, maximum=current_year)
if not year:
# Try to detect the year of the last transaction
Expand Down
4 changes: 2 additions & 2 deletions www/%username/wallet/statement.spt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from liberapay.utils import check_address_v2, get_participant, render, render_postal_address
from liberapay.utils.history import get_wallet_ledger
Expand All @@ -13,7 +13,7 @@ STATUS_MAP = {
participant = get_participant(state, restrict=True)
title = _("Account Statement")

now = datetime.utcnow()
now = datetime.now(timezone.utc)
today = now.date()
year = request.qs.get_int('year', now.year, minimum=2016)
month = request.qs.get_int('month', None, minimum=1, maximum=12)
Expand Down

0 comments on commit 32294eb

Please sign in to comment.