python-adblock

Updated Brave adblock library for Python
Log | Files | Refs | README

commit 653221ca5463a4e785839bed6142dad04d6a6d6e
parent 04678357e0d95ba1569e65b7fc423c17f867a87f
Author: Árni Dagur <arni@dagur.eu>
Date:   Tue, 22 Sep 2020 16:35:15 +0000

Merge pull request #13 from ArniDagur/update-to-0.3.2

Update to 0.3.2
Diffstat:
M.github/workflows/ci.yml | 23+++++++++++++++++------
MCargo.toml | 4++--
Madblock/__init__.py | 5++++-
Mpyproject.toml | 2+-
Msrc/lib.rs | 2+-
Atests/test_imports.py | 34++++++++++++++++++++++++++++++++++
6 files changed, 59 insertions(+), 11 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.5, 3.6, 3.7, 3.8] + python-version: [3.5, 3.6, 3.7, 3.8, 3.9] os: [ubuntu-latest, macos-latest, windows-latest] exclude: # There is a known issue where Python C extensions @@ -53,11 +53,16 @@ jobs: - name: Checkout uses: actions/checkout@v1 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + - uses: actions/setup-python@v2 + if: matrix.python-version != 3.9 with: python-version: ${{ matrix.python-version }} + - uses: actions/setup-python@v2 + if: matrix.python-version == 3.9 + with: + python-version: '3.9.0-alpha - 3.9.0' + - name: Install dependencies run: | python -m pip install --upgrade pip @@ -86,7 +91,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.5, 3.6, 3.7, 3.8] + python-version: [3.5, 3.6, 3.7, 3.8, 3.9] os: [ubuntu-latest, macos-latest, windows-latest] exclude: # There is a known issue where Python C extensions @@ -98,10 +103,16 @@ jobs: steps: - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 + - uses: actions/setup-python@v2 + if: matrix.python-version != 3.9 with: python-version: ${{ matrix.python-version }} + - uses: actions/setup-python@v2 + if: matrix.python-version == 3.9 + with: + python-version: '3.9.0-alpha - 3.9.0' + - name: Install latest nightly uses: actions-rs/toolchain@v1 with: @@ -150,7 +161,7 @@ jobs: docs-publish: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/master' && github.event.action == 'push' steps: - uses: actions/checkout@v2 with: diff --git a/Cargo.toml b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "adblock" publish = false -version = "0.3.1" +version = "0.3.2" authors = ["Árni Dagur <arni@dagur.eu"] edition = "2018" license = "MIT OR Apache-2.0" @@ -11,7 +11,7 @@ debug = true [dependencies] adblock = { version = "0.3.2", default-features = false, features = ["full-regex-handling", "embedded-domain-resolver"] } -pyo3 = "0.11" +pyo3 = "0.12" [lib] name = "adblock" diff --git a/adblock/__init__.py b/adblock/__init__.py @@ -1 +1,4 @@ -from .adblock import * +from .adblock import __version__, Engine, FilterSet, BlockerResult, UrlSpecificResources + + +__all__ = ("Engine", "FilterSet", "BlockerResult", "UrlSpecificResources") diff --git a/pyproject.toml b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "adblock" -version = "0.3.1" +version = "0.3.2" description = "Brave's adblocking in Python" authors = ["Árni Dagur <arni@dagur.eu>"] license = "MIT OR Apache-2.0" diff --git a/src/lib.rs b/src/lib.rs @@ -17,7 +17,7 @@ use adblock::engine::Engine as RustEngine; use adblock::lists::FilterFormat; use adblock::lists::FilterSet as RustFilterSet; use pyo3::class::PyObjectProtocol; -use pyo3::exceptions::ValueError as PyValueError; +use pyo3::exceptions::PyValueError; use pyo3::prelude::*; use pyo3::types::PyBytes; use pyo3::PyErr; diff --git a/tests/test_imports.py b/tests/test_imports.py @@ -0,0 +1,34 @@ +import re +import adblock + + +def get_added_classes(): + """ + Try to get the names of all classes that we added to the Python module + from Rust. As always, we unfortunately don't have access to the Rust AST + so we have to make do with regular expressions. + """ + classes = [] + with open("src/lib.rs", "r", encoding="utf-8") as rs_f: + for line in rs_f: + match = re.match(r"m\.add_class::<(.+)>\(\)\?;", line.strip()) + if match is not None: + classes.append(match.group(1)) + return classes + + +def test_added_classes(): + """ + Make sure that there's no class that we added in Rust but didn't import in + `__init__.py` and vice versa. + """ + added_classes = get_added_classes() + assert added_classes == list(adblock.__all__) + + +def test_dunder_all_classes_imported(): + """ + Make sure that there's no class in `__all__` that we haven't imported. + """ + for c in adblock.__all__: + assert hasattr(adblock, c)