Skip to content

Commit a9eafbf

Browse files
committed
fix: patching the local server options (disabledRuleIds, blockedReferrers, pipelineCaching, premiumOnly and pipelinePrewarming wasn't working) and removing deprecated options
1 parent 6aef1c6 commit a9eafbf

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

language_tool_python/config_file.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import tempfile
66

77
ALLOWED_CONFIG_KEYS = {
8-
'maxTextLength', 'maxTextHardLength', 'secretTokenKey', 'maxCheckTimeMillis', 'maxErrorsPerWordRate',
9-
'maxSpellingSuggestions', 'maxCheckThreads', 'cacheSize', 'cacheTTLSeconds', 'cacheSize', 'requestLimit',
8+
'maxTextLength', 'maxTextHardLength', 'maxCheckTimeMillis', 'maxErrorsPerWordRate',
9+
'maxSpellingSuggestions', 'maxCheckThreads', 'cacheSize', 'cacheTTLSeconds', 'requestLimit',
1010
'requestLimitInBytes', 'timeoutRequestLimit', 'requestLimitPeriodInSeconds', 'languageModel',
11-
'word2vecModel', 'fasttextModel', 'fasttextBinary', 'maxWorkQueueSize', 'rulesFile', 'warmUp',
11+
'fasttextModel', 'fasttextBinary', 'maxWorkQueueSize', 'rulesFile',
1212
'blockedReferrers', 'premiumOnly', 'disabledRuleIds', 'pipelineCaching', 'maxPipelinePoolSize',
13-
'pipelineCaching', 'pipelineExpireTimeInSeconds', 'pipelinePrewarming'
13+
'pipelineExpireTimeInSeconds', 'pipelinePrewarming'
1414
}
1515
class LanguageToolConfig:
1616
config: Dict[str, Any]
@@ -19,6 +19,15 @@ def __init__(self, config: Dict[str, Any]):
1919
assert set(config.keys()) <= ALLOWED_CONFIG_KEYS, f"unexpected keys in config: {set(config.keys()) - ALLOWED_CONFIG_KEYS}"
2020
assert len(config), "config cannot be empty"
2121
self.config = config
22+
23+
if 'disabledRuleIds' in self.config:
24+
self.config['disabledRuleIds'] = ','.join(self.config['disabledRuleIds'])
25+
if 'blockedReferrers' in self.config:
26+
self.config['blockedReferrers'] = ','.join(self.config['blockedReferrers'])
27+
for key in ["pipelineCaching", "premiumOnly", "pipelinePrewarming"]:
28+
if key in self.config:
29+
self.config[key] = str(bool(self.config[key])).lower()
30+
2231
self.path = self._create_temp_file()
2332

2433
def _create_temp_file(self) -> str:

tests/test_major_functionality.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ def test_session_only_new_spellings():
255255
assert initial_checksum.hexdigest() == subsequent_checksum.hexdigest()
256256

257257

258+
def test_disabled_rule_in_config():
259+
import language_tool_python
260+
GRAMMAR_TOOL_CONFIG = {
261+
'disabledRuleIds': ['MORFOLOGIK_RULE_EN_US']
262+
}
263+
with language_tool_python.LanguageTool('en-US', config=GRAMMAR_TOOL_CONFIG) as tool:
264+
text = "He realised that the organization was in jeopardy."
265+
matches = tool.check(text)
266+
assert len(matches) == 0
267+
268+
258269
def test_debug_mode():
259270
from language_tool_python.server import DEBUG_MODE
260271
assert DEBUG_MODE is False

0 commit comments

Comments
 (0)