diff --git a/Makefile b/Makefile index 59aea5569..f292aa615 100644 --- a/Makefile +++ b/Makefile @@ -198,8 +198,8 @@ lint-frontend: .PHONY: lint-backend lint-backend: - $(RUN) ruff check --diff --exit-zero . - $(RUN) black --check --diff -l 120 src tests + -$(RUN) ruff check --diff . + -$(RUN) ruff format --diff . .PHONY: format @@ -208,8 +208,8 @@ format: format-frontend format-backend .PHONY: format-backend format-backend: - $(RUN) ruff check --fix --exit-zero . - $(RUN) black -l 120 src tests + -$(RUN) ruff check --fix . + -$(RUN) ruff format . .PHONY: format-frontend diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 3cb5df53c..fc8786426 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -67,6 +67,10 @@ pythonpath = [".", "src"] [tool.ruff] line-length = 120 +exclude = ["tests/fixtures/*.py", "src/monarch_py/datamodels/model.py"] +# per-file-ignores = {"" = ""} + +[tool.ruff.lint] ignore = [ "F541", # f-strings with no placeholders ] diff --git a/backend/src/monarch_py/api/config.py b/backend/src/monarch_py/api/config.py index ee92fb9a9..5c7350ff6 100644 --- a/backend/src/monarch_py/api/config.py +++ b/backend/src/monarch_py/api/config.py @@ -16,7 +16,7 @@ class Settings(BaseModel): semsim_server_host: str = os.getenv("SEMSIM_SERVER_HOST", "127.0.0.1") semsim_server_port: str = os.getenv("SEMSIM_SERVER_PORT", 9999) - + monarch_kg_version: str = os.getenv("MONARCH_KG_VERSION", "unknown") monarch_api_version: str = os.getenv("MONARCH_API_VERSION", "unknown") monarch_kg_source: str = os.getenv("MONARCH_KG_SOURCE", "unknown") diff --git a/backend/src/monarch_py/api/search.py b/backend/src/monarch_py/api/search.py index 41627c6c4..873e91835 100644 --- a/backend/src/monarch_py/api/search.py +++ b/backend/src/monarch_py/api/search.py @@ -55,7 +55,7 @@ async def autocomplete( default="*:*", title="Query string to autocomplete against", examples=["fanc", "ehler"], - ) + ), ) -> SearchResults: """Autocomplete for entities by label diff --git a/backend/src/monarch_py/api/semsim.py b/backend/src/monarch_py/api/semsim.py index f4bf7c23c..c19359411 100644 --- a/backend/src/monarch_py/api/semsim.py +++ b/backend/src/monarch_py/api/semsim.py @@ -61,8 +61,8 @@ def _compare( print( f""" Running semsim compare: - subjects: {subjects.split(',')} - objects: {objects.split(',')} + subjects: {subjects.split(",")} + objects: {objects.split(",")} metric: {metric} """ ) diff --git a/backend/src/monarch_py/implementations/solr/solr_query_utils.py b/backend/src/monarch_py/implementations/solr/solr_query_utils.py index 508d8395d..0df862b65 100644 --- a/backend/src/monarch_py/implementations/solr/solr_query_utils.py +++ b/backend/src/monarch_py/implementations/solr/solr_query_utils.py @@ -30,7 +30,6 @@ def build_association_query( offset: int = 0, limit: int = 20, ) -> SolrQuery: - entity_fields = ["subject", "object", "disease_context_qualifier"] """Populate a SolrQuery object with association filters""" query = SolrQuery(start=offset, rows=limit) diff --git a/backend/src/monarch_py/utils/utils.py b/backend/src/monarch_py/utils/utils.py index 2d106051a..85b290c6f 100644 --- a/backend/src/monarch_py/utils/utils.py +++ b/backend/src/monarch_py/utils/utils.py @@ -131,4 +131,4 @@ def get_release_metadata(release: str, dev: bool = False): def print_release_info(release_info: Release): for key, value in release_info.model_dump().items(): - console.print(f"{key+' ':—<12} {value}") + console.print(f"{key + ' ':—<12} {value}") diff --git a/backend/tests/integration/test_solr_association.py b/backend/tests/integration/test_solr_association.py index 3c877d622..4bdd39326 100644 --- a/backend/tests/integration/test_solr_association.py +++ b/backend/tests/integration/test_solr_association.py @@ -68,7 +68,6 @@ def test_entity(): assert response assert response.total > 50 for association in response.items: - if ( association.subject_closure is None or len(association.subject_closure) == 0 ) and association.disease_context_qualifier is None: diff --git a/backend/tests/unit/test_oak_semsim.py b/backend/tests/unit/test_oak_semsim.py index 034164adf..a6ca9010a 100644 --- a/backend/tests/unit/test_oak_semsim.py +++ b/backend/tests/unit/test_oak_semsim.py @@ -5,7 +5,6 @@ @pytest.mark.skip(reason="This is a long running test") def test_semsim_compare(): - subject_ids = ["MP:0010771"] object_ids = ["HP:0004325"] diff --git a/backend/tests/unit/test_solr_entity_utils.py b/backend/tests/unit/test_solr_entity_utils.py index 88dbeb203..ff5b40ea5 100644 --- a/backend/tests/unit/test_solr_entity_utils.py +++ b/backend/tests/unit/test_solr_entity_utils.py @@ -49,9 +49,9 @@ def test_get_counterpart_entity(association, this_entity, other_entity): """Test that the get_counterpart_entity function returns the correct entity""" si = SolrImplementation() associated_entity = si._get_counterpart_entity(association, this_entity) - assert ( - associated_entity == other_entity - ), f"Associated entity is not as expected. Expected: {other_entity}, got: {associated_entity}" + assert associated_entity == other_entity, ( + f"Associated entity is not as expected. Expected: {other_entity}, got: {associated_entity}" + ) def test_entity_boost_with_empty_calls_blank_search_boost(): diff --git a/backend/tests/unit/test_solr_parsers.py b/backend/tests/unit/test_solr_parsers.py index 30352de79..5ebc2d0ca 100644 --- a/backend/tests/unit/test_solr_parsers.py +++ b/backend/tests/unit/test_solr_parsers.py @@ -24,27 +24,27 @@ def test_parse_associations_compact(association_response, associations_compact): association_response["response"]["numFound"] = association_response["response"].pop("num_found") solr_response = SolrQueryResult(**association_response) parsed = parse_associations(solr_response, compact=True).model_dump() - assert ( - parsed == associations_compact - ), f"Parsed result is not as expected. Difference: {dict_diff(parsed, associations_compact)}" + assert parsed == associations_compact, ( + f"Parsed result is not as expected. Difference: {dict_diff(parsed, associations_compact)}" + ) def test_parse_association_counts(association_counts_response, association_counts, node): association_counts_response["response"]["numFound"] = association_counts_response["response"].pop("num_found") solr_response = SolrQueryResult(**association_counts_response) parsed = parse_association_counts(solr_response, entity=Node(**node).id).model_dump() - assert ( - parsed == association_counts - ), f"Parsed result is not as expected. Difference: {dict_diff(parsed, association_counts)}" + assert parsed == association_counts, ( + f"Parsed result is not as expected. Difference: {dict_diff(parsed, association_counts)}" + ) def test_parse_association_table(association_table_response, association_table, node): association_table_response["response"]["numFound"] = association_table_response["response"].pop("num_found") solr_response = SolrQueryResult(**association_table_response) parsed = parse_association_table(solr_response, entity=[Node(**node).id], offset=0, limit=5).model_dump() - assert ( - parsed == association_table - ), f"Parsed result is not as expected. Difference: {dict_diff(parsed, association_table)}" + assert parsed == association_table, ( + f"Parsed result is not as expected. Difference: {dict_diff(parsed, association_table)}" + ) def test_parse_entity(entity_response, node): @@ -64,9 +64,9 @@ def test_parse_search(search_response, search): solr_response = SolrQueryResult(**search_response) parsed = parse_search(solr_response).model_dump() # assert that top level keys are the same - assert set(parsed.keys()) == set( - search.keys() - ), f"Parsed result keys are not as expected. Difference: {dict_diff(parsed, search)}" + assert set(parsed.keys()) == set(search.keys()), ( + f"Parsed result keys are not as expected. Difference: {dict_diff(parsed, search)}" + ) # compare the first document (parsed.items[0]), assert that all of the keys in expected search (search.items[0]) for key in search["items"][0].keys(): assert key in parsed["items"][0], f"Key {key} not found in parsed result." @@ -77,9 +77,9 @@ def test_parse_autocomplete(autocomplete_response, autocomplete): solr_response = SolrQueryResult(**autocomplete_response) parsed = parse_autocomplete(solr_response).model_dump() # assert that top level keys are the same - assert set(parsed.keys()) == set( - autocomplete.keys() - ), f"Parsed result keys are not as expected. Difference: {dict_diff(parsed, autocomplete)}" + assert set(parsed.keys()) == set(autocomplete.keys()), ( + f"Parsed result keys are not as expected. Difference: {dict_diff(parsed, autocomplete)}" + ) # compare the first document (parsed.items[0]), assert that all of the keys in expected autocomplete (autocomplete.items[0]) for key in autocomplete["items"][0].keys(): assert key in parsed["items"][0], f"Key {key} not found in parsed result." diff --git a/backend/tests/unit/test_solr_queries.py b/backend/tests/unit/test_solr_queries.py index 7c42055aa..c2c5e3d14 100644 --- a/backend/tests/unit/test_solr_queries.py +++ b/backend/tests/unit/test_solr_queries.py @@ -72,9 +72,9 @@ def test_build_association_multiple_predicates(): ) assert len(query.filter_queries) > 0, "filter_queries is empty" predicate_filter = [fq for fq in query.filter_queries if fq.startswith("predicate:")][0] - assert ( - predicate_filter == "predicate:biolink\\:has_phenotype OR predicate:biolink\\:expressed_in" - ), "multiple predicate filter is not as expected" + assert predicate_filter == "predicate:biolink\\:has_phenotype OR predicate:biolink\\:expressed_in", ( + "multiple predicate filter is not as expected" + ) def test_build_association_multiple_entites():