Skip to content

Commit 399fd23

Browse files
ptgoldenGlassglass-ships
authored
Use ruff format for code formatting (#1032)
### Related issues - Closes #965 ### Summary Drops `black` as a dependency, in favor of using `ruff format` as a formatter. On my machine, it's a ~100x speedup. There's a small change to the makefile too. Instead of using the `--exit-zero` flag in `ruff check`, the command is prefixed with `-` to [continue running even after a non-zero exit code](https://www.gnu.org/software/make/manual/make.html#Errors-in-Recipes). ### Checks - [x] All tests have passed (or issues created for failing tests) --------- Co-authored-by: Glass <glass.ships@outlook.com> Co-authored-by: Glass <glass.ships@protonmail.com>
1 parent 6b16e2c commit 399fd23

File tree

12 files changed

+34
-33
lines changed

12 files changed

+34
-33
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ lint-frontend:
198198

199199
.PHONY: lint-backend
200200
lint-backend:
201-
$(RUN) ruff check --diff --exit-zero .
202-
$(RUN) black --check --diff -l 120 src tests
201+
-$(RUN) ruff check --diff .
202+
-$(RUN) ruff format --diff .
203203

204204

205205
.PHONY: format
@@ -208,8 +208,8 @@ format: format-frontend format-backend
208208

209209
.PHONY: format-backend
210210
format-backend:
211-
$(RUN) ruff check --fix --exit-zero .
212-
$(RUN) black -l 120 src tests
211+
-$(RUN) ruff check --fix .
212+
-$(RUN) ruff format .
213213

214214

215215
.PHONY: format-frontend

backend/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ pythonpath = [".", "src"]
6767

6868
[tool.ruff]
6969
line-length = 120
70+
exclude = ["tests/fixtures/*.py", "src/monarch_py/datamodels/model.py"]
71+
# per-file-ignores = {"" = ""}
72+
73+
[tool.ruff.lint]
7074
ignore = [
7175
"F541", # f-strings with no placeholders
7276
]

backend/src/monarch_py/api/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Settings(BaseModel):
1616

1717
semsim_server_host: str = os.getenv("SEMSIM_SERVER_HOST", "127.0.0.1")
1818
semsim_server_port: str = os.getenv("SEMSIM_SERVER_PORT", 9999)
19-
19+
2020
monarch_kg_version: str = os.getenv("MONARCH_KG_VERSION", "unknown")
2121
monarch_api_version: str = os.getenv("MONARCH_API_VERSION", "unknown")
2222
monarch_kg_source: str = os.getenv("MONARCH_KG_SOURCE", "unknown")

backend/src/monarch_py/api/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def autocomplete(
5555
default="*:*",
5656
title="Query string to autocomplete against",
5757
examples=["fanc", "ehler"],
58-
)
58+
),
5959
) -> SearchResults:
6060
"""Autocomplete for entities by label
6161

backend/src/monarch_py/api/semsim.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def _compare(
6161
print(
6262
f"""
6363
Running semsim compare:
64-
subjects: {subjects.split(',')}
65-
objects: {objects.split(',')}
64+
subjects: {subjects.split(",")}
65+
objects: {objects.split(",")}
6666
metric: {metric}
6767
"""
6868
)

backend/src/monarch_py/implementations/solr/solr_query_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def build_association_query(
3030
offset: int = 0,
3131
limit: int = 20,
3232
) -> SolrQuery:
33-
3433
entity_fields = ["subject", "object", "disease_context_qualifier"]
3534
"""Populate a SolrQuery object with association filters"""
3635
query = SolrQuery(start=offset, rows=limit)

backend/src/monarch_py/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ def get_release_metadata(release: str, dev: bool = False):
131131

132132
def print_release_info(release_info: Release):
133133
for key, value in release_info.model_dump().items():
134-
console.print(f"{key+' ':—<12} {value}")
134+
console.print(f"{key + ' ':—<12} {value}")

backend/tests/integration/test_solr_association.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def test_entity():
6868
assert response
6969
assert response.total > 50
7070
for association in response.items:
71-
7271
if (
7372
association.subject_closure is None or len(association.subject_closure) == 0
7473
) and association.disease_context_qualifier is None:

backend/tests/unit/test_oak_semsim.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
@pytest.mark.skip(reason="This is a long running test")
77
def test_semsim_compare():
8-
98
subject_ids = ["MP:0010771"]
109
object_ids = ["HP:0004325"]
1110

backend/tests/unit/test_solr_entity_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def test_get_counterpart_entity(association, this_entity, other_entity):
4949
"""Test that the get_counterpart_entity function returns the correct entity"""
5050
si = SolrImplementation()
5151
associated_entity = si._get_counterpart_entity(association, this_entity)
52-
assert (
53-
associated_entity == other_entity
54-
), f"Associated entity is not as expected. Expected: {other_entity}, got: {associated_entity}"
52+
assert associated_entity == other_entity, (
53+
f"Associated entity is not as expected. Expected: {other_entity}, got: {associated_entity}"
54+
)
5555

5656

5757
def test_entity_boost_with_empty_calls_blank_search_boost():

0 commit comments

Comments
 (0)