From 000a90367640a0c7fae954d18bc40cb86578b0f4 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Sat, 22 Jan 2022 23:15:36 +0000 Subject: [PATCH] ci: build all examples in debug --- .github/workflows/bench.yml | 6 ++-- examples/decorator/noxfile.py | 3 +- examples/maturin-starter/noxfile.py | 3 +- examples/setuptools-rust-starter/noxfile.py | 4 ++- examples/setuptools-rust-starter/setup.cfg | 4 +-- examples/setuptools-rust-starter/setup.py | 9 +++++- examples/word-count/.template/pyproject.toml | 3 ++ examples/word-count/README.md | 25 ++++++----------- examples/word-count/noxfile.py | 14 ++++++++-- examples/word-count/pyproject.toml | 20 ++++++++++++- examples/word-count/requirements-dev.txt | 1 - examples/word-count/setup.cfg | 17 ----------- examples/word-count/setup.py | 6 ---- pytests/pyo3-benchmarks/Cargo.toml | 2 +- pytests/pyo3-benchmarks/README.md | 6 ++-- pytests/pyo3-benchmarks/noxfile.py | 16 +++++++++-- .../pyo3_benchmarks/__init__.py | 1 - pytests/pyo3-benchmarks/pyproject.toml | 6 ++++ pytests/pyo3-benchmarks/setup.py | 28 ------------------- pytests/pyo3-benchmarks/src/lib.rs | 2 +- pytests/pyo3-pytests/pyproject.toml | 3 +- 21 files changed, 88 insertions(+), 91 deletions(-) delete mode 100644 examples/word-count/setup.cfg delete mode 100644 examples/word-count/setup.py delete mode 100644 pytests/pyo3-benchmarks/pyo3_benchmarks/__init__.py create mode 100644 pytests/pyo3-benchmarks/pyproject.toml delete mode 100644 pytests/pyo3-benchmarks/setup.py diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 634d8bc6..c1c1919d 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -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: diff --git a/examples/decorator/noxfile.py b/examples/decorator/noxfile.py index e6d1b300..17a6b80f 100644 --- a/examples/decorator/noxfile.py +++ b/examples/decorator/noxfile.py @@ -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") diff --git a/examples/maturin-starter/noxfile.py b/examples/maturin-starter/noxfile.py index e6d1b300..17a6b80f 100644 --- a/examples/maturin-starter/noxfile.py +++ b/examples/maturin-starter/noxfile.py @@ -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") diff --git a/examples/setuptools-rust-starter/noxfile.py b/examples/setuptools-rust-starter/noxfile.py index b1414225..f6c62af1 100644 --- a/examples/setuptools-rust-starter/noxfile.py +++ b/examples/setuptools-rust-starter/noxfile.py @@ -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") diff --git a/examples/setuptools-rust-starter/setup.cfg b/examples/setuptools-rust-starter/setup.cfg index cd9882bc..95caeb75 100644 --- a/examples/setuptools-rust-starter/setup.cfg +++ b/examples/setuptools-rust-starter/setup.cfg @@ -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 diff --git a/examples/setuptools-rust-starter/setup.py b/examples/setuptools-rust-starter/setup.py index 3725444b..85d9e21d 100644 --- a/examples/setuptools-rust-starter/setup.py +++ b/examples/setuptools-rust-starter/setup.py @@ -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", + ) + ], ) diff --git a/examples/word-count/.template/pyproject.toml b/examples/word-count/.template/pyproject.toml index c25d7dc5..b436b675 100644 --- a/examples/word-count/.template/pyproject.toml +++ b/examples/word-count/.template/pyproject.toml @@ -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" diff --git a/examples/word-count/README.md b/examples/word-count/README.md index 42fa6c0e..6005fc53 100644 --- a/examples/word-count/README.md +++ b/examples/word-count/README.md @@ -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): diff --git a/examples/word-count/noxfile.py b/examples/word-count/noxfile.py index b1414225..39230d26 100644 --- a/examples/word-count/noxfile.py +++ b/examples/word-count/noxfile.py @@ -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") diff --git a/examples/word-count/pyproject.toml b/examples/word-count/pyproject.toml index d82653c1..9d312b85 100644 --- a/examples/word-count/pyproject.toml +++ b/examples/word-count/pyproject.toml @@ -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" diff --git a/examples/word-count/requirements-dev.txt b/examples/word-count/requirements-dev.txt index dbc0f652..fcd8fc54 100644 --- a/examples/word-count/requirements-dev.txt +++ b/examples/word-count/requirements-dev.txt @@ -1,3 +1,2 @@ pytest>=3.5.0 -setuptools_rust~=1.0.0 pytest-benchmark>=3.1.1 diff --git a/examples/word-count/setup.cfg b/examples/word-count/setup.cfg deleted file mode 100644 index d8f501ba..00000000 --- a/examples/word-count/setup.cfg +++ /dev/null @@ -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 diff --git a/examples/word-count/setup.py b/examples/word-count/setup.py deleted file mode 100644 index df702806..00000000 --- a/examples/word-count/setup.py +++ /dev/null @@ -1,6 +0,0 @@ -from setuptools import setup -from setuptools_rust import RustExtension - -setup( - rust_extensions=[RustExtension("word_count.word_count", debug=False)], -) diff --git a/pytests/pyo3-benchmarks/Cargo.toml b/pytests/pyo3-benchmarks/Cargo.toml index f931e19a..56305b66 100644 --- a/pytests/pyo3-benchmarks/Cargo.toml +++ b/pytests/pyo3-benchmarks/Cargo.toml @@ -12,5 +12,5 @@ path = "../../" features = ["extension-module"] [lib] -name = "_pyo3_benchmarks" +name = "pyo3_benchmarks" crate-type = ["cdylib"] diff --git a/pytests/pyo3-benchmarks/README.md b/pytests/pyo3-benchmarks/README.md index 5317d4ec..2d7c33ea 100644 --- a/pytests/pyo3-benchmarks/README.md +++ b/pytests/pyo3-benchmarks/README.md @@ -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 ``` diff --git a/pytests/pyo3-benchmarks/noxfile.py b/pytests/pyo3-benchmarks/noxfile.py index 23e6efe1..39230d26 100644 --- a/pytests/pyo3-benchmarks/noxfile.py +++ b/pytests/pyo3-benchmarks/noxfile.py @@ -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") diff --git a/pytests/pyo3-benchmarks/pyo3_benchmarks/__init__.py b/pytests/pyo3-benchmarks/pyo3_benchmarks/__init__.py deleted file mode 100644 index cd0f9b65..00000000 --- a/pytests/pyo3-benchmarks/pyo3_benchmarks/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from ._pyo3_benchmarks import * diff --git a/pytests/pyo3-benchmarks/pyproject.toml b/pytests/pyo3-benchmarks/pyproject.toml new file mode 100644 index 00000000..79ac372f --- /dev/null +++ b/pytests/pyo3-benchmarks/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = ["maturin>=0.12,<0.13"] +build-backend = "maturin" + +[tool.pytest.ini_options] +addopts = "--benchmark-disable" diff --git a/pytests/pyo3-benchmarks/setup.py b/pytests/pyo3-benchmarks/setup.py deleted file mode 100644 index f38bebdf..00000000 --- a/pytests/pyo3-benchmarks/setup.py +++ /dev/null @@ -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, -) diff --git a/pytests/pyo3-benchmarks/src/lib.rs b/pytests/pyo3-benchmarks/src/lib.rs index e649fd1c..1f858091 100644 --- a/pytests/pyo3-benchmarks/src/lib.rs +++ b/pytests/pyo3-benchmarks/src/lib.rs @@ -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)?)?; diff --git a/pytests/pyo3-pytests/pyproject.toml b/pytests/pyo3-pytests/pyproject.toml index 5f0a84ee..256b3705 100644 --- a/pytests/pyo3-pytests/pyproject.toml +++ b/pytests/pyo3-pytests/pyproject.toml @@ -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"