Skip to content
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
16 changes: 7 additions & 9 deletions .github/workflows/slack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ on:
branches: [main]
jobs:
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Post to Slack
uses: slackapi/[email protected]
with:
channel-id: 'C4K6M7P5E'
slack-message: "A workflow run failed\n*Repo:* `${{ github.event.repository.full_name }}` (${{ github.event.repository.html_url }})\n*Workflow:* ${{ github.event.workflow.name }} (${{ github.event.workflow.html_url }})\n*Branch:* `${{ github.event.workflow_run.head_branch }}`\n*Commit:* `${{ github.event.workflow_run.head_commit.id }}`\n*Run:* ${{ github.event.workflow_run.html_url }}\n*Conclusion:* ${{ github.event.workflow_run.conclusion }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
name: Post to Slack
uses: hypothesis/workflows/.github/workflows/slack.yml@main
with:
payload: |
channel: "C4K6M7P5E"
markdown_text: "Failed `${{ github.event.workflow_run.path }}` run (attempt ${{ github.event.workflow_run.run_attempt }}) on `${{ github.event.workflow_run.head_branch }}` in `${{ github.event.workflow_run.repository.full_name }}`: ${{ github.event.workflow_run.html_url }}"
secrets: inherit
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ $(call help,make help,print this help message)
$(call help,make services,start the services that the app needs)
services: args?=up -d --wait
services: python
@docker network create dbs 2>/dev/null || true
@docker compose $(args)

.PHONY: db
Expand Down
8 changes: 4 additions & 4 deletions h/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def fetch_git_ref():
return subprocess.check_output( # noqa: S603
return subprocess.check_output(
["git", "rev-parse", "--short", "HEAD"], # noqa: S607
stderr=DEVNULL,
).strip()
Expand All @@ -27,10 +27,10 @@ def fetch_git_date(ref):
def fetch_git_dirty():
# Ensure git index is up-to-date first. This usually isn't necessary, but
# can be needed inside a docker container where the index is out of date.
subprocess.call(["git", "update-index", "-q", "--refresh"]) # noqa: S603, S607
dirty_tree = bool(subprocess.call(["git", "diff-files", "--quiet"])) # noqa: S603, S607
subprocess.call(["git", "update-index", "-q", "--refresh"]) # noqa: S607
dirty_tree = bool(subprocess.call(["git", "diff-files", "--quiet"])) # noqa: S607
dirty_index = bool(
subprocess.call(["git", "diff-index", "--quiet", "--cached", "HEAD"]) # noqa: S603, S607
subprocess.call(["git", "diff-index", "--quiet", "--cached", "HEAD"]) # noqa: S607
)
return dirty_tree or dirty_index

Expand Down
2 changes: 1 addition & 1 deletion h/activity/bucketing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
_ = i18n.TranslationStringFactory(__package__)


class DocumentBucket:
class DocumentBucket: # noqa: PLW1641
def __init__(self, document, annotations=None):
self.annotations = []
self.tags = set()
Expand Down
2 changes: 1 addition & 1 deletion h/cli/commands/create_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@click.pass_context
@click.option("--number", default=100)
def create_annotations(ctx, number):
from tests.common import factories
from tests.common import factories # noqa: PLC0415

request = ctx.obj["bootstrap"]()
db = request.db
Expand Down
6 changes: 3 additions & 3 deletions h/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def close_the_sqlalchemy_session(_request):


def _maybe_create_default_organization(engine, authority): # pragma: no cover
from h.services.organization import OrganizationService
from h.services.organization import OrganizationService # noqa: PLC0415

session = Session(bind=engine)
default_org = OrganizationService(session).get_default(authority)
Expand All @@ -134,8 +134,8 @@ def _maybe_create_default_organization(engine, authority): # pragma: no cover


def _maybe_create_world_group(engine, authority, default_org): # pragma: no cover
from h import models
from h.models.group import ReadableBy, WriteableBy
from h import models # noqa: PLC0415
from h.models.group import ReadableBy, WriteableBy # noqa: PLC0415

session = Session(bind=engine)
world_group = session.query(models.Group).filter_by(pubid="__world__").one_or_none()
Expand Down
2 changes: 1 addition & 1 deletion h/db/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Custom SQLAlchemy types for use with the Annotations API database.""" # noqa: A005
"""Custom SQLAlchemy types for use with the Annotations API database."""

import base64
import binascii
Expand Down
2 changes: 1 addition & 1 deletion h/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __call__(self, template_name, **kwargs):
context = self._system.copy()
context.update(kwargs)

return Markup(template.render(context))
return Markup(f"{template.render(context)}") # noqa: S704


def create_environment(base):
Expand Down
2 changes: 1 addition & 1 deletion h/jinja_extensions/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ def to_json(value):
.replace("'", "\\u0027")
)

return Markup(result)
return Markup(result) # noqa: S704
2 changes: 1 addition & 1 deletion h/jinja_extensions/svg_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def svg_icon(name, css_class=""):
if title_el is not None:
root.remove(title_el)

return Markup(ElementTree.tostring(root).decode())
return Markup(ElementTree.tostring(root).decode()) # noqa: S704
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ def downgrade():


def _document_title(document):
for meta in document.meta_titles: # noqa: RET503
for meta in document.meta_titles:
if meta.value:
return meta.value[0]

return None


def _fetch_windows(session, chunksize=100):
updated = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ class Document(Base):

def updated_web_uri(self):
def first_http_url(type_=None):
for document_uri in self.document_uris: # noqa: RET503
for document_uri in self.document_uris:
uri = document_uri.uri
if type_ is not None and document_uri.type != type_:
continue
if urlparse(uri).scheme not in ["http", "https"]:
continue
return document_uri.uri

return None

return (
first_http_url(type_="self-claim")
or first_http_url(type_="rel-canonical")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ def downgrade():


def _document_web_uri(document):
for docuri in document.document_uris: # noqa: RET503
for docuri in document.document_uris:
uri = urlparse(docuri.uri)
if uri.scheme in ["http", "https"]:
return docuri.uri

return None


def _fetch_windows(session, chunksize=100):
updated = (
Expand Down
6 changes: 4 additions & 2 deletions h/models/document/_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ def first_http_url(type_=None):
If no type is given just return this document's first http(s)
URL, or None.
"""
for document_uri in self.document_uris: # noqa: RET503
for document_uri in self.document_uris:
uri = document_uri.uri
if type_ is not None and document_uri.type != type_:
continue
if urlparse(uri).scheme not in ["http", "https"]:
continue
return document_uri.uri

return None

self.web_uri = (
first_http_url(type_="self-claim")
or first_http_url(type_="rel-canonical")
Expand Down Expand Up @@ -155,7 +157,7 @@ def merge_documents(session, documents, updated=None):
# the purpose of centralized model access in the service.
# It's pending to move the rest of this functions to a DocumentService that uses DI to get this service.
# In the meantime we are doing this import here to avoid a circular dependency.
from h.services.annotation_write import AnnotationWriteService
from h.services.annotation_write import AnnotationWriteService # noqa: PLC0415

AnnotationWriteService.change_document(session, duplicate_ids, master)
session.query(Document).filter(Document.id.in_(duplicate_ids)).delete(
Expand Down
2 changes: 1 addition & 1 deletion h/models/token.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime # noqa: A005
import datetime
from typing import TYPE_CHECKING

import sqlalchemy
Expand Down
2 changes: 1 addition & 1 deletion h/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def in_(self, other):
return _normalise_username(self.__clause_element__()).in_(usernames)


class UserIDComparator(Comparator):
class UserIDComparator(Comparator): # noqa: PLW1641
"""
Custom comparator for :py:attr:`~h.models.user.User.userid`.

Expand Down
2 changes: 1 addition & 1 deletion h/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def paginate(request, total, page_size=PAGE_SIZE):
first = 1
page_max = int(math.ceil(total / page_size))
page_max = int(math.ceil(total / page_size)) # noqa: RUF046
page_max = max(1, page_max) # There's always at least one page.

try:
Expand Down
2 changes: 1 addition & 1 deletion h/presenters/annotation_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def text_rendered(self):
care of all necessary escaping.
"""
if self.annotation.text_rendered:
return Markup(self.annotation.text_rendered)
return Markup(self.annotation.text_rendered) # noqa: S704
return Markup("")

@property
Expand Down
2 changes: 1 addition & 1 deletion h/presenters/document_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,4 @@ def truncate(content, length=55):
host_or_filename=markupsafe.escape(host_or_filename),
)

return markupsafe.Markup(link)
return markupsafe.Markup(f"{link}") # noqa: S704
2 changes: 1 addition & 1 deletion h/pshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def setup(env):
from tests.common import factories
from tests.common import factories # noqa: PLC0415

request = env["request"]

Expand Down
2 changes: 1 addition & 1 deletion h/security/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def derive_key(key_material: str | bytes, salt: bytes, info: bytes) -> bytes:
key_material = key_material.encode()

return cast(
bytes,
"bytes",
HKDF(
master=key_material,
key_len=64,
Expand Down
2 changes: 0 additions & 2 deletions h/services/email.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# noqa: A005

import smtplib
from dataclasses import dataclass
from datetime import UTC, datetime, timedelta
Expand Down
2 changes: 1 addition & 1 deletion h/services/flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def flag_counts(self, annotation_ids):

flag_counts = {f.annotation_id: f.flag_count for f in query}
missing_ids = set(annotation_ids) - set(flag_counts.keys())
flag_counts.update({id_: 0 for id_ in missing_ids})
flag_counts.update(dict.fromkeys(missing_ids, 0))

# Prime the cache for `flag_count()`
self._flag_count_cache.update(flag_counts)
Expand Down
2 changes: 0 additions & 2 deletions h/services/html.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# noqa: A005

from html.parser import HTMLParser


Expand Down
2 changes: 1 addition & 1 deletion h/services/http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from requests import RequestException, Response, Session # noqa: A005
from requests import RequestException, Response, Session

from h.services.exceptions import ExternalRequestError

Expand Down
2 changes: 1 addition & 1 deletion h/streamer/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def reply(self, payload, ok=True): # noqa: FBT002
"""
reply_to = self.payload.get("id")
# Short-circuit if message is missing an ID or has a non-numeric ID.
if not isinstance(reply_to, (int, float)): # noqa: UP038
if not isinstance(reply_to, (int, float)):
return
data = copy.deepcopy(payload)
data["ok"] = ok
Expand Down
2 changes: 1 addition & 1 deletion h/tasks/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A module for sending email.

This module defines a Celery task for sending emails in a worker process.
""" # noqa: A005
"""

from typing import Any

Expand Down
2 changes: 1 addition & 1 deletion h/util/datetime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Shared utility functions for manipulating dates and times.""" # noqa: A005
"""Shared utility functions for manipulating dates and times."""


def utc_iso8601(datetime):
Expand Down
22 changes: 11 additions & 11 deletions h/views/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ def _reset_password(self, user, password):
svc.update_password(user, password)

self.request.session.flash(
Markup(
_(
_(
Markup(
"Your password has been reset. You can now log in with "
"your new password."
)
Expand Down Expand Up @@ -346,8 +346,8 @@ def get_when_not_logged_in(self):
activation = models.Activation.get_by_code(self.request.db, code)
if activation is None:
self.request.session.flash(
Markup(
_(
_(
Markup(
"We didn't recognize that activation link. "
"Have you already activated your account? "
"If so, try logging in using the username "
Expand All @@ -365,8 +365,8 @@ def get_when_not_logged_in(self):
user.activate()

self.request.session.flash(
Markup(
_(
_(
Markup(
"Your account has been activated! "
"You can now log in using the password you provided."
),
Expand Down Expand Up @@ -394,18 +394,18 @@ def get_when_logged_in(self):
# The user is already logged in to the account (so the account
# must already be activated).
self.request.session.flash(
Markup(_("Your account has been activated and you're logged in.")),
_(Markup("Your account has been activated and you're logged in.")),
"success",
)
else:
self.request.session.flash(
Markup(
_(
_(
Markup(
"You're already logged in to a different account. "
'<a href="{url}">Log out</a> and open the activation link '
"again."
).format(url=self.request.route_url("logout"))
),
)
).format(url=self.request.route_url("logout")),
"error",
)

Expand Down
8 changes: 3 additions & 5 deletions h/views/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,9 @@ def user_annotation_count(aggregation, userid):
result["more_info"] = "more_info" in self.request.params

if not result.get("q"):
result["zero_message"] = Markup(
_("The group “{name}” has not made any annotations yet.").format(
name=Markup.escape(self.group.name)
)
)
result["zero_message"] = _(
Markup("The group “{name}” has not made any annotations yet.")
).format(name=Markup.escape(self.group.name))

result["show_leave_button"] = self.request.user in self.group.members

Expand Down
2 changes: 1 addition & 1 deletion h/views/admin/email.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dataclasses import asdict # noqa: A005
from dataclasses import asdict

from pyramid.httpexceptions import HTTPSeeOther
from pyramid.view import view_config
Expand Down
2 changes: 1 addition & 1 deletion h/views/admin/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def on_success(appstruct):
self.group_members_svc.add_members(group, member_userids)

self.request.session.flash(
Markup(f'Created new group "{group.name}"'),
Markup('Created new group "{}"').format(group.name),
queue="success",
)

Expand Down
2 changes: 1 addition & 1 deletion h/views/admin/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def on_success(appstruct):

self.request.db.add(organization)
self.request.session.flash(
Markup(_(f"Created new organization {name}")), # noqa: INT001
_(Markup("Created new organization {}")).format(name),
"success",
)

Expand Down
Loading
Loading