Skip to content

Commit 0d91968

Browse files
Merge branch 'develop'
2 parents f6da05b + 8f0aaa8 commit 0d91968

34 files changed

Lines changed: 164 additions & 192 deletions

.github/workflows/python-package.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip
29-
pip install flake8 pytest
30-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
29+
pip install flake8 pytest mypy
30+
pip install -U .
3131
- name: Lint with flake8
3232
run: |
3333
# stop the build if there are Python syntax errors or undefined names
@@ -37,3 +37,6 @@ jobs:
3737
- name: Test with pytest
3838
run: |
3939
pytest
40+
- name: Test with mypy
41+
run: |
42+
mypy --strict sifter

setup.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
from setuptools import setup
3+
from setuptools import setup, find_packages
44

55
# read the contents of your README file
66
from os import path
@@ -41,18 +41,35 @@
4141
"Topic :: Software Development :: Interpreters",
4242
"Topic :: Software Development :: Libraries :: Python Modules",
4343
],
44-
packages=[
45-
"sifter",
46-
"sifter.commands",
47-
"sifter.comparators",
48-
"sifter.extensions",
49-
"sifter.grammar",
50-
"sifter.t",
51-
"sifter.tests",
52-
"sifter.validators",
53-
],
44+
packages=find_packages(exclude=("tests",)),
5445
package_data={
55-
"sifter": ['py.typed'],
56-
"sifter.t": ["*.in", "*.out", "*.msg", "*.rules"],
46+
"sifter": ['py.typed']
5747
},
48+
entry_points={
49+
'sifter_extensions': [
50+
# sifter commands
51+
'discard = sifter.commands.discard:CommandDiscard',
52+
'fileinto = sifter.commands.fileinto:CommandFileInto',
53+
'if = sifter.commands.if_cmd:CommandIf',
54+
'elseif = sifter.commands.if_cmd:CommandElsIf',
55+
'else = sifter.commands.if_cmd:CommandElse',
56+
'keep = sifter.commands.keep:CommandKeep',
57+
'redirect = sifter.commands.redirect:CommandRedirect',
58+
'require = sifter.commands.require:CommandRequire',
59+
'stop = sifter.commands.stop:CommandStop',
60+
# sifter tests
61+
'address = sifter.tests.address:TestAddress',
62+
'allof = sifter.tests.allof:TestAllOf',
63+
'anyof = sifter.tests.anyof:TestAnyOf',
64+
'exists = sifter.tests.exists:TestExists',
65+
'header = sifter.tests.header:TestHeader',
66+
'false = sifter.tests.false:TestFalse',
67+
'not_test = sifter.tests.not_test:TestNot',
68+
'size = sifter.tests.size:TestSize',
69+
'true = sifter.tests.true:TestTrue',
70+
# sifter comparators
71+
'ascii_casemap = sifter.comparators.ascii_casemap:ComparatorASCIICasemap',
72+
'octed = sifter.comparators.octet:ComparatorOctet'
73+
],
74+
}
5875
)

sifter/commands/discard.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,3 @@ class CommandDiscard(Command):
1616
def evaluate(self, message: Message, state: EvaluationState) -> Optional[Actions]:
1717
state.actions.cancel_implicit_keep()
1818
return None
19-
20-
21-
CommandDiscard.register()

sifter/commands/fileinto.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,3 @@ def evaluate(self, message: Message, state: EvaluationState) -> Optional[Actions
2222
state.actions.append('fileinto', file_dest) # type: ignore
2323
state.actions.cancel_implicit_keep()
2424
return None
25-
26-
27-
CommandFileInto.register()

sifter/commands/if_cmd.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ class CommandIf(CommandIfBase):
2828
RULE_IDENTIFIER = 'IF'
2929

3030

31-
CommandIf.register()
32-
33-
3431
class CommandElsIf(CommandIfBase):
3532

3633
RULE_IDENTIFIER = 'ELSIF'
@@ -41,9 +38,6 @@ def evaluate(self, message: Message, state: EvaluationState) -> Optional[Actions
4138
return super().evaluate(message, state)
4239

4340

44-
CommandElsIf.register()
45-
46-
4741
class CommandElse(Command):
4842

4943
RULE_IDENTIFIER = 'ELSE'
@@ -54,6 +48,3 @@ def evaluate(self, message: Message, state: EvaluationState) -> Optional[Actions
5448
if state.last_if:
5549
return None
5650
return self.block.evaluate(message, state)
57-
58-
59-
CommandElse.register()

sifter/commands/keep.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,3 @@ def evaluate(self, message: Message, state: EvaluationState) -> Optional[Actions
1818
state.actions.append('keep')
1919
state.actions.cancel_implicit_keep()
2020
return None
21-
22-
23-
CommandKeep.register()

sifter/commands/redirect.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,3 @@ def evaluate(self, message: Message, state: EvaluationState) -> Optional[Actions
5252
state.actions.append('redirect', self.email_address)
5353
state.actions.cancel_implicit_keep()
5454
return None
55-
56-
57-
CommandRedirect.register()

sifter/commands/require.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
)
66

77
from sifter.grammar.command import Command
8-
import sifter.grammar
9-
import sifter.handler
8+
from sifter.extensions import ExtensionRegistry
109
from sifter.validators.stringlist import StringList
1110
from sifter.grammar.state import EvaluationState
1211
from sifter.grammar.actions import Actions
@@ -21,13 +20,10 @@ class CommandRequire(Command):
2120
def evaluate(self, message: Message, state: EvaluationState) -> Optional[Actions]:
2221
ext_name_list = self.positional_args[0]
2322
for ext_name in ext_name_list: # type: ignore
24-
if not sifter.handler.get('extension', ext_name):
23+
if not ExtensionRegistry.has_extension(ext_name):
2524
raise RuntimeError(
2625
"Required extension '%s' not supported"
2726
% ext_name
2827
)
2928
state.require_extension(ext_name)
3029
return None
31-
32-
33-
CommandRequire.register()

sifter/commands/stop.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,3 @@ class CommandStop(Command):
1616
def evaluate(self, message: Message, state: EvaluationState) -> Optional[Actions]:
1717
state.actions.append('stop')
1818
return None
19-
20-
21-
CommandStop.register()

sifter/comparator.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@
44
Text,
55
Optional,
66
Tuple,
7-
Type,
87
Union
98
)
109

11-
import sifter.handler
10+
from sifter.extensions import ExtensionRegistry
1211

1312
if TYPE_CHECKING:
14-
from sifter.grammar.comparator import Comparator
1513
from sifter.grammar.tag import Tag
1614
from sifter.grammar.state import EvaluationState
1715

1816

19-
def register(comparator_name: Optional[Text], comparator_cls: Type['Comparator']) -> None:
20-
sifter.handler.register('comparator', comparator_name, comparator_cls)
21-
22-
2317
def get_match_fn(
2418
comparator: Optional[Union[Text, 'Tag']],
2519
match_type: Optional[Union[Text, 'Tag']]
@@ -37,7 +31,7 @@ def get_match_fn(
3731
match_type = 'IS'
3832

3933
# TODO: support wildcard matching in comparator names (RFC 4790)
40-
cmp_handler = sifter.handler.get('comparator', comparator)
34+
cmp_handler = ExtensionRegistry.get_comparator(comparator)
4135
if not cmp_handler:
4236
raise RuntimeError("Comparator not supported: %s" % comparator)
4337

0 commit comments

Comments
 (0)