Skip to content

Commit cc467e4

Browse files
committed
Fix ruff lint errors and add README badges
Rename ambiguous variable `l` to `line` (E741), remove unused BASE_IRI import (F401), apply ruff formatting, and add CI + license badges to README.
1 parent 41a4cb1 commit cc467e4

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# WikiPathways IRI Resolver
22

3+
[![CI](https://github.com/wikipathways/wikipathways-iri-resolver/actions/workflows/ci.yml/badge.svg)](https://github.com/wikipathways/wikipathways-iri-resolver/actions/workflows/ci.yml)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5+
36
A lightweight Flask app that makes `http://rdf.wikipathways.org/` IRIs resolvable by proxying requests as SPARQL `DESCRIBE` queries against the WikiPathways Virtuoso endpoint.
47

58
## Features

app.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
storage_uri="memory://",
9191
)
9292

93+
9394
# ---------------------------------------------------------------------------
9495
# CORS & caching headers
9596
# ---------------------------------------------------------------------------
@@ -163,7 +164,9 @@ def is_empty_turtle(text):
163164
Virtuoso returns ``# Empty TURTLE`` instead of an empty body.
164165
"""
165166
stripped = "\n".join(
166-
l for l in text.splitlines() if l.strip() and not l.strip().startswith("#")
167+
line
168+
for line in text.splitlines()
169+
if line.strip() and not line.strip().startswith("#")
167170
)
168171
return not stripped
169172

@@ -176,11 +179,12 @@ def linkify_iris(html):
176179
Only IRIs starting with the BASE_IRI are made into relative links
177180
so they resolve within this service; others link externally.
178181
"""
182+
179183
def _replace(match):
180184
url = match.group(0)
181185
if url.startswith(BASE_IRI + "/"):
182186
# Relative link within this service
183-
relative = "/" + url[len(BASE_IRI) + 1:]
187+
relative = "/" + url[len(BASE_IRI) + 1 :]
184188
return f'<a href="{relative}">{url}</a>'
185189
return f'<a href="{url}" rel="noopener">{url}</a>'
186190

test_app.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
import responses
55

6-
from app import app, _cache, BASE_IRI, SPARQL_ENDPOINT
6+
from app import app, _cache, SPARQL_ENDPOINT
77

88

99
SAMPLE_TURTLE = """\
@@ -100,9 +100,7 @@ def test_html_contains_clickable_links(client):
100100
@responses.activate
101101
def test_resolve_turtle_accept(client):
102102
responses.get(SPARQL_ENDPOINT, body=SAMPLE_TURTLE, status=200)
103-
resp = client.get(
104-
"/Pathway/WP4846_r140186", headers={"Accept": "text/turtle"}
105-
)
103+
resp = client.get("/Pathway/WP4846_r140186", headers={"Accept": "text/turtle"})
106104
assert resp.status_code == 200
107105
assert "text/turtle" in resp.content_type
108106
assert b"wp:Pathway" in resp.data
@@ -130,7 +128,9 @@ def test_resolve_jsonld_extension(client):
130128

131129
@responses.activate
132130
def test_resolve_rdf_extension(client):
133-
rdfxml_body = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>'
131+
rdfxml_body = (
132+
'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>'
133+
)
134134
responses.get(SPARQL_ENDPOINT, body=rdfxml_body, status=200)
135135
resp = client.get("/Pathway/WP4846_r140186.rdf")
136136
assert resp.status_code == 200
@@ -139,7 +139,7 @@ def test_resolve_rdf_extension(client):
139139

140140
@responses.activate
141141
def test_resolve_nt_extension(client):
142-
nt_body = '<http://example.org/s> <http://example.org/p> <http://example.org/o> .\n'
142+
nt_body = "<http://example.org/s> <http://example.org/p> <http://example.org/o> .\n"
143143
responses.get(SPARQL_ENDPOINT, body=nt_body, status=200)
144144
resp = client.get("/Pathway/WP4846_r140186.nt")
145145
assert resp.status_code == 200
@@ -178,6 +178,7 @@ def test_empty_result_404_turtle(client):
178178
@responses.activate
179179
def test_sparql_connection_error_502(client):
180180
from requests.exceptions import ConnectionError as RequestsConnectionError
181+
181182
responses.get(SPARQL_ENDPOINT, body=RequestsConnectionError("refused"))
182183
resp = client.get("/Pathway/WP4846_r140186")
183184
assert resp.status_code == 502
@@ -186,6 +187,7 @@ def test_sparql_connection_error_502(client):
186187
@responses.activate
187188
def test_sparql_timeout_504(client):
188189
from requests.exceptions import ReadTimeout
190+
189191
responses.get(SPARQL_ENDPOINT, body=ReadTimeout("timed out"))
190192
resp = client.get("/Pathway/WP4846_r140186")
191193
assert resp.status_code == 504
@@ -234,9 +236,7 @@ def test_if_none_match_304(client):
234236
resp1 = client.get("/Pathway/WP4846_r140186")
235237
etag = resp1.headers["ETag"]
236238
# Second request with If-None-Match
237-
resp2 = client.get(
238-
"/Pathway/WP4846_r140186", headers={"If-None-Match": etag}
239-
)
239+
resp2 = client.get("/Pathway/WP4846_r140186", headers={"If-None-Match": etag})
240240
assert resp2.status_code == 304
241241

242242

@@ -271,6 +271,7 @@ def test_rate_limit_handler(client):
271271
"""The 429 error handler returns a proper response."""
272272
with app.test_request_context():
273273
from app import handle_429
274+
274275
resp = handle_429(None)
275276
assert resp.status_code == 429
276277
assert b"Rate limit" in resp.data

0 commit comments

Comments
 (0)