Skip to content

Commit dc33223

Browse files
authored
Packaging improvements (#34)
* Use maturin for PEP 517 compliancy * Removing relative import in __init__.py * Bump version to 0.4.2
1 parent d0dbf82 commit dc33223

File tree

9 files changed

+134
-71
lines changed

9 files changed

+134
-71
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
release:
55
types: [created]
66
push:
7+
branches:
8+
- master
79
pull_request:
810
schedule:
911
# Runs every Thursday at 20:23 GMT to avoid bit rot
@@ -69,7 +71,7 @@ jobs:
6971
- name: Install dependencies
7072
run: |
7173
python -m pip install --upgrade pip
72-
pip install poetry
74+
pip install poetry twine
7375
poetry install
7476
7577
- name: Set Rust target environment variable
@@ -84,15 +86,17 @@ jobs:
8486
override: true
8587

8688
- name: Build Python package
87-
if: matrix.architecture == 'x86'
88-
run: poetry run maturin build --target ${{ env.ACTIONS_RUST_TARGET }}
89+
run: poetry run maturin build --interpreter python${{matrix.python_version}} --target ${{ env.ACTIONS_RUST_TARGET }}
8990

90-
- name: Build Python package
91-
if: matrix.architecture != 'x86'
92-
run: poetry run maturin develop
91+
- name: Check wheels with Twine
92+
run: twine check target/wheels/*
93+
shell: bash
94+
95+
- name: Install Python package
96+
run: poetry run pip install target/wheels/adblock*.whl
97+
shell: bash
9398

9499
- name: Run Python tests
95-
if: matrix.architecture != 'x86'
96100
run: poetry run pytest -vv --color=yes
97101

98102
python-publish:
@@ -133,10 +137,10 @@ jobs:
133137
- name: Install dependencies
134138
run: |
135139
python -m pip install --upgrade pip
136-
pip install poetry
140+
pip install poetry twine
137141
poetry install
138142
- 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 }}
140144

141145
- name: List wheels
142146
if: matrix.os == 'windows-latest'
@@ -146,15 +150,9 @@ jobs:
146150
if: matrix.os != 'windows-latest'
147151
run: find ./target/wheels/
148152

149-
# Note: Windows doesn't support glob
150-
# https://stackoverflow.com/a/52481267/270334
151153
- 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'
157154
run: pip install target/wheels/adblock*.whl
155+
shell: bash
158156

159157
- name: Release
160158
uses: softprops/action-gh-release@v1
@@ -167,8 +165,9 @@ jobs:
167165
- name: PyPi publish
168166
if: github.event_name == 'release' && github.event.action == 'created'
169167
env:
170-
MATURIN_PASSWORD: ${{ secrets.PYPI }}
171-
run: poetry run maturin publish --interpreter python${{matrix.python_version}} --username __token__
168+
TWINE_PASSWORD: ${{ secrets.PYPI }}
169+
run: twine upload --non-interactive --skip-existing --username __token__ target/wheels/*
170+
shell: bash
172171

173172
docs-publish:
174173
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
77
---
88

99

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+
1016
## 0.4.1 - (2021-01-27)
1117
---
1218

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
[package]
2-
name = "adblock"
32
publish = false
4-
version = "0.4.1"
5-
authors = ["Árni Dagur <[email protected]"]
3+
name = "adblock"
4+
version = "0.4.2"
65
edition = "2018"
6+
authors = ["Árni Dagur <[email protected]>"]
77
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"
820

921
[profile.release]
1022
debug = true
@@ -18,4 +30,4 @@ name = "adblock"
1830
crate-type = ["rlib", "cdylib"]
1931

2032
[features]
21-
default = ["pyo3/extension-module"]
33+
default = ["pyo3/extension-module"]

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@ python-adblock
22
==========
33
Python wrapper for Brave's adblocking library, which is written in Rust.
44

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+
531
### Documentation
632

733
Rust documentation for the latest `master` branch can be found at https://arnidagur.github.io/python-adblock/docs/adblock/index.html.

adblock/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .adblock import __version__, Engine, FilterSet, BlockerResult, UrlSpecificResources
1+
from adblock.adblock import __version__, Engine, FilterSet, BlockerResult, UrlSpecificResources
22

33

44
__all__ = ("Engine", "FilterSet", "BlockerResult", "UrlSpecificResources")

pyproject.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
[tool.poetry]
22
name = "adblock"
3-
version = "0.4.1"
3+
version = "0.0.0"
44
description = "Brave's adblocking in Python"
55
authors = ["Árni Dagur <[email protected]>"]
6-
license = "MIT OR Apache-2.0"
7-
readme = "README.md"
8-
repository = "https://github.com/ArniDagur/python-adblock"
9-
keywords = []
106

117
[tool.poetry.dependencies]
12-
python = "^3.5"
8+
python = "^3.6"
139

1410
[tool.poetry.dev-dependencies]
1511
maturin = "*"
1612
pytest = "*"
1713
toml = "*"
18-
changelog-cli = "*"
14+
15+
[build-system]
16+
requires = ["maturin"]
17+
build-backend = "maturin"

tests/test_metadata.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/test_version_numbers.py

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

0 commit comments

Comments
 (0)