You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by gc...@apache.org on 2025/05/01 14:48:13 UTC
(allura) 02/02: [#8578] ruff checks updates
This is an automated email from the ASF dual-hosted git repository.
gcruz pushed a commit to branch gc/8578
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 3f35d2367078ceb6a0610db3d94930899c5820be
Author: Guillermo Cruz <gu...@slashdotmedia.com>
AuthorDate: Thu May 1 08:47:40 2025 -0600
[#8578] ruff checks updates
---
Allura/allura/config/app_cfg.py | 2 +-
Allura/allura/lib/app_globals.py | 6 +++---
Allura/allura/lib/diff.py | 2 +-
Allura/allura/lib/helpers.py | 10 ++++------
Allura/allura/lib/macro.py | 2 +-
Allura/allura/lib/markdown_extensions.py | 2 +-
Allura/allura/lib/phone/nexmo.py | 4 ++--
Allura/allura/lib/utils.py | 2 +-
Allura/allura/lib/widgets/search.py | 4 ++--
Allura/allura/lib/widgets/user_profile.py | 2 +-
Allura/allura/model/auth.py | 2 +-
Allura/allura/model/index.py | 2 +-
Allura/allura/tasks/repo_tasks.py | 2 +-
ForgeGit/forgegit/tests/model/test_repository.py | 4 ++--
ForgeSVN/forgesvn/tests/model/test_repository.py | 4 ++--
ForgeTracker/forgetracker/model/ticket.py | 6 +++---
ForgeTracker/forgetracker/tracker_main.py | 2 +-
17 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/Allura/allura/config/app_cfg.py b/Allura/allura/config/app_cfg.py
index d03c1a5d2..8e17f7e08 100644
--- a/Allura/allura/config/app_cfg.py
+++ b/Allura/allura/config/app_cfg.py
@@ -194,7 +194,7 @@ def render(self, template, context):
context = self.context(context)
with ew.utils.push_context(ew.widget_context, render_context=context):
text = template.render(**context)
- return Markup(text)
+ return Markup(text) # noqa: S704
base_config = ForgeConfig()
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 0870579f8..0e9c72102 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -132,7 +132,7 @@ def cached_convert(self, artifact: MappedClass, field_name: str) -> Markup:
if cache.md5 is not None:
md5 = hashlib.md5(source_text.encode('utf-8')).hexdigest()
if cache.md5 == md5 and getattr(cache, 'fix7528', False) == bugfix_rev:
- return Markup(cache.html)
+ return Markup(cache.html) # noqa: S704
# Convert the markdown and time the result.
start = time.time()
@@ -477,7 +477,7 @@ def highlight(self, text, lexer=None, filename=None):
# no highlighting, but we should wrap it in a <pre> safely
return Markup('<pre>{}</pre>').format(text)
else:
- return Markup(pygments.highlight(text, lexer, formatter))
+ return Markup(pygments.highlight(text, lexer, formatter)) # noqa: S704
@property
def markdown(self):
@@ -694,4 +694,4 @@ def render(self, show_title=False, extra_css=None, closing_tag=True, tag='a', **
visible_title = f' {Markup.escape(title)}'
closing_tag = f'</{tag}>' if closing_tag else ''
icon = f'<{tag} {attrs}><i class="{self.css}"></i>{visible_title}{closing_tag}'
- return Markup(icon)
+ return Markup(icon) # noqa: S704
diff --git a/Allura/allura/lib/diff.py b/Allura/allura/lib/diff.py
index e9f7b60e8..3199b28e2 100644
--- a/Allura/allura/lib/diff.py
+++ b/Allura/allura/lib/diff.py
@@ -68,7 +68,7 @@ def _spit(self, content):
def run(self, diff_result: Iterable[LineChange | None]):
self.out = ''
super().run(diff_result)
- return Markup(self.out) # "safe" because we use html.escape in a few key places below
+ return Markup(self.out) # noqa: S704 "safe" because we use html.escape in a few key places below
def visit_row(self, line_change: LineChange | None):
if line_change is None:
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 96658f835..f66193a94 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -593,7 +593,7 @@ def escape_list(words_list):
result += ['<ins>'] + escape_list(t2_words[j1:j2]) + ['</ins>']
if tag == 'equal':
result += escape_list(t1_words[i1:i2])
- return Markup(' '.join(result).replace('\n', '<br/>\n'))
+ return Markup(' '.join(result).replace('\n', '<br/>\n')) # noqa: S704
def gen_message_id(_id=None):
@@ -800,7 +800,7 @@ def render_any_markup(name, txt, code_mode=False, linenumbers_style=TABLE):
txt = _add_table_line_numbers_to_text(txt)
else:
txt = '<pre>%s</pre>' % txt
- return Markup(txt)
+ return Markup(txt) # noqa: S704
@pass_context
@@ -828,7 +828,7 @@ def subrender_jinja_filter(context, html_tmpl: str) -> Markup:
def nl2br_jinja_filter(value):
result = '<br>\n'.join(escape(line) for line in value.split('\n'))
- return Markup(result)
+ return Markup(result) # noqa: S704
def log_if_changed(artifact, attr, new_val, message):
@@ -1416,6 +1416,4 @@ def parse_fediverse_address(username: str):
def clean_html(value: str) -> Markup:
from allura.lib.markdown_extensions import HTMLSanitizer
- return Markup(
- HTMLSanitizer().run(value)
- )
+ return Markup(HTMLSanitizer().run(value)) # noqa: S704
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index 711bd3de4..e073c35b6 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -505,6 +505,6 @@ def embed(url=None):
embed_url = embed_url.geturl()
embed_url = embed_url.replace('www.youtube.com', 'www.youtube-nocookie.com')
html.find('iframe')['src'] = embed_url
- return markupsafe.Markup('<p>%s</p>' % html)
+ return markupsafe.Markup('<p>%s</p>' % html) # noqa: S704
return '[[embed url=%s]]' % url
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 0228cc98b..eeff314f2 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -459,7 +459,7 @@ def reset(self):
class MarkAsSafe(markdown.postprocessors.Postprocessor):
def run(self, text):
- return Markup(text)
+ return Markup(text) # noqa: S704
class AddCustomClass(markdown.postprocessors.Postprocessor):
diff --git a/Allura/allura/lib/phone/nexmo.py b/Allura/allura/lib/phone/nexmo.py
index 9ac4829f7..3ee573e98 100644
--- a/Allura/allura/lib/phone/nexmo.py
+++ b/Allura/allura/lib/phone/nexmo.py
@@ -57,11 +57,11 @@ def error(self, code=None, msg=None, number=''):
msg = 'Failed sending request to Nexmo'
if str(code) == '3' and msg.endswith(' number'):
msg = markupsafe.Markup(
- '{}{}{}'.format(
+ '{}{}{}').format(
html.escape(msg), # escape it just in case Nexmo sent some HTML we don't want through
'<br>Make sure you include the country code (see examples above)',
'. For US numbers, you must include <code>1-</code> before the area code.' if len(number) == 10 else '',
- ))
+ )
return {'status': 'error', 'error': msg}
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index cbf6cc675..0391f026c 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -310,7 +310,7 @@ def extra_fields(self):
for fldno in range(self.num_honey):
fld_name = self.enc('honey%d' % (fldno))
fld_id = self.enc('honey%d%d' % (self.counter, fldno))
- yield Markup(self.honey_field_template).format(
+ yield Markup(self.honey_field_template).format( # noqa: S704
honey_class=self.honey_class,
fld_id=fld_id,
fld_name=fld_name)
diff --git a/Allura/allura/lib/widgets/search.py b/Allura/allura/lib/widgets/search.py
index c772992d1..2950b55c9 100644
--- a/Allura/allura/lib/widgets/search.py
+++ b/Allura/allura/lib/widgets/search.py
@@ -55,8 +55,8 @@ def __init__(self, comments=True, history=True, fields={}):
jinja2_env = jinja2.Environment(
autoescape=True,
loader=jinja2.PackageLoader('allura', 'templates/widgets'))
- self.content = Markup(jinja2_env.get_template('search_help.html').render(dict(
- comments=comments,
+ self.content = Markup(jinja2_env.get_template('search_help.html').render(dict( # noqa: S704
+ comments=comments,
history=history,
fields=fields,
)))
diff --git a/Allura/allura/lib/widgets/user_profile.py b/Allura/allura/lib/widgets/user_profile.py
index 6d1eb3588..65d669be5 100644
--- a/Allura/allura/lib/widgets/user_profile.py
+++ b/Allura/allura/lib/widgets/user_profile.py
@@ -132,7 +132,7 @@ def display(self, *a, **kw):
tmpl = g.jinja2_env.get_template(self.template)
if not self.context:
self.setup_context()
- return Markup(tmpl.render(self.context))
+ return Markup(tmpl.render(self.context)) # noqa: S704
except Exception as e:
log.exception('Error rendering section %s: %s', type(self).__name__, e)
if asbool(tg.config.get('debug')):
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 4088154b8..1fd0ab991 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -1083,7 +1083,7 @@ def message_html(self):
for line in
with_br.split('<br>\n')
])
- return Markup(message_bold)
+ return Markup(message_bold) # noqa: S704
@property
def url_str(self):
diff --git a/Allura/allura/model/index.py b/Allura/allura/model/index.py
index 64f5526b4..bd0e54241 100644
--- a/Allura/allura/model/index.py
+++ b/Allura/allura/model/index.py
@@ -166,7 +166,7 @@ def from_artifact(cls, a):
@classmethod
def from_links(cls, *links):
'''Convert a sequence of shortlinks to the matching Shortlink objects'''
- if len(links):
+ if links:
result = {}
# Parse all the links
parsed_links = {link: cls._parse_link(link)
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index e7855d655..e73a6d0b2 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -178,7 +178,7 @@ def can_merge(merge_request_id):
def determine_mr_commits(merge_request_id):
from allura import model as M
mr = M.MergeRequest.query.get(_id=merge_request_id)
- mr.commits # noqa: B018. build & cache the commits
+ mr.commits # noqa: B018 build & cache the commits
@task
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index adcbf756f..63b7b1a4e 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -199,7 +199,7 @@ def test_clone(self):
shutil.rmtree(dirname)
repo.init()
repo._impl.clone_from(repo_path)
- assert len(list(repo.log()))
+ assert list(repo.log())
assert not os.path.exists(
os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
assert not os.path.exists(
@@ -233,7 +233,7 @@ def test_hotcopy(self, clone_from):
repo.init()
repo._impl.clone_from(repo_path)
assert not clone_from.called
- assert len(list(repo.log()))
+ assert list(repo.log())
assert os.path.exists(
os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
assert os.path.exists(
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 631deea82..00c890b1b 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -171,7 +171,7 @@ def test_fork(self):
assert 'exec $DIR/post-commit-user "$@"\n' in hook_data
repo.refresh(notify=False)
- assert len(list(repo.log(limit=100)))
+ assert list(repo.log(limit=100))
shutil.rmtree(dirname)
@@ -221,7 +221,7 @@ def test_clone(self, post_event):
assert 'exec $DIR/post-commit-user "$@"\n' in c
repo.refresh(notify=False)
- assert len(list(repo.log(limit=100)))
+ assert list(repo.log(limit=100))
shutil.rmtree(dirname)
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 05a0fbd74..8445e63c6 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -459,7 +459,7 @@ def changes_iter(user):
# mark changes text as safe, thus it wouldn't be escaped in plain-text emails
# html part of email is handled by markdown and it'll be
# properly escaped
- yield (changed_tickets[t_id], markupsafe.Markup(changes[t_id]))
+ yield (changed_tickets[t_id], markupsafe.Markup(changes[t_id])) # noqa: S704
mail = dict(
sender=c.project.app_instance(self.app_config).email_address,
fromaddr=str(c.user._id),
@@ -482,7 +482,7 @@ def changes_iter(user):
v = user.display_name if user else v
head.append(f'- **{cf.label}**: {v}')
tmpl_context = {'context': c, 'data':
- {'header': markupsafe.Markup('\n'.join(['Mass edit changing:', ''] + head))}}
+ {'header': markupsafe.Markup('\n'.join(['Mass edit changing:', ''] + head))}} # noqa: S704
for user in users:
tmpl_context['data'].update({'changes': changes_iter(user)})
mail.update(dict(
@@ -501,7 +501,7 @@ def changes_iter(user):
self.app_config.options.get('TicketMonitoringType') ==
'AllTicketChanges'):
visible_changes.append(
- (changed_tickets[t_id], markupsafe.Markup(changes[t_id])))
+ (changed_tickets[t_id], markupsafe.Markup(changes[t_id]))) # noqa: S704
if visible_changes:
tmpl_context['data'].update({'changes': visible_changes})
mail.update(dict(
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 708345038..92d630ba8 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -389,7 +389,7 @@ def sidebar_menu(self):
links += milestones
- if len(search_bins):
+ if search_bins:
links.append(SitemapEntry('Searches'))
links = links + search_bins
links.append(SitemapEntry('Help'))