diff options
| -rw-r--r-- | .github/workflows/ci.yml | 35 | ||||
| -rw-r--r-- | CHANGELOG.md | 6 | ||||
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | Cargo.toml | 20 | ||||
| -rw-r--r-- | README.md | 26 | ||||
| -rw-r--r-- | adblock/__init__.py | 2 | ||||
| -rw-r--r-- | pyproject.toml | 13 | ||||
| -rw-r--r-- | tests/test_metadata.py | 61 | ||||
| -rw-r--r-- | tests/test_version_numbers.py | 40 |
9 files changed, 134 insertions, 71 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68e1a10..806059d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml | |||
| @@ -4,6 +4,8 @@ on: | |||
| 4 | release: | 4 | release: |
| 5 | types: [created] | 5 | types: [created] |
| 6 | push: | 6 | push: |
| 7 | branches: | ||
| 8 | - master | ||
| 7 | pull_request: | 9 | pull_request: |
| 8 | schedule: | 10 | schedule: |
| 9 | # Runs every Thursday at 20:23 GMT to avoid bit rot | 11 | # Runs every Thursday at 20:23 GMT to avoid bit rot |
| @@ -69,7 +71,7 @@ jobs: | |||
| 69 | - name: Install dependencies | 71 | - name: Install dependencies |
| 70 | run: | | 72 | run: | |
| 71 | python -m pip install --upgrade pip | 73 | python -m pip install --upgrade pip |
| 72 | pip install poetry | 74 | pip install poetry twine |
| 73 | poetry install | 75 | poetry install |
| 74 | 76 | ||
| 75 | - name: Set Rust target environment variable | 77 | - name: Set Rust target environment variable |
| @@ -84,15 +86,17 @@ jobs: | |||
| 84 | override: true | 86 | override: true |
| 85 | 87 | ||
| 86 | - name: Build Python package | 88 | - name: Build Python package |
| 87 | if: matrix.architecture == 'x86' | 89 | run: poetry run maturin build --interpreter python${{matrix.python_version}} --target ${{ env.ACTIONS_RUST_TARGET }} |
| 88 | run: poetry run maturin build --target ${{ env.ACTIONS_RUST_TARGET }} | ||
| 89 | 90 | ||
| 90 | - name: Build Python package | 91 | - name: Check wheels with Twine |
| 91 | if: matrix.architecture != 'x86' | 92 | run: twine check target/wheels/* |
| 92 | run: poetry run maturin develop | 93 | shell: bash |
| 94 | |||
| 95 | - name: Install Python package | ||
| 96 | run: poetry run pip install target/wheels/adblock*.whl | ||
| 97 | shell: bash | ||
| 93 | 98 | ||
| 94 | - name: Run Python tests | 99 | - name: Run Python tests |
| 95 | if: matrix.architecture != 'x86' | ||
| 96 | run: poetry run pytest -vv --color=yes | 100 | run: poetry run pytest -vv --color=yes |
| 97 | 101 | ||
| 98 | python-publish: | 102 | python-publish: |
| @@ -133,10 +137,10 @@ jobs: | |||
| 133 | - name: Install dependencies | 137 | - name: Install dependencies |
| 134 | run: | | 138 | run: | |
| 135 | python -m pip install --upgrade pip | 139 | python -m pip install --upgrade pip |
| 136 | pip install poetry | 140 | pip install poetry twine |
| 137 | poetry install | 141 | poetry install |
| 138 | - name: Build Python package | 142 | - name: Build Python package |
| 139 | run: poetry run maturin build --release --no-sdist --strip --interpreter python${{matrix.python_version}} --target ${{ env.ACTIONS_RUST_TARGET }} | 143 | run: poetry run maturin build --release --strip --interpreter python${{matrix.python_version}} --target ${{ env.ACTIONS_RUST_TARGET }} |
| 140 | 144 | ||
| 141 | - name: List wheels | 145 | - name: List wheels |
| 142 | if: matrix.os == 'windows-latest' | 146 | if: matrix.os == 'windows-latest' |
| @@ -146,15 +150,9 @@ jobs: | |||
| 146 | if: matrix.os != 'windows-latest' | 150 | if: matrix.os != 'windows-latest' |
| 147 | run: find ./target/wheels/ | 151 | run: find ./target/wheels/ |
| 148 | 152 | ||
| 149 | # Note: Windows doesn't support glob | ||
| 150 | # https://stackoverflow.com/a/52481267/270334 | ||
| 151 | - name: Install wheels | 153 | - name: Install wheels |
| 152 | if: matrix.os == 'windows-latest' | ||
| 153 | run: pip install --find-links=target\wheels adblock | ||
| 154 | |||
| 155 | - name: Install wheels | ||
| 156 | if: matrix.os != 'windows-latest' | ||
| 157 | run: pip install target/wheels/adblock*.whl | 154 | run: pip install target/wheels/adblock*.whl |
| 155 | shell: bash | ||
| 158 | 156 | ||
| 159 | - name: Release | 157 | - name: Release |
| 160 | uses: softprops/action-gh-release@v1 | 158 | uses: softprops/action-gh-release@v1 |
| @@ -167,8 +165,9 @@ jobs: | |||
| 167 | - name: PyPi publish | 165 | - name: PyPi publish |
| 168 | if: github.event_name == 'release' && github.event.action == 'created' | 166 | if: github.event_name == 'release' && github.event.action == 'created' |
| 169 | env: | 167 | env: |
| 170 | MATURIN_PASSWORD: ${{ secrets.PYPI }} | 168 | TWINE_PASSWORD: ${{ secrets.PYPI }} |
| 171 | run: poetry run maturin publish --interpreter python${{matrix.python_version}} --username __token__ | 169 | run: twine upload --non-interactive --skip-existing --username __token__ target/wheels/* |
| 170 | shell: bash | ||
| 172 | 171 | ||
| 173 | docs-publish: | 172 | docs-publish: |
| 174 | runs-on: ubuntu-latest | 173 | runs-on: ubuntu-latest |
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e603b8..9274c90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
| @@ -7,6 +7,12 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch | |||
| 7 | --- | 7 | --- |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | ## 0.4.2 - (2021-02-01) | ||
| 11 | --- | ||
| 12 | ### Fixes | ||
| 13 | * Remove relative import which caused problems in [#17](https://github.com/ArniDagur/python-adblock/issues/17). | ||
| 14 | |||
| 15 | |||
| 10 | ## 0.4.1 - (2021-01-27) | 16 | ## 0.4.1 - (2021-01-27) |
| 11 | --- | 17 | --- |
| 12 | 18 | ||
| @@ -24,7 +24,7 @@ dependencies = [ | |||
| 24 | 24 | ||
| 25 | [[package]] | 25 | [[package]] |
| 26 | name = "adblock" | 26 | name = "adblock" |
| 27 | version = "0.4.1" | 27 | version = "0.4.2" |
| 28 | dependencies = [ | 28 | dependencies = [ |
| 29 | "adblock 0.3.4", | 29 | "adblock 0.3.4", |
| 30 | "pyo3", | 30 | "pyo3", |
| @@ -1,10 +1,22 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "adblock" | ||
| 3 | publish = false | 2 | publish = false |
| 4 | version = "0.4.1" | 3 | name = "adblock" |
| 5 | authors = ["Árni Dagur <arni@dagur.eu"] | 4 | version = "0.4.2" |
| 6 | edition = "2018" | 5 | edition = "2018" |
| 6 | authors = ["Árni Dagur <arni@dagur.eu>"] | ||
| 7 | license = "MIT OR Apache-2.0" | 7 | license = "MIT OR Apache-2.0" |
| 8 | readme = "README.md" | ||
| 9 | homepage = "https://github.com/ArniDagur/python-adblock" | ||
| 10 | repository = "https://github.com/ArniDagur/python-adblock" | ||
| 11 | |||
| 12 | [package.metadata.maturin] | ||
| 13 | classifier = [ | ||
| 14 | "Programming Language :: Python", | ||
| 15 | "Programming Language :: Rust", | ||
| 16 | "License :: OSI Approved :: MIT License", | ||
| 17 | "License :: OSI Approved :: Apache Software License", | ||
| 18 | ] | ||
| 19 | requires-python = ">=3.6" | ||
| 8 | 20 | ||
| 9 | [profile.release] | 21 | [profile.release] |
| 10 | debug = true | 22 | debug = true |
| @@ -18,4 +30,4 @@ name = "adblock" | |||
| 18 | crate-type = ["rlib", "cdylib"] | 30 | crate-type = ["rlib", "cdylib"] |
| 19 | 31 | ||
| 20 | [features] | 32 | [features] |
| 21 | default = ["pyo3/extension-module"] | 33 | default = ["pyo3/extension-module"] \ No newline at end of file |
| @@ -2,6 +2,32 @@ python-adblock | |||
| 2 | ========== | 2 | ========== |
| 3 | Python wrapper for Brave's adblocking library, which is written in Rust. | 3 | Python wrapper for Brave's adblocking library, which is written in Rust. |
| 4 | 4 | ||
| 5 | ### Building | ||
| 6 | |||
| 7 | ``` | ||
| 8 | maturin build --release | ||
| 9 | ``` | ||
| 10 | |||
| 11 | #### Build dependencies | ||
| 12 | |||
| 13 | | Build Dependency | Versions | Arch Linux | Url | | ||
| 14 | |------------------|----------|------------|-----| | ||
| 15 | | Python | `>=3.6` | `python3` | - | | ||
| 16 | | Rust | `>=1.45` | `rust` | - | | ||
| 17 | | Maturin | `*` | `maturin` | https://github.com/PyO3/maturin | | ||
| 18 | |||
| 19 | ### Developing | ||
| 20 | |||
| 21 | I use Poetry for development. To create and enter a virtual environment, do | ||
| 22 | ``` | ||
| 23 | poetry install | ||
| 24 | poetry shell | ||
| 25 | ``` | ||
| 26 | then, to install the `adblock` module into the virtual environment, do | ||
| 27 | ``` | ||
| 28 | maturin develop | ||
| 29 | ``` | ||
| 30 | |||
| 5 | ### Documentation | 31 | ### Documentation |
| 6 | 32 | ||
| 7 | Rust documentation for the latest `master` branch can be found at https://arnidagur.github.io/python-adblock/docs/adblock/index.html. | 33 | Rust documentation for the latest `master` branch can be found at https://arnidagur.github.io/python-adblock/docs/adblock/index.html. |
diff --git a/adblock/__init__.py b/adblock/__init__.py index bb1b6e1..0cc1876 100644 --- a/adblock/__init__.py +++ b/adblock/__init__.py | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | from .adblock import __version__, Engine, FilterSet, BlockerResult, UrlSpecificResources | 1 | from adblock.adblock import __version__, Engine, FilterSet, BlockerResult, UrlSpecificResources |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | __all__ = ("Engine", "FilterSet", "BlockerResult", "UrlSpecificResources") | 4 | __all__ = ("Engine", "FilterSet", "BlockerResult", "UrlSpecificResources") |
diff --git a/pyproject.toml b/pyproject.toml index 432e476..8bbdb76 100644 --- a/pyproject.toml +++ b/pyproject.toml | |||
| @@ -1,18 +1,17 @@ | |||
| 1 | [tool.poetry] | 1 | [tool.poetry] |
| 2 | name = "adblock" | 2 | name = "adblock" |
| 3 | version = "0.4.1" | 3 | version = "0.0.0" |
| 4 | description = "Brave's adblocking in Python" | 4 | description = "Brave's adblocking in Python" |
| 5 | authors = ["Árni Dagur <arni@dagur.eu>"] | 5 | authors = ["Árni Dagur <arni@dagur.eu>"] |
| 6 | license = "MIT OR Apache-2.0" | ||
| 7 | readme = "README.md" | ||
| 8 | repository = "https://github.com/ArniDagur/python-adblock" | ||
| 9 | keywords = [] | ||
| 10 | 6 | ||
| 11 | [tool.poetry.dependencies] | 7 | [tool.poetry.dependencies] |
| 12 | python = "^3.5" | 8 | python = "^3.6" |
| 13 | 9 | ||
| 14 | [tool.poetry.dev-dependencies] | 10 | [tool.poetry.dev-dependencies] |
| 15 | maturin = "*" | 11 | maturin = "*" |
| 16 | pytest = "*" | 12 | pytest = "*" |
| 17 | toml = "*" | 13 | toml = "*" |
| 18 | changelog-cli = "*" \ No newline at end of file | 14 | |
| 15 | [build-system] | ||
| 16 | requires = ["maturin"] | ||
| 17 | build-backend = "maturin" \ No newline at end of file | ||
diff --git a/tests/test_metadata.py b/tests/test_metadata.py new file mode 100644 index 0000000..1a0e6d8 --- /dev/null +++ b/tests/test_metadata.py | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | import re | ||
| 2 | import sys | ||
| 3 | |||
| 4 | import toml | ||
| 5 | import adblock | ||
| 6 | |||
| 7 | |||
| 8 | def get_version_value_cargo(): | ||
| 9 | with open("Cargo.toml", encoding="utf-8") as f: | ||
| 10 | cargo_toml = toml.loads(f.read()) | ||
| 11 | return cargo_toml["package"]["version"] | ||
| 12 | |||
| 13 | |||
| 14 | def get_version_value_changelog(): | ||
| 15 | """ | ||
| 16 | Try to get the names of all classes that we added to the Python module | ||
| 17 | from Rust. As always, we unfortunately don't have access to the Rust AST | ||
| 18 | so we have to make do with regular expressions. | ||
| 19 | """ | ||
| 20 | versions = [] | ||
| 21 | with open("CHANGELOG.md", "r", encoding="utf-8") as f: | ||
| 22 | for line in f: | ||
| 23 | match = re.match( | ||
| 24 | r"## ([0-9]+\.[0-9]+\.[0-9]+) - \(20[0-9]+-[0-1][0-9]-[0-3][0-9]\)", | ||
| 25 | line.strip(), | ||
| 26 | ) | ||
| 27 | if match is not None: | ||
| 28 | versions.append(match.group(1)) | ||
| 29 | assert versions == sorted(versions, reverse=True) | ||
| 30 | return versions[0] | ||
| 31 | |||
| 32 | |||
| 33 | def test_version_numbers_all_same(): | ||
| 34 | """ | ||
| 35 | Makes sure that `Cargo.toml` and `CHANGELOG.md` contain the same version | ||
| 36 | number as the one attached to the `adblock` module. | ||
| 37 | """ | ||
| 38 | cargo_version = get_version_value_cargo() | ||
| 39 | changelog_version = get_version_value_changelog() | ||
| 40 | module_version = adblock.__version__ | ||
| 41 | |||
| 42 | assert cargo_version == module_version | ||
| 43 | assert module_version == changelog_version | ||
| 44 | |||
| 45 | |||
| 46 | def get_current_python_version(): | ||
| 47 | return f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" | ||
| 48 | |||
| 49 | |||
| 50 | def test_required_python_version(): | ||
| 51 | """ | ||
| 52 | Make sure that the Python interpreter we're running this test suite on | ||
| 53 | falls into the required Python range. | ||
| 54 | """ | ||
| 55 | with open("Cargo.toml", encoding="utf-8") as f: | ||
| 56 | cargo_toml = toml.loads(f.read()) | ||
| 57 | |||
| 58 | required_python = cargo_toml["package"]["metadata"]["maturin"]["requires-python"] | ||
| 59 | assert required_python.startswith(">=") | ||
| 60 | required_python = required_python[2:] | ||
| 61 | assert get_current_python_version() >= required_python | ||
diff --git a/tests/test_version_numbers.py b/tests/test_version_numbers.py deleted file mode 100644 index 77db2f5..0000000 --- a/tests/test_version_numbers.py +++ /dev/null | |||
| @@ -1,40 +0,0 @@ | |||
| 1 | import subprocess | ||
| 2 | |||
| 3 | import toml | ||
| 4 | import adblock | ||
| 5 | |||
| 6 | |||
| 7 | def get_version_value_poetry(): | ||
| 8 | with open("pyproject.toml", encoding="utf-8") as f: | ||
| 9 | pyproject_toml = toml.loads(f.read()) | ||
| 10 | return pyproject_toml["tool"]["poetry"]["version"] | ||
| 11 | |||
| 12 | |||
| 13 | def get_version_value_cargo(): | ||
| 14 | with open("Cargo.toml", encoding="utf-8") as f: | ||
| 15 | cargo_toml = toml.loads(f.read()) | ||
| 16 | return cargo_toml["package"]["version"] | ||
| 17 | |||
| 18 | |||
| 19 | def get_version_value_changelog(): | ||
| 20 | try: | ||
| 21 | proc = subprocess.Popen(["changelog", "current"], stdout=subprocess.PIPE) | ||
| 22 | except FileNotFoundError: | ||
| 23 | return None | ||
| 24 | assert proc.wait() == 0 | ||
| 25 | return proc.stdout.read().decode("utf-8").strip() | ||
| 26 | |||
| 27 | |||
| 28 | def test_version_numbers_all_same(): | ||
| 29 | """ | ||
| 30 | Makes sure that `pyproject.toml`, `Cargo.toml`, and `CHANGELOG.md` contain | ||
| 31 | the same version number as the one attached to the `adblock` module. | ||
| 32 | """ | ||
| 33 | cargo_version = get_version_value_cargo() | ||
| 34 | poetry_version = get_version_value_poetry() | ||
| 35 | changelog_version = get_version_value_changelog() | ||
| 36 | module_version = adblock.__version__ | ||
| 37 | |||
| 38 | assert cargo_version == poetry_version | ||
| 39 | assert poetry_version == module_version | ||
| 40 | assert changelog_version is None or module_version == changelog_version | ||
