Skip to content

Commit

Permalink
chore: ruff update
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed May 7, 2024
1 parent d68f3cf commit 7af179c
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 62 deletions.
2 changes: 1 addition & 1 deletion downloads/management/commands/add_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def handle(self, *args, **options):
dlpath = dlpath[:-1]

for f in options["file"]:
self.stdout.write("Adding %s..." % f)
self.stdout.write(f"Adding {f}...")
filename = os.path.basename(f)

with open(f, "rb") as handle:
Expand Down
5 changes: 1 addition & 4 deletions downloads/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ def save(self, *args, **kwargs):
programurl=f"https://{current_site}{PROGRAM_URLS[self.program]}",
versionurl=f"https://{current_site}{self.get_absolute_url()}",
)
body = (
"Full list of changes:\n\n%s\n\nYou can download it from <https://wammu.eu/download/>.\n\nSupport this program by donations <https://wammu.eu/donate/>."
% self.changelog
)
body = f"Full list of changes:\n\n{self.changelog}\n\nYou can download it from <https://wammu.eu/download/>.\n\nSupport this program by donations <https://wammu.eu/donate/>."
title = f"{get_program(self.program)} {self.version}"
slug = "{}-{}".format(
self.program,
Expand Down
16 changes: 10 additions & 6 deletions downloads/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

def detail(request, program):
if program not in (x[0] for x in PROGRAM_CHOICES):
raise Http404("No such program %s." % program)
msg = f"No such program {program}."
raise Http404(msg)

downloads = get_current_downloads(program)

Expand All @@ -23,7 +24,8 @@ def detail(request, program):
testing_release, testing_downloads = (None, None)

if stable_downloads.count() == 0:
raise Http404("No such download option %s." % program)
msg = f"No such download option {program}."
raise Http404(msg)

return render(
request,
Expand Down Expand Up @@ -64,13 +66,14 @@ def download(request):

def doap(request, program):
if program not in (x[0] for x in PROGRAM_CHOICES):
raise Http404("No such program %s." % program)
msg = f"No such program {program}."
raise Http404(msg)

downloads = get_current_downloads(program)

return render(
request,
"downloads/doap/%s.xml" % program,
f"downloads/doap/{program}.xml",
{
"downloads": downloads[0][1],
"release": downloads[0][0],
Expand All @@ -81,7 +84,8 @@ def doap(request, program):

def pad(request, program):
if program not in (x[0] for x in PROGRAM_CHOICES):
raise Http404("No such program %s." % program)
msg = f"No such program {program}."
raise Http404(msg)

downloads = get_current_downloads(program)

Expand All @@ -96,7 +100,7 @@ def pad(request, program):

return render(
request,
"downloads/pad/%s.xml" % program,
f"downloads/pad/{program}.xml",
{
"download": download,
"release": release,
Expand Down
2 changes: 1 addition & 1 deletion news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def category(request, slug):
.order_by("-pub_date")
.prefetch_related("author")
)
return render_news(request, objects, "news/%s_index.html" % slug)
return render_news(request, objects, f"news/{slug}_index.html")


def render_news(request, objects, template):
Expand Down
2 changes: 1 addition & 1 deletion phonedb/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs):
_('%(description)s [<a href="%(url)s">Link</a>]')
% {
"description": f.get_description(),
"url": "/phones/search/%s/" % f.name,
"url": f"/phones/search/{f.name}/",
},
),
)
Expand Down
5 changes: 2 additions & 3 deletions phonedb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def get_related_sites(self):
name = self.__str__().replace(" ", "_").replace("-", "_")
result.append(
{
"url": "https://wikipedia.org/wiki/%s" % name,
"url": f"https://wikipedia.org/wiki/{name}",
"name": "Wikipedia",
},
)
Expand All @@ -195,8 +195,7 @@ def get_related_sites(self):
name = name[:-1] + "_fold"
result.append(
{
"url": "http://www.developer.nokia.com/Devices/Device_specifications/%s/"
% name,
"url": f"http://www.developer.nokia.com/Devices/Device_specifications/{name}/",
"name": "Nokia Developer",
},
)
Expand Down
8 changes: 4 additions & 4 deletions phonedb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def get_chart_url(force=False):
cache_key = "phonedb-chart-url-%s" % settings.LANGUAGE_CODE
cache_key = f"phonedb-chart-url-{settings.LANGUAGE_CODE}"
url = cache.get(cache_key)
if url is not None and not force:
return url
Expand Down Expand Up @@ -195,12 +195,12 @@ def search(request, featurename=None):
if len(features) > 0:
phones = phones.filter(connection__isnull=False)
for feature in features:
urlparams.append("feature=%s" % feature)
urlparams.append(f"feature={feature}")
phones = phones.filter(features__name=feature)

# Filter for query string
if query:
urlparams.append("q=%s" % query)
urlparams.append(f"q={query}")
query = query.strip()
for part in query.split():
phones = phones.filter(
Expand Down Expand Up @@ -501,7 +501,7 @@ def create_wammu(request): # noqa: C901

features = []
for feature in Feature.objects.all():
key = "fts[%s]" % feature.name
key = f"fts[{feature.name}]"
if key in request.POST and request.POST[key] == "1":
features.append(feature)

Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
profile = "black"

[tool.ruff]
output-format = "github"

[tool.ruff.lint]
extend-safe-fixes = [
"D",
"TCH",
Expand Down Expand Up @@ -44,10 +47,11 @@ ignore = [
"EM101",
"PT",
"PTH",
"ANN"
"ANN",
"COM812",
"ISC001"
]
output-format = "github"
select = ["ALL"]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 16
5 changes: 3 additions & 2 deletions screenshots/thumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ def save(self, name, content, save=True):

thumb_name_ = self.storage.save(thumb_name, thumb_content)

if not thumb_name == thumb_name_:
raise ValueError("There is already a file named %s" % thumb_name)
if thumb_name != thumb_name_:
msg = f"There is already a file named {thumb_name}"
raise ValueError(msg)

def delete(self, save=True):
name = self.name
Expand Down
2 changes: 1 addition & 1 deletion screenshots/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def index(request):
def category(request, slug):
category = get_object_or_404(Category, slug=slug)
objects = Screenshot.objects.filter(categories=category).order_by("title")
return render_screenshots(request, objects, "screenshots/%s_index.html" % slug)
return render_screenshots(request, objects, f"screenshots/{slug}_index.html")


def render_screenshots(request, objects, template):
Expand Down
6 changes: 3 additions & 3 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
("sk", "Slovenčina"),
)

LOCALE_PATHS = ("%s/locale" % WEB_ROOT,)
LOCALE_PATHS = (f"{WEB_ROOT}/locale",)

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
Expand All @@ -59,9 +59,9 @@
# calendars according to the current locale

# Absolute filesystem path to the directory that will hold user-uploaded files.
MEDIA_ROOT = "%s/media/" % WEB_ROOT
MEDIA_ROOT = f"{WEB_ROOT}/media/"

HTML_ROOT = "%s/html/" % WEB_ROOT
HTML_ROOT = f"{WEB_ROOT}/html/"

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
Expand Down
10 changes: 6 additions & 4 deletions tools/templatetags/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def base64(value):
@register.filter
def xpm2png(value):
xpm = """/* XPM */
static char * ala_xpm[] = {
"%s"};""" % '",\n"'.join(
value,
static char * ala_xpm[] = {{
"{}"}};""".format(
'",\n"'.join(
value,
)
)
xpm = xpm.replace("None", "#ffffff").replace("Black", "#000000")
io = StringIO(xpm)
Expand All @@ -41,6 +43,6 @@ def xpm2png(value):
def wrap(value):
ret = ""
while len(value) > 0:
ret += "%s\n" % value[:32]
ret += f"{value[:32]}\n"
value = value[32:]
return ret
42 changes: 21 additions & 21 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,39 @@ class PagesSitemap(Sitemap):

def items(self):
return [
("/", "%s/index.html" % settings.HTML_ROOT, 1),
("/gammu/", "%s/gammu.html" % settings.HTML_ROOT, 1),
("/libgammu/", "%s/libgammu.html" % settings.HTML_ROOT, 1),
("/wammu/", "%s/wammu.html" % settings.HTML_ROOT, 1),
("/smsd/", "%s/smsd.html" % settings.HTML_ROOT, 1),
("/python-gammu/", "%s/python-gammu.html" % settings.HTML_ROOT, 1),
("/authors/", "%s/authors.html" % settings.HTML_ROOT, 0.9),
("/license/", "%s/libgammu.html" % settings.HTML_ROOT, 0.9),
("/donate/", "%s/donate.html" % settings.HTML_ROOT, 0.3),
("/s60/", "%s/s60.html" % settings.HTML_ROOT, 0.3),
("/support/", "%s/support/index.html" % settings.HTML_ROOT, 0.9),
("/support/bugs/", "%s/support/bugs.html" % settings.HTML_ROOT, 0.9),
("/support/lists/", "%s/support/lists.html" % settings.HTML_ROOT, 0.9),
("/support/online/", "%s/support/online.html" % settings.HTML_ROOT, 0.9),
("/support/buy/", "%s/support/buy.html" % settings.HTML_ROOT, 0.9),
("/contribute/", "%s/contribute/index.html" % settings.HTML_ROOT, 0.9),
("/contribute/code/", "%s/contribute/code.html" % settings.HTML_ROOT, 0.9),
("/", f"{settings.HTML_ROOT}/index.html", 1),
("/gammu/", f"{settings.HTML_ROOT}/gammu.html", 1),
("/libgammu/", f"{settings.HTML_ROOT}/libgammu.html", 1),
("/wammu/", f"{settings.HTML_ROOT}/wammu.html", 1),
("/smsd/", f"{settings.HTML_ROOT}/smsd.html", 1),
("/python-gammu/", f"{settings.HTML_ROOT}/python-gammu.html", 1),
("/authors/", f"{settings.HTML_ROOT}/authors.html", 0.9),
("/license/", f"{settings.HTML_ROOT}/libgammu.html", 0.9),
("/donate/", f"{settings.HTML_ROOT}/donate.html", 0.3),
("/s60/", f"{settings.HTML_ROOT}/s60.html", 0.3),
("/support/", f"{settings.HTML_ROOT}/support/index.html", 0.9),
("/support/bugs/", f"{settings.HTML_ROOT}/support/bugs.html", 0.9),
("/support/lists/", f"{settings.HTML_ROOT}/support/lists.html", 0.9),
("/support/online/", f"{settings.HTML_ROOT}/support/online.html", 0.9),
("/support/buy/", f"{settings.HTML_ROOT}/support/buy.html", 0.9),
("/contribute/", f"{settings.HTML_ROOT}/contribute/index.html", 0.9),
("/contribute/code/", f"{settings.HTML_ROOT}/contribute/code.html", 0.9),
(
"/contribute/translate/",
"%s/contribute/translate.html" % settings.HTML_ROOT,
f"{settings.HTML_ROOT}/contribute/translate.html",
0.9,
),
(
"/contribute/publicity/",
"%s/contribute/publicity.html" % settings.HTML_ROOT,
f"{settings.HTML_ROOT}/contribute/publicity.html",
0.9,
),
(
"/contribute/wanted/",
"%s/contribute/wanted.html" % settings.HTML_ROOT,
f"{settings.HTML_ROOT}/contribute/wanted.html",
0.9,
),
("/docs/", "%s/docs/index.html" % settings.HTML_ROOT, 0.9),
("/docs/", f"{settings.HTML_ROOT}/docs/index.html", 0.9),
("/screenshots/", None, 0.8),
("/downloads/gammu/", None, 0.7),
("/downloads/python-gammu/", None, 0.7),
Expand Down
16 changes: 8 additions & 8 deletions wammu/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,43 @@ def translations(request):

if lang != "cs":
langs.append(
{"url": "https://cs.wammu.eu%s" % path, "name": "Česky", "code": "cs"},
{"url": f"https://cs.wammu.eu{path}", "name": "Česky", "code": "cs"},
)

if lang != "en":
langs.append(
{"url": "https://wammu.eu%s" % path, "name": "English", "code": "en"},
{"url": f"https://wammu.eu{path}", "name": "English", "code": "en"},
)

if lang != "es":
langs.append(
{"url": "https://es.wammu.eu%s" % path, "name": "Español", "code": "es"},
{"url": f"https://es.wammu.eu{path}", "name": "Español", "code": "es"},
)

if lang != "de":
langs.append(
{"url": "https://de.wammu.eu%s" % path, "name": "Deutsch", "code": "de"},
{"url": f"https://de.wammu.eu{path}", "name": "Deutsch", "code": "de"},
)

if lang != "ru":
langs.append(
{"url": "https://ru.wammu.eu%s" % path, "name": "Русский", "code": "ru"},
{"url": f"https://ru.wammu.eu{path}", "name": "Русский", "code": "ru"},
)

if lang != "sk":
langs.append(
{"url": "https://sk.wammu.eu%s" % path, "name": "Slovenčina", "code": "sk"},
{"url": f"https://sk.wammu.eu{path}", "name": "Slovenčina", "code": "sk"},
)

if lang != "fr":
langs.append(
{"url": "https://fr.wammu.eu%s" % path, "name": "Français", "code": "fr"},
{"url": f"https://fr.wammu.eu{path}", "name": "Français", "code": "fr"},
)

if lang != "pt-br":
langs.append(
{
"url": "https://pt-br.wammu.eu%s" % path,
"url": f"https://pt-br.wammu.eu{path}",
"name": "Português brasileiro",
"code": "pt-BR",
},
Expand Down

0 comments on commit 7af179c

Please sign in to comment.