ci: build all examples in debug

This commit is contained in:
David Hewitt 2022-01-22 23:15:36 +00:00
parent a3862de682
commit 000a903676
21 changed files with 88 additions and 91 deletions

View File

@ -84,9 +84,9 @@ jobs:
- name: Run benchmarks
run: |
cd pytests/pyo3-benchmarks
python -m pip install -r requirements-dev.txt
python setup.py develop
pytest --benchmark-json ../../output.json
pip install -r requirements-dev.txt
pip install .
pytest --benchmark-json ../../output.json --benchmark-enable
- name: Store benchmark result
uses: rhysd/github-action-benchmark@v1
with:

View File

@ -4,5 +4,6 @@ import nox
@nox.session
def python(session):
session.install("-rrequirements-dev.txt")
session.install(".", "--no-build-isolation")
session.install("maturin")
session.run_always("maturin", "develop")
session.run("pytest")

View File

@ -4,5 +4,6 @@ import nox
@nox.session
def python(session):
session.install("-rrequirements-dev.txt")
session.install(".", "--no-build-isolation")
session.install("maturin")
session.run_always("maturin", "develop")
session.run("pytest")

View File

@ -4,5 +4,7 @@ import nox
@nox.session
def python(session):
session.install("-rrequirements-dev.txt")
session.install("-e", ".", "--no-build-isolation")
session.run_always(
"pip", "install", "-e", ".", "--no-build-isolation", env={"BUILD_DEBUG": "1"}
)
session.run("pytest")

View File

@ -1,8 +1,6 @@
[metadata]
name = setuptools-rust-starter
version = 0.1.0
packages =
setuptools_rust_starter
classifiers =
License :: OSI Approved :: MIT License
Development Status :: 3 - Alpha
@ -13,5 +11,7 @@ classifiers =
Operating System :: MacOS :: MacOS X
[options]
packages =
setuptools_rust_starter
include_package_data = True
zip_safe = False

View File

@ -1,6 +1,13 @@
import os
from setuptools import setup
from setuptools_rust import RustExtension
setup(
rust_extensions=[RustExtension("setuptools_rust_starter._setuptools_rust_starter")],
rust_extensions=[
RustExtension(
"setuptools_rust_starter._setuptools_rust_starter",
debug=os.environ.get("BUILD_DEBUG") == "1",
)
],
)

View File

@ -4,3 +4,6 @@ requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=1.0.0"]
[project]
name = "{{project-name}}"
version = "0.1.0"
[tool.pytest.ini_options]
addopts = "--benchmark-disable"

View File

@ -5,7 +5,7 @@ Demonstrates searching for a file in plain python, with rust singlethreaded and
## Build
```shell
python setup.py install
pip install .
```
## Usage
@ -18,21 +18,6 @@ search("foo bar", "foo")
search_sequential("foo bar", "foo")
```
## Benchmark
Install the depedencies:
```shell
pip install -r requirements-dev.txt
```
There is a benchmark in `tests/test_word_count.py`:
```shell
pytest -v tests
```
## Testing
To test install nox globally and run
@ -41,6 +26,14 @@ To test install nox globally and run
nox
```
## Benchmark
To test install nox globally and run
```shell
nox -s bench
```
## Copying this example
Use [`cargo-generate`](https://crates.io/crates/cargo-generate):

View File

@ -1,8 +1,18 @@
import nox
nox.options.sessions = ["test"]
@nox.session
def python(session):
def test(session):
session.install("-rrequirements-dev.txt")
session.install("-e", ".", "--no-build-isolation")
session.install("maturin")
session.run_always("maturin", "develop")
session.run("pytest")
@nox.session
def bench(session):
session.install("-rrequirements-dev.txt")
session.install(".")
session.run("pytest", "--benchmark-enable")

View File

@ -1,2 +1,20 @@
[build-system]
requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=1.0.0"]
requires = ["maturin>=0.12,<0.13"]
build-backend = "maturin"
[project]
name = "word-count"
version = "0.1.0"
classifier=[
"License :: OSI Approved :: MIT License",
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Rust",
"Operating System :: POSIX",
"Operating System :: MacOS :: MacOS X",
]
[tool.pytest.ini_options]
addopts = "--benchmark-disable"

View File

@ -1,3 +1,2 @@
pytest>=3.5.0
setuptools_rust~=1.0.0
pytest-benchmark>=3.1.1

View File

@ -1,17 +0,0 @@
[metadata]
name = word-count
version = 0.1.0
packages =
word_count
classifiers =
License :: OSI Approved :: MIT License
Development Status :: 3 - Alpha
Intended Audience :: Developers
Programming Language :: Python
Programming Language :: Rust
Operating System :: POSIX
Operating System :: MacOS :: MacOS X
[options]
include_package_data = True
zip_safe = False

View File

@ -1,6 +0,0 @@
from setuptools import setup
from setuptools_rust import RustExtension
setup(
rust_extensions=[RustExtension("word_count.word_count", debug=False)],
)

View File

@ -12,5 +12,5 @@ path = "../../"
features = ["extension-module"]
[lib]
name = "_pyo3_benchmarks"
name = "pyo3_benchmarks"
crate-type = ["cdylib"]

View File

@ -7,12 +7,12 @@ This extension module contains benchmarks for pieces of PyO3's API accessible fr
You can install the module in your Python environment and then run the benchmarks with pytest:
```shell
python setup.py develop
pytest
pip install .
pytest --benchmark-enable
```
Or with nox:
```shell
nox
nox -s bench
```

View File

@ -1,8 +1,18 @@
import nox
nox.options.sessions = ["test"]
@nox.session
def python(session):
def test(session):
session.install("-rrequirements-dev.txt")
session.install("-e", ".", "--no-build-isolation")
session.run("pytest", "--benchmark-sort=name")
session.install("maturin")
session.run_always("maturin", "develop")
session.run("pytest")
@nox.session
def bench(session):
session.install("-rrequirements-dev.txt")
session.install(".")
session.run("pytest", "--benchmark-enable")

View File

@ -1 +0,0 @@
from ._pyo3_benchmarks import *

View File

@ -0,0 +1,6 @@
[build-system]
requires = ["maturin>=0.12,<0.13"]
build-backend = "maturin"
[tool.pytest.ini_options]
addopts = "--benchmark-disable"

View File

@ -1,28 +0,0 @@
import os
from setuptools import setup
from setuptools_rust import RustExtension
setup(
name="pyo3-benchmarks",
version="0.1.0",
classifiers=[
"License :: OSI Approved :: MIT License",
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Rust",
"Operating System :: POSIX",
"Operating System :: MacOS :: MacOS X",
],
packages=["pyo3_benchmarks"],
rust_extensions=[
RustExtension(
"pyo3_benchmarks._pyo3_benchmarks",
# build debug when measuring coverage, otherwise release
debug="CARGO_LLVM_COV_TARGET_DIR" in os.environ,
),
],
include_package_data=True,
zip_safe=False,
)

View File

@ -66,7 +66,7 @@ impl EmptyClass {
}
#[pymodule]
fn _pyo3_benchmarks(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
fn pyo3_benchmarks(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(none, m)?)?;
m.add_function(wrap_pyfunction!(simple, m)?)?;
m.add_function(wrap_pyfunction!(simple_args, m)?)?;

View File

@ -1,4 +1,3 @@
[build-system]
# FIXME: branch is necessary for coverage to work
requires = ["maturin @ git+https://github.com/davidhewitt/maturin@profile-arg"]
requires = ["maturin>=0.12,<0.13"]
build-backend = "maturin"