diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 3429c6c3..8a3782ca 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -5,11 +5,9 @@ Please consider adding the following to your pull request: - docs to all new functions and / or detail in the guide - tests for all new or changed functions -Be aware the CI pipeline will check your pull request for the following: - - Rust tests (Just `cargo test` or `make test` if you need to test examples) - - Rust lints (`make clippy`) - - Rust formatting (`cargo fmt`) - - Python formatting (`black . --check`. You can install black with `pip install black`) - - Compatibility with all supported Python versions for all examples. This uses `tox`; you can do run it using `cargo xtask test-py`. - -You can run a similar set of checks as the CI pipeline using `make test`. +Be aware the CI pipeline will check your pull request for the following. This is done using `nox` (you can install with `pip install nox`): + - Rust tests (`cargo test` or `nox -s test-rust`) + - Examples (`nox -s test-py`) + - Rust lints (`nox -s clippy`) + - Rust formatting (`nox -s fmt-rust`) + - Python formatting (`nox -s fmt-py`) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf4f018c..055b9152 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,27 +15,29 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 - - run: pip install black==21.12b0 + - run: pip install nox - uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal components: rustfmt - name: Check python formatting (black) - run: make fmt_py + run: nox -s fmt-py - name: Check rust formatting (rustfmt) - run: make fmt_rust + run: nox -s fmt-rust clippy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: pip install nox - uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal components: clippy - - run: make clippy + - run: nox -s clippy check-target: needs: [fmt] diff --git a/Makefile b/Makefile deleted file mode 100644 index 668807e3..00000000 --- a/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -.PHONY: test test_py publish clippy lint fmt fmt_py fmt_rust - -ALL_ADDITIVE_FEATURES = macros multiple-pymethods num-bigint num-complex hashbrown serde indexmap eyre anyhow -COVERAGE_PACKAGES = --package pyo3 --package pyo3-build-config --package pyo3-macros-backend --package pyo3-macros - -test: lint test_py - cargo test - cargo test --features="abi3" - cargo test --features="$(ALL_ADDITIVE_FEATURES)" - cargo test --features="abi3 $(ALL_ADDITIVE_FEATURES)" - -test_py: - @for example in examples/*/noxfile.py; do echo "-- Running nox for $$example --"; nox -f $$example/noxfile.py || exit 1; echo ""; done - echo "-- Running nox for pytests/noxfile.py --"; - nox -f pytests/noxfile.py || exit 1; - -fmt_py: - black . --check - -fmt_rust: - cargo fmt --all -- --check - -fmt: fmt_rust fmt_py - @true - -clippy: - cargo clippy --features="$(ALL_ADDITIVE_FEATURES)" --all-targets --workspace -- -Dwarnings - cargo clippy --features="abi3 $(ALL_ADDITIVE_FEATURES)" --all-targets --workspace -- -Dwarnings - for example in examples/*/; do cargo clippy --manifest-path $$example/Cargo.toml -- -Dwarnings || exit 1; done - -lint: fmt clippy - @true - -publish: test - cargo publish --manifest-path pyo3-build-config/Cargo.toml - sleep 10 - cargo publish --manifest-path pyo3-macros-backend/Cargo.toml - sleep 10 # wait for crates.io to update - cargo publish --manifest-path pyo3-macros/Cargo.toml - sleep 10 # wait for crates.io to update - cargo publish diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 00000000..f6b85e1b --- /dev/null +++ b/noxfile.py @@ -0,0 +1,88 @@ +import time +from glob import glob + +import nox + +nox.options.sessions = ["test", "clippy", "fmt"] + + +@nox.session(venv_backend="none") +def test(session: nox.Session): + test_rust(session) + test_py(session) + + +@nox.session(name="test-rust", venv_backend="none") +def test_rust(session: nox.Session): + session.run("cargo", "test", external=True) + session.run("cargo", "test", "--features=abi3", external=True) + session.run("cargo", "test", "--features=full", external=True) + session.run("cargo", "test", "--features=abi3 full", external=True) + + +@nox.session(name="test-py", venv_backend="none") +def test_py(session): + session.run("nox", "-f", "pytests/noxfile.py", external=True) + for example in glob("examples/*/noxfile.py"): + session.run("nox", "-f", example, external=True) + + +@nox.session +def fmt(session: nox.Session): + fmt_rust(session) + fmt_py(session) + + +@nox.session(name="fmt-rust", venv_backend="none") +def fmt_rust(session: nox.Session): + session.run("cargo", "fmt", "--all", "--check", external=True) + + +@nox.session(name="fmt-py") +def fmt_py(session: nox.Session): + session.install("black==22.1.0") + session.run("black", ".", "--check") + + +@nox.session(venv_backend="none") +def clippy(session: nox.Session) -> None: + for feature_set in ["full", "abi3 full"]: + session.run( + "cargo", + "clippy", + f"--features={feature_set}", + "--all-targets", + "--workspace", + "--", + "--deny=warnings", + external=True, + ) + + +@nox.session(venv_backend="none") +def publish(session: nox.Session) -> None: + session.run( + "cargo", + "publish", + "--manifest-path", + "pyo3-build-config/Cargo.toml", + external=True, + ) + time.sleep(10) + session.run( + "cargo", + "publish", + "--manifest-path", + "pyo3-macros-backend/Cargo.toml", + external=True, + ) + time.sleep(10) + session.run( + "cargo", "publish", "--manifest-path", "pyo3-macros/Cargo.toml", external=True + ) + time.sleep(10) + session.run( + "cargo", "publish", "--manifest-path", "pyo3-ffi/Cargo.toml", external=True + ) + time.sleep(10) + session.run("cargo", "publish", external=True) diff --git a/pytests/tests/test_othermod.py b/pytests/tests/test_othermod.py index 08ac367a..ff67bba4 100644 --- a/pytests/tests/test_othermod.py +++ b/pytests/tests/test_othermod.py @@ -3,14 +3,14 @@ from hypothesis import strategies as st from pyo3_pytests import othermod -INTEGER32_ST = st.integers(min_value=(-(2 ** 31)), max_value=(2 ** 31 - 1)) +INTEGER32_ST = st.integers(min_value=(-(2**31)), max_value=(2**31 - 1)) USIZE_ST = st.integers(min_value=othermod.USIZE_MIN, max_value=othermod.USIZE_MAX) @given(x=INTEGER32_ST) def test_double(x): expected = x * 2 - assume(-(2 ** 31) <= expected <= (2 ** 31 - 1)) + assume(-(2**31) <= expected <= (2**31 - 1)) assert othermod.double(x) == expected