Skip to content

Commit 2efdad6

Browse files
committed
Rewrite docs and add new html example
1 parent 516cf38 commit 2efdad6

23 files changed

+25342
-26
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
*.pyo
33
*.so
44
.eggs
5-
/dist
6-
/build
5+
dist
6+
build
7+
target
8+
.pytest_cache
79
*.egg-info
810
Cargo.lock
911
pyo3

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ script:
2828
- cd example_tomlgen
2929
- python setup.py tomlgen_rust -w build
3030
- cd ..
31-
- git clone --depth 1 https://github.com/PyO3/pyo3
32-
- cd pyo3/examples/word-count
31+
- cd html-py-ever
32+
- pip install -r requirements-dev.txt
3333
- python setup.py install
34-
- cd ../../..
35-
- python -c "import word_count"
34+
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then cd test && pytest; fi

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.10.3 (2018-09-06)
4+
5+
- `path` in `RustExtension` now defaults to `Cargo.toml`
6+
37
## 0.10.2 (2018-08-09)
48

59
- Add `rustc_flags` and `verbose` as options

README.md

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,80 @@
1-
# Setuptools plugin for Rust extensions support
1+
# Setuptools plugin for Rust extensions
22

33
[![Build Status](https://travis-ci.org/PyO3/setuptools-rust.svg?branch=master)](https://travis-ci.org/PyO3/setuptools-rust)
44
[![pypi package](https://badge.fury.io/py/setuptools-rust.svg)](https://badge.fury.io/py/setuptools-rust)
55
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
66

77
**You might want to check out [pyo3-pack](https://github.com/PyO3/pyo3-pack), the successor to this project, which allows to develop, build and upload without any configuration**
88

9-
Setuptools helpers for rust Python extensions implemented with [PyO3
10-
python binding](https://github.com/PyO3/pyo3).
9+
Setuptools helpers for rust Python extensions implemented with [PyO3](https://github.com/PyO3/pyo3) and [rust-cpython](https://github.com/dgrunwald/rust-cpython).
1110

1211
Compile and distribute Python extensions written in rust as easily as if
1312
they were written in C.
1413

15-
## Example
14+
## Setup
1615

1716
For a complete example, see
18-
[word-count](https://github.com/PyO3/pyo3/tree/master/examples/word-count).
17+
[html-py-ever](https://github.com/PyO3/setuptools-rust/tree/master/html-py-ever).
18+
19+
First, you need to create a bunch of files:
1920

2021
### setup.py
2122

2223
```python
2324
from setuptools import setup
2425
from setuptools_rust import Binding, RustExtension
2526

26-
setup(name='hello-rust',
27-
version='1.0',
28-
rust_extensions=[RustExtension('hello_rust.helloworld',
29-
'Cargo.toml', binding=Binding.PyO3)],
30-
packages=['hello_rust'],
31-
# rust extensions are not zip safe, just like C-extensions.
32-
zip_safe=False
27+
setup(
28+
name="hello-rust",
29+
version="1.0",
30+
rust_extensions=[RustExtension("hello_rust.hello_rust", binding=Binding.PyO3)],
31+
packages=["hello_rust"],
32+
# rust extensions are not zip safe, just like C-extensions.
33+
zip_safe=False,
3334
)
3435
```
3536

37+
### MANIFEST.in
38+
39+
This file is required for building source distributions
40+
41+
```text
42+
include Cargo.toml
43+
recursive-include src *
44+
```
45+
46+
### pyproject.toml
47+
48+
```toml
49+
[build-system]
50+
requires = ["setuptools", "wheel", "setuptools-rust"]
51+
```
52+
53+
### build-wheels.sh
54+
55+
```bash
56+
#!/bin/bash
57+
set -ex
58+
59+
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly -y
60+
export PATH="$HOME/.cargo/bin:$PATH"
61+
62+
cd /io
63+
64+
for PYBIN in /opt/python/{cp27-cp27m,cp27-cp27mu,cp35-cp35m,cp36-cp36m,cp37-cp37m}/bin; do
65+
export PYTHON_SYS_EXECUTABLE="$PYBIN/python"
66+
67+
"${PYBIN}/pip" install -U setuptools wheel setuptools-rust
68+
"${PYBIN}/python" setup.py bdist_wheel
69+
done
70+
71+
for whl in dist/*.whl; do
72+
auditwheel repair "$whl" -w dist/
73+
done
74+
```
75+
76+
## Usage
77+
3678
You can use same commands as for c-extensions. For example:
3779

3880
```
@@ -56,17 +98,38 @@ Processing dependencies for hello_rust==1.0
5698
Finished processing dependencies for hello_rust==1.0
5799
```
58100

59-
Or you can use commands like bdist\_wheel (after installing wheel) or
60-
bdist\_egg.
101+
Or you can use commands like bdist_wheel (after installing wheel).
102+
103+
By default, `develop` will create a debug build, while `install` will create a release build.
61104

62-
You can build manylinux1 binary wheels using Docker, e.g. with the
63-
build-wheels.sh
64-
script:
105+
### Binary wheels on linux
106+
107+
To build binary wheels on linux, you need to use the [manylinux docker container](https://github.com/pypa/manylinux). You also need a `build-wheels.sh` similar to [the one in the example](https://github.com/PyO3/setuptools-rist/blob/master/html-py-ever/build-wheels.sh), which will be run in that container.
108+
109+
First, pull the `manylinux1` Docker image:
110+
111+
```bash
112+
docker pull quay.io/pypa/manylinux1_x86_64
113+
```
114+
115+
Then use the following command to build wheels for supported Python versions:
65116

66117
```bash
67118
docker run --rm -v `pwd`:/io quay.io/pypa/manylinux1_x86_64 /io/build-wheels.sh
68119
```
69120

121+
This will create wheels in the `dist` directory:
122+
123+
```bash
124+
$ ls dist
125+
hello_rust-1.0-cp27-cp27m-linux_x86_64.whl hello_rust-1.0-cp35-cp35m-linux_x86_64.whl
126+
hello_rust-1.0-cp27-cp27m-manylinux1_x86_64.whl hello_rust-1.0-cp35-cp35m-manylinux1_x86_64.whl
127+
hello_rust-1.0-cp27-cp27mu-linux_x86_64.whl hello_rust-1.0-cp36-cp36m-linux_x86_64.whl
128+
hello_rust-1.0-cp27-cp27mu-manylinux1_x86_64.whl hello_rust-1.0-cp36-cp36m-manylinux1_x86_64.whl
129+
```
130+
131+
You can then upload the `manylinux1` wheels to pypi using [twine](https://github.com/pypa/twine).
132+
70133
## RustExtension
71134

72135
You can define rust extension with RustExtension class:

html-py-ever/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "html-py-ever"
3+
version = "0.1.0"
4+
authors = ["konstin <konstin@mailbox.org>"]
5+
6+
[dependencies]
7+
kuchiki = "0.7.2"
8+
pyo3 = {path= "../../pyo3", features = ["extension-module"]}
9+
tendril = "0.4.0"
10+
11+
[lib]
12+
name = "html_py_ever"
13+
crate-type = ["cdylib"]

html-py-ever/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# html-py-ever
2+
3+
Using [html5ever](https://github.com/servo/html5ever) through [kuchiki](https://github.com/kuchiki-rs/kuchiki) to speed up html parsing and css-selecting.
4+
5+
## Benchmarking
6+
7+
Create a python 3.6+ venv and activate it. Install html-py-ever in there (`python setup.py install`). To get a readable benchmark, run `test/run_all.py`. To get a real benchmark, run `pytest test_parsing.py` or `pytest test_selector.py`. Both have a `--benchmark-histogram` option.

html-py-ever/build-wheels.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly -y
5+
export PATH="$HOME/.cargo/bin:$PATH"
6+
7+
cd /io
8+
9+
for PYBIN in /opt/python/{cp27-cp27m,cp27-cp27mu,cp35-cp35m,cp36-cp36m,cp37-cp37m}/bin; do
10+
export PYTHON_SYS_EXECUTABLE="$PYBIN/python"
11+
12+
"${PYBIN}/pip" install -U setuptools wheel setuptools-rust
13+
"${PYBIN}/python" setup.py bdist_wheel
14+
done
15+
16+
for whl in dist/*.whl; do
17+
auditwheel repair "$whl" -w dist/
18+
done

html-py-ever/html_py_ever/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .html_py_ever import *

html-py-ever/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel", "setuptools-rust"]

html-py-ever/requirements-dev.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
setuptools
2+
setuptools-rust
3+
wheel
4+
pytest-benchmark[historgram]
5+
pytest
6+

0 commit comments

Comments
 (0)