summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yml5
-rw-r--r--.gitignore103
-rw-r--r--pyproject.toml1
-rw-r--r--src/lib.rs19
-rw-r--r--tests/test_engine.py10
5 files changed, 33 insertions, 105 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a5c429c..18cdc06 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -72,6 +72,9 @@ jobs:
72 - name: Build Python package 72 - name: Build Python package
73 run: poetry run maturin develop --release 73 run: poetry run maturin develop --release
74 74
75 - name: Run Python tests
76 run: poetry run pytest -vv --color=yes
77
75 python-publish: 78 python-publish:
76 needs: build 79 needs: build
77 runs-on: ${{ matrix.os }} 80 runs-on: ${{ matrix.os }}
@@ -162,4 +165,4 @@ jobs:
162 uses: peaceiris/actions-gh-pages@v3 165 uses: peaceiris/actions-gh-pages@v3
163 with: 166 with:
164 github_token: ${{ secrets.GITHUB_TOKEN }} 167 github_token: ${{ secrets.GITHUB_TOKEN }}
165 publish_dir: ./target/github-pages \ No newline at end of file 168 publish_dir: ./target/github-pages
diff --git a/.gitignore b/.gitignore
index 12a4447..7683933 100644
--- a/.gitignore
+++ b/.gitignore
@@ -95,17 +95,12 @@ tags
95# End of https://www.gitignore.io/api/vim,emacs,visualstudiocode 95# End of https://www.gitignore.io/api/vim,emacs,visualstudiocode
96 96
97# -- Python -- 97# -- Python --
98# Python virtual environment
99.env
100 98
101# Byte-compiled / optimized / DLL files 99# Byte-compiled / optimized / DLL files
102__pycache__/ 100__pycache__/
103*.py[cod] 101*.py[cod]
104*$py.class 102*$py.class
105 103
106# C extensions
107*.so
108
109# Distribution / packaging 104# Distribution / packaging
110.Python 105.Python
111build/ 106build/
@@ -127,93 +122,9 @@ share/python-wheels/
127*.egg 122*.egg
128MANIFEST 123MANIFEST
129 124
130# PyInstaller
131# Usually these files are written by a python script from a template
132# before PyInstaller builds the exe, so as to inject date/other infos into it.
133*.manifest
134*.spec
135
136# Installer logs
137pip-log.txt
138pip-delete-this-directory.txt
139
140# Unit test / coverage reports
141htmlcov/
142.tox/
143.nox/
144.coverage
145.coverage.*
146.cache
147nosetests.xml
148coverage.xml
149*.cover
150*.py,cover
151.hypothesis/
152.pytest_cache/
153cover/
154
155# Translations
156*.mo
157*.pot
158
159# Django stuff:
160*.log
161local_settings.py
162db.sqlite3
163db.sqlite3-journal
164
165# Flask stuff:
166instance/
167.webassets-cache
168
169# Scrapy stuff:
170.scrapy
171
172# Sphinx documentation
173docs/_build/
174
175# PyBuilder
176.pybuilder/
177target/
178
179# Jupyter Notebook
180.ipynb_checkpoints
181
182# IPython
183profile_default/
184ipython_config.py
185
186# pyenv
187# For a library or package, you might want to ignore these files since the code is
188# intended to run in multiple environments; otherwise, check them in:
189# .python-version
190
191# pipenv
192# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
193# However, in case of collaboration, if having platform-specific dependencies or dependencies
194# having no cross-platform support, pipenv may install dependencies that don't work, or not
195# install all needed dependencies.
196#Pipfile.lock
197
198# PEP 582; used by e.g. github.com/David-OConnor/pyflow 125# PEP 582; used by e.g. github.com/David-OConnor/pyflow
199__pypackages__/ 126__pypackages__/
200 127
201# Celery stuff
202celerybeat-schedule
203celerybeat.pid
204
205# SageMath parsed files
206*.sage.py
207
208# Environments
209.env
210.venv
211env/
212venv/
213ENV/
214env.bak/
215venv.bak/
216
217# Spyder project settings 128# Spyder project settings
218.spyderproject 129.spyderproject
219.spyproject 130.spyproject
@@ -221,20 +132,10 @@ venv.bak/
221# Rope project settings 132# Rope project settings
222.ropeproject 133.ropeproject
223 134
224# mkdocs documentation
225/site
226
227# mypy 135# mypy
228.mypy_cache/ 136.mypy_cache/
229.dmypy.json 137.dmypy.json
230dmypy.json 138dmypy.json
231 139
232# Pyre type checker 140# poetry
233.pyre/ 141poetry.lock
234
235# pytype static type analyzer
236.pytype/
237
238# Cython debug symbols
239cython_debug/
240
diff --git a/pyproject.toml b/pyproject.toml
index 530fc34..61530aa 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -13,3 +13,4 @@ python = "^3.5"
13 13
14[tool.poetry.dev-dependencies] 14[tool.poetry.dev-dependencies]
15maturin = "*" 15maturin = "*"
16pytest = "*"
diff --git a/src/lib.rs b/src/lib.rs
index 49f4ba2..bbaa08c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -230,7 +230,7 @@ impl PyObjectProtocol for HostnameSpecificResources {
230/// 230///
231/// [1]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/ResourceType 231/// [1]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/ResourceType
232#[pyclass] 232#[pyclass]
233#[text_signature = "($self, network_filters)"] 233#[text_signature = "($self, network_filters=None, load_network=True, load_cosmetic=False, debug=False)"]
234pub struct Engine { 234pub struct Engine {
235 engine: RustEngine, 235 engine: RustEngine,
236} 236}
@@ -239,8 +239,21 @@ pub struct Engine {
239impl Engine { 239impl Engine {
240 /// Create a new adblocking engine 240 /// Create a new adblocking engine
241 #[new] 241 #[new]
242 pub fn from_rules(network_filters: Vec<String>) -> Self { 242 #[args(network_filters="None", load_network=true, load_cosmetic=false, debug=false)]
243 let engine = RustEngine::from_rules(&network_filters); 243 pub fn new(
244 network_filters: Option<Vec<String>>,
245 load_network: bool,
246 load_cosmetic: bool,
247 debug: bool,
248 ) -> Self {
249 let filters = network_filters.unwrap_or(Vec::new());
250 let engine = RustEngine::from_rules_parametrised(
251 &filters,
252 load_network,
253 load_cosmetic,
254 debug,
255 true,
256 );
244 Self { engine } 257 Self { engine }
245 } 258 }
246 259
diff --git a/tests/test_engine.py b/tests/test_engine.py
new file mode 100644
index 0000000..602d794
--- /dev/null
+++ b/tests/test_engine.py
@@ -0,0 +1,10 @@
1import adblock
2
3def test_engine_arguments():
4 # None of these should panic
5 adblock.Engine()
6 adblock.Engine([])
7 adblock.Engine(network_filters=None)
8 adblock.Engine(network_filters=[])
9 adblock.Engine(load_network=False, load_cosmetic=True, debug=False)
10 adblock.Engine(debug=True)