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 - name: Run benchmarks
run: | run: |
cd pytests/pyo3-benchmarks cd pytests/pyo3-benchmarks
python -m pip install -r requirements-dev.txt pip install -r requirements-dev.txt
python setup.py develop pip install .
pytest --benchmark-json ../../output.json pytest --benchmark-json ../../output.json --benchmark-enable
- name: Store benchmark result - name: Store benchmark result
uses: rhysd/github-action-benchmark@v1 uses: rhysd/github-action-benchmark@v1
with: with:

View File

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

View File

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

View File

@ -4,5 +4,7 @@ import nox
@nox.session @nox.session
def python(session): def python(session):
session.install("-rrequirements-dev.txt") 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") session.run("pytest")

View File

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

View File

@ -1,6 +1,13 @@
import os
from setuptools import setup from setuptools import setup
from setuptools_rust import RustExtension from setuptools_rust import RustExtension
setup( 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] [project]
name = "{{project-name}}" name = "{{project-name}}"
version = "0.1.0" 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 ## Build
```shell ```shell
python setup.py install pip install .
``` ```
## Usage ## Usage
@ -18,21 +18,6 @@ search("foo bar", "foo")
search_sequential("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 ## Testing
To test install nox globally and run To test install nox globally and run
@ -41,6 +26,14 @@ To test install nox globally and run
nox nox
``` ```
## Benchmark
To test install nox globally and run
```shell
nox -s bench
```
## Copying this example ## Copying this example
Use [`cargo-generate`](https://crates.io/crates/cargo-generate): Use [`cargo-generate`](https://crates.io/crates/cargo-generate):

View File

@ -1,8 +1,18 @@
import nox import nox
nox.options.sessions = ["test"]
@nox.session @nox.session
def python(session): def test(session):
session.install("-rrequirements-dev.txt") session.install("-rrequirements-dev.txt")
session.install("-e", ".", "--no-build-isolation") session.install("maturin")
session.run_always("maturin", "develop")
session.run("pytest") 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] [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 pytest>=3.5.0
setuptools_rust~=1.0.0
pytest-benchmark>=3.1.1 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"] features = ["extension-module"]
[lib] [lib]
name = "_pyo3_benchmarks" name = "pyo3_benchmarks"
crate-type = ["cdylib"] 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: You can install the module in your Python environment and then run the benchmarks with pytest:
```shell ```shell
python setup.py develop pip install .
pytest pytest --benchmark-enable
``` ```
Or with nox: Or with nox:
```shell ```shell
nox nox -s bench
``` ```

View File

@ -1,8 +1,18 @@
import nox import nox
nox.options.sessions = ["test"]
@nox.session @nox.session
def python(session): def test(session):
session.install("-rrequirements-dev.txt") session.install("-rrequirements-dev.txt")
session.install("-e", ".", "--no-build-isolation") session.install("maturin")
session.run("pytest", "--benchmark-sort=name") 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] #[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!(none, m)?)?;
m.add_function(wrap_pyfunction!(simple, m)?)?; m.add_function(wrap_pyfunction!(simple, m)?)?;
m.add_function(wrap_pyfunction!(simple_args, m)?)?; m.add_function(wrap_pyfunction!(simple_args, m)?)?;

View File

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