Skip to content

Commit

Permalink
Merge pull request #2349 from liberapay/various
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco authored Apr 30, 2024
2 parents 79fde1d + b199115 commit d1e6755
Show file tree
Hide file tree
Showing 17 changed files with 414 additions and 202 deletions.
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,25 @@ test-shell: $(env)
test-schema: $(env)
$(with_tests_env) ./recreate-schema.sh test

pyflakes: $(env)
$(env_py) -m flake8 app.py liberapay tests
lint: $(env)
$(env_py) -m ruff check app.py liberapay tests

test: test-schema pytest
tests: test

pytest: $(env)
$(py_test) ./tests/py/test_$${PYTEST-*}.py
@$(MAKE) --no-print-directory pyflakes
@$(MAKE) --no-print-directory lint
$(py_test) --doctest-modules liberapay

pytest-cov: $(env)
$(py_test) --cov-report html --cov liberapay ./tests/py/test_$${PYTEST-*}.py
@$(MAKE) --no-print-directory pyflakes
@$(MAKE) --no-print-directory lint
$(py_test) --doctest-modules liberapay

pytest-re: $(env)
$(py_test) --lf ./tests/py/
@$(MAKE) --no-print-directory pyflakes
@$(MAKE) --no-print-directory lint

pytest-i18n-browse: $(env)
@if [ -f sql/branch.sql ]; then $(MAKE) --no-print-directory test-schema; fi
Expand Down
11 changes: 11 additions & 0 deletions liberapay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ def generate_value(self, currency):

LAUNCH_TIME = datetime(2016, 2, 3, 12, 50, 0, 0, utc)

MARK_CLASSES = {
'trusted': 'text-success',
'okay': 'text-info',
'unsettling': 'text-info',
'controversial': 'text-warning',
'irrelevant': 'text-warning',
'misleading': 'text-warning',
'spam': 'text-danger',
'fraud': 'text-danger',
}

PARTICIPANT_KINDS = {
'individual': _("Individual"),
'organization': _("Organization"),
Expand Down
22 changes: 13 additions & 9 deletions liberapay/i18n/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def __init__(self, *a, **kw):
super().__init__(*a, **kw)
self.currency_formats['amount_only'] = MONEY_AMOUNT_FORMAT
delta_p = self.currency_formats['standard'].pattern
minus_sign = self.number_symbols.get('minusSign', '-')
plus_sign = self.number_symbols.get('plusSign', '+')
minus_sign = self.number_symbols[self.default_numbering_system].get('minusSign', '-')
plus_sign = self.number_symbols[self.default_numbering_system].get('plusSign', '+')
if ';' in delta_p:
pos, neg = delta_p.split(';')
assert len(neg) >= len(pos), (self, neg, pos)
Expand Down Expand Up @@ -235,10 +235,10 @@ def format(self, s, *a, **kw):
def format_money(self, m, format='standard', trailing_zeroes=True):
s = self.currency_formats[format].apply(
m.amount, self, currency=m.currency, currency_digits=True,
decimal_quantization=True
decimal_quantization=True, numbering_system='default',
)
if trailing_zeroes is False:
i = s.find(self.number_symbols['decimal'])
i = s.find(self.number_symbols[self.default_numbering_system]['decimal'])
if i != -1 and set(s[i+1:]) == ONLY_ZERO:
s = s[:i]
return s
Expand All @@ -252,6 +252,7 @@ def format_datetime(self, *a):
return format_datetime(*a, locale=self)

def format_decimal(self, number, **kw):
kw.setdefault('numbering_system', 'default')
return self.decimal_formats[None].apply(number, self, **kw)

def format_list(self, l, pattern='standard', escape=_return_):
Expand All @@ -274,7 +275,10 @@ def format_money_basket(self, basket, sep=','):
return '0'
pattern = self.currency_formats['standard']
items = (
pattern.apply(money.amount, self, currency=money.currency)
pattern.apply(
money.amount, self, currency=money.currency,
numbering_system='default',
)
for money in basket if money
)
if sep == ',':
Expand All @@ -286,7 +290,7 @@ def format_money_basket(self, basket, sep=','):
def format_money_delta(self, money):
return self.currency_delta_pattern.apply(
money.amount, self, currency=money.currency, currency_digits=True,
decimal_quantization=True
decimal_quantization=True, numbering_system='default',
)

def format_percent(self, number, min_precision=1, group_separator=True):
Expand All @@ -297,7 +301,7 @@ def format_percent(self, number, min_precision=1, group_separator=True):
return self.percent_formats[None].apply(
number, self,
decimal_quantization=decimal_quantization,
group_separator=True,
group_separator=True, numbering_system='default',
)

def format_time(self, t, format='medium'):
Expand All @@ -309,8 +313,8 @@ def format_timedelta(self, o, **kw):
return format_timedelta(o, locale=self, **kw)

def parse_money_amount(self, string, currency, maximum=D_MAX):
group_symbol = self.number_symbols['group']
decimal_symbol = self.number_symbols['decimal']
group_symbol = self.number_symbols[self.default_numbering_system]['group']
decimal_symbol = self.number_symbols[self.default_numbering_system]['decimal']
# Strip the string of spaces, and of the specified currency's symbol in
# this locale (if that symbol exists).
string = string.strip()
Expand Down
5 changes: 3 additions & 2 deletions liberapay/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@
website.default_renderers_by_media_type['text/html'] = 'jinja2'
website.default_renderers_by_media_type['text/plain'] = 'jinja2'

def _assert(x):
assert x, repr(x)
def _assert(x, msg=None):
if not x:
raise AssertionError(msg or repr(x))
return x

def soft_assert(x, msg):
Expand Down
2 changes: 1 addition & 1 deletion liberapay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2863,7 +2863,7 @@ def find_partial_match(new_sp, current_schedule_map):
for naive_group in naive_groups:
naive_group.sort(key=due_date_getter)
group = None
execution_date = weeks_until_execution = None # for flake8
execution_date = weeks_until_execution = None # for the linter
for tip in naive_group:
last_payment_amount = last_payment_amounts.get(tip.tippee)
# Start a new group if…
Expand Down
2 changes: 1 addition & 1 deletion liberapay/testing/elsewhere.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flake8: noqa
# ruff: noqa

"""
Examples of data returned by the APIs of the elsewhere platforms.
Expand Down
2 changes: 1 addition & 1 deletion liberapay/utils/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def iter_payday_events(db, participant, period_start, period_end, today, minimiz
prev_date = None
get_timestamp = lambda e: e['timestamp']
events = sorted(exchanges+transfers, key=get_timestamp, reverse=True)
day_events, day_open = None, None # for pyflakes
day_events, day_open = None, None # for the linter
for event in events:

collapse = False
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.ruff]
# https://docs.astral.sh/ruff/configuration/
line-length = 120
output-format = "full"

[tool.ruff.lint]
ignore = [
"E226", "E301", "E302", "E303", "E305", "E306", "E402",
"E701", "E711", "E712", "E721", "E731", "E741",
]
Loading

0 comments on commit d1e6755

Please sign in to comment.