Skip to content

Commit 3999f85

Browse files
authored
Merge pull request #130 from SaInekK/pr/ruff-config-cleanup
add ruff config and clean unused imports
2 parents 5032509 + 1e98f07 commit 3999f85

8 files changed

Lines changed: 25 additions & 17 deletions

File tree

pyproject.toml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,27 @@ dependencies = [
6565
[project.optional-dependencies]
6666

6767
# dev - the developer dependency set, for contributors to harmony
68-
dev = ["check-manifest", "pytest", "matplotlib"]
68+
dev = ["check-manifest", "pytest", "matplotlib", "ruff"]
69+
70+
[tool.ruff]
71+
target-version = "py310"
72+
line-length = 120
73+
extend-exclude = ["update.ipynb", "Harmony_example_walkthrough.ipynb"]
74+
75+
[tool.ruff.lint]
76+
# Pragmatic baseline for a legacy research codebase:
77+
# enable pyflakes (real bugs), ignore stylistic noise that would require
78+
# touching many files for no functional gain.
79+
select = ["F", "E9"]
80+
ignore = [
81+
"F403", # `from module import *` — used intentionally in __init__.py
82+
"F405", # `*`-import undefined names — paired with F403
83+
"F841", # unused local — common in legacy code, low value to fix now
84+
]
85+
86+
[tool.ruff.lint.per-file-ignores]
87+
"__init__.py" = ["F401"] # re-exports
88+
"tests/*" = ["F401"]
6989

7090
[project.urls]
7191
"Documentation" = "https://harmonydata.ac.uk/frequently-asked-questions/"

src/harmony/matching/cluster.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
from harmony.matching.default_matcher import convert_texts_to_vector
1010
from harmony.schemas.requests.text import Question
11-
from harmony.schemas.responses.text import HarmonyCluster
1211

13-
import numpy as np
1412
from sklearn.metrics.pairwise import cosine_similarity
1513
from harmony.matching.deterministic_clustering import find_clusters_deterministic
1614

src/harmony/matching/kmeans_clustering.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import sys
21
from typing import List
32

4-
import pandas as pd
53
from sklearn.cluster import KMeans
6-
from sklearn.decomposition import PCA
7-
from sklearn.metrics import silhouette_score
84

95
from harmony.matching.generate_cluster_topics import generate_cluster_topics
106
from harmony.schemas.requests.text import Question
117
from harmony.schemas.responses.text import HarmonyCluster
128

13-
import numpy as np
14-
from sklearn.metrics.pairwise import cosine_similarity
159

1610

1711
def perform_kmeans(embeddings_in, num_clusters=5):

src/harmony/matching/wmd_matcher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from wmd import WMD
21
import numpy as np
32
import math
43
import libwmdrelax

src/harmony/parsing/html_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
# Try to import lxml for better performance, fall back to html.parser
3535
try:
36-
import lxml
36+
import lxml # noqa: F401 # availability probe
3737
DEFAULT_PARSER = 'lxml'
3838
except ImportError:
3939
DEFAULT_PARSER = 'html.parser'

src/harmony/schemas/requests/text.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
'''
2727

2828
import uuid
29-
from typing import List, Optional
29+
from typing import Any, Dict, List, Optional
3030
from pydantic import ConfigDict, BaseModel, Field
3131
from harmony.schemas.catalogue_instrument import CatalogueInstrument
3232
from harmony.schemas.catalogue_question import CatalogueQuestion
3333
from harmony.schemas.enums.file_types import FileType
3434
from harmony.schemas.enums.languages import Language
35-
from pydantic import ConfigDict, BaseModel, Field
36-
from typing import Any, Dict, List, Optional
3735

3836
DEFAULT_FRAMEWORK = "huggingface"
3937
DEFAULT_MODEL = 'sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2'

src/harmony/services/export_pdf_report.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
2-
import io
32
from datetime import datetime
4-
from typing import List, Optional, Tuple
3+
from typing import List, Tuple
54
import tempfile
65
from fpdf import FPDF
76

src/harmony/util/url_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _validate_url(self, url: str) -> None:
9090
parsed = urllib.parse.urlparse(url)
9191

9292
if parsed.scheme not in ALLOWED_SCHEMES:
93-
raise BadRequestError(f"URL must use HTTPS")
93+
raise BadRequestError("URL must use HTTPS")
9494

9595
if not parsed.netloc or '.' not in parsed.netloc:
9696
raise BadRequestError("Invalid domain")

0 commit comments

Comments
 (0)