Skip to content

Commit

Permalink
ci: Fix invalid escape sequences in Python code (#5802)
Browse files Browse the repository at this point in the history
* ci: Use ruff in pre-commit to further limit complexity

* Fix invalid escape sequences in Python code

* Delete releasenotes/notes/ruff-4d2504d362035166.yaml
  • Loading branch information
cclauss committed Sep 14, 2023
1 parent 6fc12a2 commit 9405eb9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
32 changes: 26 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,38 @@ plugins = [
]

[tool.ruff]
select = [
"AIR", # Airflow
"ASYNC", # flake8-async
"C90", # McCabe cyclomatic complexity
"CPY", # flake8-copyright
"DJ", # flake8-django
"E501", # Long lines
"EXE", # flake8-executable
"FURB", # refurb
"INT", # flake8-gettext
"PL", # Pylint
"Q", # flake8-quotes
"SLOT", # flake8-slots
"T10", # flake8-debugger
"W", # pycodestyle
"YTT", # flake8-2020
# "E", # pycodestyle
# "F", # Pyflakes
# "NPY", # NumPy-specific rules
# "PD", # pandas-vet
# "PERF", # Perflint
# "PT", # flake8-pytest-style
# "UP", # pyupgrade
]
line-length = 1486
target-version = "py38"
ignore = [
"PLR1714", # repeated-equality-comparison
"PLR5501", # collapsible-else-if
"PLW0603", # global-statement
"PLW1510", # subprocess-run-without-check
"PLW2901", # redefined-loop-name
"W605", # invalid-escape-sequence
]
select = [
"C90", # McCabe cyclomatic complexity
"PL", # Pylint
"W", # Pycodestyle warnings
]

[tool.ruff.mccabe]
Expand Down
4 changes: 2 additions & 2 deletions test/document_stores/test_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def test__validate_and_adjust_document_index_but_no_method(self, mocked_document
assert mocked_document_store.space_type == "innerproduct"
with pytest.raises(
DocumentStoreError,
match=f"Set `similarity` to one of '\['l2'\]' to properly use the embedding field 'embedding' of index '{self.index_name}'. Similarity 'dot_product' is not compatible with embedding field's space type 'l2', it requires 'innerproduct'.",
match=rf"Set `similarity` to one of '\['l2'\]' to properly use the embedding field 'embedding' of index '{self.index_name}'. Similarity 'dot_product' is not compatible with embedding field's space type 'l2', it requires 'innerproduct'.",
):
mocked_document_store._validate_and_adjust_document_index(self.index_name)

Expand All @@ -597,7 +597,7 @@ def test__validate_and_adjust_document_index_similarity_mismatch(self, mocked_do

with pytest.raises(
DocumentStoreError,
match=f"Set `similarity` to one of '\['dot_product'\]' to properly use the embedding field 'embedding' of index '{self.index_name}'. Similarity 'dot_product' is not compatible with embedding field's space type 'innerproduct', it requires 'cosinesimil'.",
match=rf"Set `similarity` to one of '\['dot_product'\]' to properly use the embedding field 'embedding' of index '{self.index_name}'. Similarity 'dot_product' is not compatible with embedding field's space type 'innerproduct', it requires 'cosinesimil'.",
):
mocked_document_store._validate_and_adjust_document_index(self.index_name)

Expand Down
16 changes: 8 additions & 8 deletions test/document_stores/test_pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def test_get_all_documents_extended_filter_compound_dates_and_other_field_explic
}
}

with pytest.raises(FilterError, match="Comparison value for '\$[l|g]te' operation must be a float or int."):
with pytest.raises(FilterError, match=r"Comparison value for '\$[l|g]te' operation must be a float or int."):
doc_store_with_docs.get_all_documents(filters=filters)

@pytest.mark.integration
Expand All @@ -343,7 +343,7 @@ def test_get_all_documents_extended_filter_compound_dates_and_other_field_simpli
"name": ["file_5.txt", "file_3.txt"],
}

with pytest.raises(FilterError, match="Comparison value for '\$[l|g]te' operation must be a float or int."):
with pytest.raises(FilterError, match=r"Comparison value for '\$[l|g]te' operation must be a float or int."):
doc_store_with_docs.get_all_documents(filters=filters_simplified)

@pytest.mark.integration
Expand All @@ -357,7 +357,7 @@ def test_get_all_documents_extended_filter_compound_dates_and_or_explicit(
}
}

with pytest.raises(FilterError, match="Comparison value for '\$[l|g]te' operation must be a float or int."):
with pytest.raises(FilterError, match=r"Comparison value for '\$[l|g]te' operation must be a float or int."):
doc_store_with_docs.get_all_documents(filters=filters)

@pytest.mark.integration
Expand All @@ -369,7 +369,7 @@ def test_get_all_documents_extended_filter_compound_dates_and_or_simplified(
"$or": {"name": ["file_5.txt", "file_3.txt"], "numeric_field": {"$lte": 5.0}},
}

with pytest.raises(FilterError, match="Comparison value for '\$[l|g]te' operation must be a float or int."):
with pytest.raises(FilterError, match=r"Comparison value for '\$[l|g]te' operation must be a float or int."):
doc_store_with_docs.get_all_documents(filters=filters_simplified)

@pytest.mark.integration
Expand All @@ -385,7 +385,7 @@ def test_get_all_documents_extended_filter_compound_dates_and_or_and_not_explici
},
}
}
with pytest.raises(FilterError, match="Comparison value for '\$[l|g]te' operation must be a float or int."):
with pytest.raises(FilterError, match=r"Comparison value for '\$[l|g]te' operation must be a float or int."):
doc_store_with_docs.get_all_documents(filters=filters)

@pytest.mark.integration
Expand All @@ -399,7 +399,7 @@ def test_get_all_documents_extended_filter_compound_dates_and_or_and_not_simplif
"$and": {"numeric_field": {"$lte": 5.0}, "$not": {"meta_field": "test-2"}},
},
}
with pytest.raises(FilterError, match="Comparison value for '\$[l|g]te' operation must be a float or int."):
with pytest.raises(FilterError, match=r"Comparison value for '\$[l|g]te' operation must be a float or int."):
doc_store_with_docs.get_all_documents(filters=filters_simplified)

@pytest.mark.integration
Expand All @@ -413,7 +413,7 @@ def test_get_all_documents_extended_filter_compound_nested_not(self, doc_store_w
}
}
}
with pytest.raises(FilterError, match="Comparison value for '\$[l|g]t' operation must be a float or int."):
with pytest.raises(FilterError, match=r"Comparison value for '\$[l|g]t' operation must be a float or int."):
doc_store_with_docs.get_all_documents(filters=filters)

@pytest.mark.integration
Expand All @@ -428,7 +428,7 @@ def test_get_all_documents_extended_filter_compound_same_level_not(
]
}

with pytest.raises(FilterError, match="Comparison value for '\$[l|g]te' operation must be a float or int."):
with pytest.raises(FilterError, match=r"Comparison value for '\$[l|g]te' operation must be a float or int."):
doc_store_with_docs.get_all_documents(filters=filters)

@pytest.mark.integration
Expand Down
2 changes: 1 addition & 1 deletion test/nodes/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_openai_answer_generator_custom_template(haystack_openai_config, docs):

lfqa_prompt = PromptTemplate(
"""Synthesize a comprehensive answer from your knowledge and the following topk most relevant paragraphs and
the given question.\n===\Paragraphs: {context}\n===\n{query}"""
the given question.\n===\\Paragraphs: {context}\n===\n{query}"""
)
node = OpenAIAnswerGenerator(
api_key=haystack_openai_config["api_key"],
Expand Down
2 changes: 1 addition & 1 deletion test/nodes/test_image_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ def test_image_to_text_not_image_document(image_to_text):
def test_image_to_text_unsupported_model_after_loading():
with pytest.raises(
ValueError,
match="The model 'deepset/minilm-uncased-squad2' \(class 'BertForQuestionAnswering'\) is not supported for ImageToText",
match=r"The model 'deepset/minilm-uncased-squad2' \(class 'BertForQuestionAnswering'\) is not supported for ImageToText",
):
_ = TransformersImageToText(model_name_or_path="deepset/minilm-uncased-squad2")
2 changes: 1 addition & 1 deletion test/nodes/test_shaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def test_strings_to_answers_yaml(tmp_path):
def test_strings_to_answers_with_reference_meta_yaml(tmp_path):
with open(tmp_path / "tmp_config.yml", "w") as tmp_file:
tmp_file.write(
f"""
rf"""
version: ignore
components:
- name: shaper
Expand Down
2 changes: 1 addition & 1 deletion test/pipelines/test_pipeline_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ def run_batch(self):

with open(tmp_path / "tmp_config.yml", "w", encoding="utf-8") as tmp_file:
tmp_file.write(
f"""
rf"""
version: '1.9.0'
components:
Expand Down

0 comments on commit 9405eb9

Please sign in to comment.