Skip to content

Commit 64a927c

Browse files
author
Gerit Wagner
committed
drop linter mode
1 parent 7195ac2 commit 64a927c

File tree

16 files changed

+45
-148
lines changed

16 files changed

+45
-148
lines changed

docs/source/dev_docs/_autosummary/search_query.constants.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ search\_query.constants
2020
Colors
2121
ExitCodes
2222
Fields
23-
LinterMode
2423
ListToken
2524
ListTokenTypes
2625
OperatorNodeTokenTypes

docs/source/dev_docs/linter_development.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,3 @@ Best Practices
3232

3333
.. literalinclude:: linter_skeleton.py
3434
:language: python
35-
36-
37-
Strict vs. Non-Strict Mode
38-
---------------------------
39-
40-
In non-strict mode (`mode="lenient"`), linters report errors but do not raise exceptions.
41-
In strict mode (`mode="strict"`), any linter message will cause an exception to be raised,
42-
which can be used for automated pipelines or validation gates.

docs/source/dev_docs/parser_skeleton.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class CustomParser(QueryStringParser):
88
[PARENTHESIS_REGEX, LOGIC_OPERATOR_REGEX, FIELD_REGEX, TERM_REGEX]
99
)
1010

11-
def __init__(self, query_str, *, field_general="", mode=LinterMode.STRICT):
12-
super().__init__(query_str, field_general=field_general, mode=mode)
11+
def __init__(self, query_str, *, field_general=""):
12+
super().__init__(query_str, field_general=field_general)
1313
self.linter = CustomLinter(self)
1414

1515
def tokenize(self):

docs/source/index.rst

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
onclick="window.open('https://github.com/CoLRev-Environment/search-query/releases/')">
1818
</div>
1919

20-
..
21-
<img src="https://mybinder.org/badge_logo.svg" alt="Binder"
22-
onclick="window.open('https://mybinder.org/v2/gh/CoLRev-Environment/search-query/HEAD?labpath=docs%2Fsource%2Fdemo.ipynb')">
23-
2420
**Search Query** is a Python package designed to **load**, **lint**, **translate**, **save**, **improve**, and **automate** academic literature search queries.
2521
It is extensible and currently supports PubMed, EBSCOHost, and Web of Science.
2622
The package can be used programmatically, through the command line, or as a pre-commit hook.
@@ -51,13 +47,6 @@ Creating a query programmatically is simple:
5147
work_synonyms = OrQuery(["work", "labor", "service"], field="abstract")
5248
query = AndQuery([digital_synonyms, work_synonyms])
5349
54-
..
55-
Parameters:
56-
57-
- list of strings or queries: strings that you want to include in the search query,
58-
- ``field``: search field to which the query should be applied (available options: TODO — provide examples and link to docs)
59-
Search strings can be either in string or list format.
60-
6150
We can also parse a query from a string or a `JSON search file <#json-search-files>`_ (see the :doc:`overview of platform identifiers </platforms/platform_index>`):
6251

6352
.. code-block:: python
@@ -97,27 +86,6 @@ Note how the syntax is translated and how the search for :literal:`Title/Abstrac
9786
# Output:
9887
# ((AB="digital health" OR TI="digital health") AND (AB="privacy" OR TI="privacy"))
9988
100-
101-
..
102-
Beyond the instructive error message, additional information on the specific messages is available `here <messages/errors_index.html>`_.
103-
104-
Each query parser has a corresponding linter that checks for errors and warnings in the query.
105-
To validate a JSON query file, run the linter:
106-
107-
.. code-block:: python
108-
109-
from search_query.linter import run_linter
110-
111-
messages = run_linter(search.search_string, platform=search.platform)
112-
print(messages)
113-
114-
There are two modes:
115-
116-
- **Strict mode**: Forces the user to maintain clean, valid input but at the cost of convenience. This mode fails on fatal or error outcomes and prints warnings.
117-
- **Non-strict mode**: Focuses on usability, automatically resolving common issues while maintaining transparency via warnings. This mode fails only on fatal outcomes. Auto-corrects errors as much as possible and prints a message (adds a fatal message if this is not possible). Prints warnings.
118-
119-
An additional "silent" option may be used to silence warnings.
120-
12189
Demo
12290
============
12391

@@ -134,13 +102,6 @@ Below is a high-level overview of the core functionalities:
134102

135103
.. image:: presentation.png
136104

137-
..
138-
Parser development
139-
-------------------------
140-
141-
To develop a parser, see `dev-parser <dev_docs/parser.html>`_ docs.
142-
143-
144105
.. toctree::
145106
:hidden:
146107
:maxdepth: 3

search_query/constants.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,6 @@ class Colors:
195195
END = "\033[0m"
196196

197197

198-
class LinterMode:
199-
"""Linter mode"""
200-
201-
STRICT = "strict"
202-
NONSTRICT = "non-strict"
203-
204-
205198
class QueryErrorCode(Enum):
206199
"""Error codes for the query parser"""
207200

search_query/ebsco/parser.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import re
66
import typing
77

8-
from search_query.constants import LinterMode
98
from search_query.constants import PLATFORM
109
from search_query.constants import Token
1110
from search_query.constants import TokenTypes
@@ -53,7 +52,6 @@ def __init__(
5352
query_str: str,
5453
*,
5554
field_general: str = "",
56-
mode: str = LinterMode.STRICT,
5755
offset: typing.Optional[dict] = None,
5856
original_str: typing.Optional[str] = None,
5957
silent: bool = False,
@@ -62,7 +60,6 @@ def __init__(
6260
super().__init__(
6361
query_str,
6462
field_general=field_general,
65-
mode=mode,
6663
offset=offset,
6764
original_str=original_str,
6865
)
@@ -413,13 +410,11 @@ def __init__(
413410
self,
414411
query_list: str,
415412
field_general: str = "",
416-
mode: str = LinterMode.NONSTRICT,
417413
) -> None:
418414
super().__init__(
419415
query_list=query_list,
420416
parser_class=EBSCOParser,
421417
field_general=field_general,
422-
mode=mode,
423418
)
424419
self.linter = EBSCOListLinter(parser=self, string_parser_class=EBSCOParser)
425420

@@ -440,7 +435,6 @@ def parse(self) -> Query:
440435
query_str=query_str,
441436
original_str=self.query_list,
442437
field_general=self.field_general,
443-
mode=self.mode,
444438
offset=offset,
445439
silent=True,
446440
)

search_query/linter_base.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ def check_status(self) -> None:
155155
self.print_messages()
156156

157157
if self.has_fatal_errors():
158-
# OR any (code.is_error() for code in messages)
159-
# and self.parser.mode == "strict":
160158
raise QuerySyntaxError(self)
161159

162160
def has_fatal_errors(self) -> bool:
@@ -413,7 +411,7 @@ def check_boolean_operator_readability(
413411
for token in self.tokens:
414412
if token.type == TokenTypes.LOGIC_OPERATOR:
415413
if token.value in faulty_operators:
416-
details = f"Please use AND, OR, NOT instead of {faulty_operators}"
414+
details = f"Use AND, OR, NOT instead of {faulty_operators}"
417415
self.add_message(
418416
QueryErrorCode.BOOLEAN_OPERATOR_READABILITY,
419417
positions=[token.position],
@@ -956,10 +954,7 @@ def _check_date_filters_in_subquery(self, query: Query, level: int = 0) -> None:
956954

957955
generic_fields = self.syntax_str_to_generic_field_set(query.field.value)
958956
if generic_fields & {Fields.YEAR_PUBLICATION}:
959-
details = (
960-
"Please double-check whether date filters "
961-
"should apply to the entire query."
962-
)
957+
details = "Check whether date filters should apply to the entire query."
963958
positions = [(-1, -1)]
964959
if query.position and query.position is not None:
965960
positions = [query.position]
@@ -997,7 +992,7 @@ def _check_journal_filters_in_subquery(self, query: Query, level: int = 0) -> No
997992
generic_fields = self.syntax_str_to_generic_field_set(query.field.value)
998993
if generic_fields & {Fields.JOURNAL, Fields.PUBLICATION_NAME}:
999994
details = (
1000-
"Please double-check whether journal/publication-name filters "
995+
"Check whether journal/publication-name filters "
1001996
f"({query.field.value}) should apply to the entire query."
1002997
)
1003998
self.add_message(
@@ -1285,8 +1280,6 @@ def check_status(self) -> None:
12851280
self.print_messages()
12861281

12871282
if self.has_fatal_errors():
1288-
# OR any (code.is_error() for code in messages)
1289-
# and self.parser.mode == "strict":
12901283
raise ListQuerySyntaxError(self)
12911284

12921285

search_query/parser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sys
66
import typing
77

8-
from search_query.constants import LinterMode
98
from search_query.constants import PLATFORM
109
from search_query.ebsco.parser import EBSCOListParser
1110
from search_query.ebsco.parser import EBSCOParser
@@ -38,7 +37,6 @@ def parse(
3837
*,
3938
field_general: str = "",
4039
platform: str = PLATFORM.WOS.value,
41-
mode: str = LinterMode.STRICT,
4240
) -> Query:
4341
"""Parse a query string."""
4442
platform = get_platform(platform)
@@ -51,7 +49,6 @@ def parse(
5149
query = LIST_PARSERS[platform]( # type: ignore
5250
query_list=query_str,
5351
field_general=field_general,
54-
mode=mode,
5552
).parse()
5653
except Exception: # pylint: disable=broad-except
5754
sys.exit(1)
@@ -63,7 +60,7 @@ def parse(
6360
parser_class = PARSERS[platform]
6461
try:
6562
query = parser_class(
66-
query_str, field_general=field_general, mode=mode
63+
query_str, field_general=field_general
6764
).parse() # type: ignore
6865
except Exception: # pylint: disable=broad-except
6966
sys.exit(1)

search_query/parser_base.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from abc import abstractmethod
99

1010
from search_query.constants import GENERAL_ERROR_POSITION
11-
from search_query.constants import LinterMode
1211
from search_query.constants import ListToken
1312
from search_query.constants import ListTokenTypes
1413
from search_query.constants import OperatorNodeTokenTypes
@@ -35,14 +34,12 @@ def __init__(
3534
query_str: str,
3635
*,
3736
field_general: str = "",
38-
mode: str = LinterMode.STRICT,
3937
offset: typing.Optional[dict] = None,
4038
original_str: typing.Optional[str] = None,
4139
silent: bool = False,
4240
) -> None:
4341
self.query_str = query_str
4442
self.tokens: list = []
45-
self.mode = mode
4643
# The external fields (in the JSON file: "field")
4744
self.field_general = field_general
4845
self.silent = silent
@@ -213,14 +210,12 @@ def __init__(
213210
*,
214211
parser_class: type[QueryStringParser],
215212
field_general: str,
216-
mode: str = LinterMode.STRICT,
217213
) -> None:
218214
# Remove leading whitespaces/newlines from the query_list
219215
# to ensure correct token positions
220216
self.query_list = query_list.lstrip()
221217
self.parser_class = parser_class
222218
self.field_general = field_general
223-
self.mode = mode
224219
self.query_dict: dict = {}
225220

226221
def tokenize_list(self) -> None:

search_query/pubmed/parser.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import re
44
import typing
55

6-
from search_query.constants import LinterMode
76
from search_query.constants import Operators
87
from search_query.constants import PLATFORM
98
from search_query.constants import Token
@@ -48,7 +47,6 @@ def __init__(
4847
query_str: str,
4948
*,
5049
field_general: str = "",
51-
mode: str = LinterMode.NONSTRICT,
5250
offset: typing.Optional[dict] = None,
5351
original_str: typing.Optional[str] = None,
5452
silent: bool = False,
@@ -57,7 +55,6 @@ def __init__(
5755
super().__init__(
5856
query_str=query_str,
5957
field_general=field_general,
60-
mode=mode,
6158
offset=offset,
6259
original_str=original_str,
6360
)
@@ -298,13 +295,11 @@ def __init__(
298295
query_list: str,
299296
*,
300297
field_general: str = "",
301-
mode: str = LinterMode.NONSTRICT,
302298
) -> None:
303299
super().__init__(
304300
query_list,
305301
parser_class=PubmedParser,
306302
field_general=field_general,
307-
mode=mode,
308303
)
309304
self.linter = PubmedQueryListLinter(self, PubmedParser)
310305

@@ -321,7 +316,6 @@ def parse(self) -> Query:
321316
query_str=query_str,
322317
original_str=self.query_list,
323318
field_general=self.field_general,
324-
mode=self.mode,
325319
offset=offset,
326320
silent=True,
327321
)

0 commit comments

Comments
 (0)