Skip to content

Commit b3c1087

Browse files
cleaned repo
1 parent 315277b commit b3c1087

8 files changed

Lines changed: 103 additions & 53 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
14
name: Python package
25

3-
on: [push]
6+
on:
7+
push:
8+
branches: [ master, develop ]
9+
pull_request:
10+
branches: [ master, develop ]
411

512
jobs:
613
build:
714

815
runs-on: ubuntu-latest
916
strategy:
1017
matrix:
11-
python-version: [3.5, 3.6, 3.7, 3.8]
18+
python-version: [3.6, 3.7, 3.8]
1219

1320
steps:
1421
- uses: actions/checkout@v2
@@ -19,9 +26,8 @@ jobs:
1926
- name: Install dependencies
2027
run: |
2128
python -m pip install --upgrade pip
22-
pip install flake8 pytest
23-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
24-
pip install -e .
29+
pip install flake8 pytest mypy
30+
pip install -U .
2531
- name: Lint with flake8
2632
run: |
2733
# stop the build if there are Python syntax errors or undefined names
@@ -31,3 +37,6 @@ jobs:
3137
- name: Test with pytest
3238
run: |
3339
pytest
40+
- name: Test with mypy
41+
run: |
42+
mypy --strict sifter
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflows will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Upload Python Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
deploy:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.x'
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install setuptools wheel twine
25+
- name: Build and publish
26+
env:
27+
TWINE_USERNAME: __token__
28+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29+
run: |
30+
python setup.py sdist bdist_wheel
31+
twine upload dist/*

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Sifter3 Extensions - unofficial extensions for Sifter 3
2+
3+
Sifter3 is a Python 3 implementation of the Sieve email filter language (RFC 5228)
4+
5+
![Python package](https://github.com/python-sifter/sifter3-extensions/workflows/Python%20package/badge.svg)
6+
[![CodeFactor](https://www.codefactor.io/repository/github/python-sifter/sifter3-extensions/badge)](https://www.codefactor.io/repository/github/python-sifter/sifter3-extensions)
7+
[![Github version](https://img.shields.io/github/v/release/python-sifter/sifter3-extensions?label=github&logo=github)](https://github.com/python-sifter/sifter3-extensions/releases)
8+
[![PyPI version](https://img.shields.io/pypi/v/sifter3-extensions.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/sifter3-extensions/)
9+
[![Supported Python versions](https://img.shields.io/pypi/pyversions/sifter3-extensions.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/sifter3-extensions/)
10+
[![PyPI downloads](https://pepy.tech/badge/sifter3-extensions/month)](https://pepy.tech/project/sifter3-extensions/month)
11+
[![GitHub](https://img.shields.io/github/license/python-sifter/sifter3-extensions.svg)](LICENSE)

README.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

setup.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@
4242
"Topic :: Software Development :: Interpreters",
4343
"Topic :: Software Development :: Libraries :: Python Modules",
4444
],
45-
packages=find_packages(exclude=("tests",))
45+
packages=find_packages(exclude=("tests",)),
46+
entry_points={
47+
'sifter_extensions': [
48+
# sifter commands
49+
'pipe = sifter_extensions.commands.pipe:CommandPipe',
50+
'rewrite = sifter_extensions.commands.rewrite:CommandRewrite'
51+
]
52+
}
4653
)

sifter_extensions/commands/pipe.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
import sifter.grammar
2-
import sifter.validators
1+
from email.message import Message
2+
from typing import (
3+
Text
4+
)
35

4-
__all__ = ('CommandPipe',)
6+
from sifter.grammar.command import Command
7+
from sifter.grammar.string import expand_variables
8+
from sifter.validators.stringlist import StringList
9+
from sifter.grammar.state import EvaluationState
510

6-
class CommandPipe(sifter.grammar.Command):
711

8-
RULE_IDENTIFIER = 'PIPE'
12+
class CommandPipe(Command):
913

10-
def __init__(self, arguments=None, tests=None, block=None):
11-
super(CommandPipe, self).__init__(arguments, tests, block)
12-
_, positional_args = self.validate_arguments(
13-
{},
14-
[ sifter.validators.StringList(length=1), ],
15-
)
16-
self.validate_tests_size(0)
17-
self.validate_block_size(0)
18-
self.pipe_dest = positional_args[0]
14+
HANDLER_ID: Text = 'PIPE'
15+
EXTENSION_NAME = 'pipe'
16+
POSITIONAL_ARGS = [StringList(length=1)]
1917

20-
def evaluate(self, message, state):
18+
def evaluate(self, message: Message, state: EvaluationState) -> None:
2119
state.check_required_extension('pipe', 'PIPE')
22-
pipe_dest = map(lambda s: sifter.grammar.string.expand_variables(s, state), self.pipe_dest)
23-
state.actions.append('pipe', pipe_dest)
20+
pipe_dest = self.positional_args[0]
21+
pipe_dest = map(lambda s: expand_variables(s, state), pipe_dest) # type: ignore
22+
state.actions.append('pipe', pipe_dest) # type: ignore
2423
state.actions.cancel_implicit_keep()
25-
26-
CommandPipe.register()
27-
Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
import sifter.grammar
2-
import sifter.validators
1+
from email.message import Message
2+
from typing import (
3+
Text
4+
)
35

4-
__all__ = ('CommandRewrite',)
6+
from sifter.grammar.string import expand_variables
7+
from sifter.grammar.command import Command
8+
from sifter.validators.stringlist import StringList
9+
from sifter.grammar.state import EvaluationState
510

6-
# section 4.1
7-
class CommandRewrite(sifter.grammar.Command):
811

9-
RULE_IDENTIFIER = 'REWRITE'
12+
class CommandRewrite(Command):
1013

11-
def __init__(self, arguments=None, tests=None, block=None):
12-
super(CommandRewrite, self).__init__(arguments, tests, block)
13-
_, positional_args = self.validate_arguments(
14-
{},
15-
[ sifter.validators.StringList(length=1),
16-
sifter.validators.StringList(length=1),
17-
],
18-
)
19-
self.validate_tests_size(0)
20-
self.validate_block_size(0)
21-
self.search = positional_args[0][0]
22-
self.replace = positional_args[1][0]
14+
HANDLER_ID: Text = 'REWRITE'
15+
EXTENSION_NAME = 'rewrite'
16+
POSITIONAL_ARGS = [
17+
StringList(length=1),
18+
StringList(length=1),
19+
]
2320

24-
def evaluate(self, message, state):
21+
def evaluate(self, message: Message, state: EvaluationState) -> None:
2522
state.check_required_extension('rewrite', 'REWRITE')
26-
search = sifter.grammar.string.expand_variables(self.search, state)
27-
replace = sifter.grammar.string.expand_variables(self.replace, state)
28-
state.actions.append('rewrite', (search, replace))
29-
30-
CommandRewrite.register()
23+
search = self.positional_args[0][0] # type: ignore
24+
replace = self.positional_args[1][0] # type: ignore
25+
search = expand_variables(search, state)
26+
replace = expand_variables(replace, state)
27+
state.actions.append('rewrite', (search, replace)) # type: ignore

tests/test_pipe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_evaulation():
2+
pass

0 commit comments

Comments
 (0)