From a5ef9ff64aecdd6d516b0ed0786568d7a0035141 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 9 Dec 2021 08:11:28 +0000 Subject: [PATCH 1/2] ci: clippy whole workspace --- Makefile | 4 ++-- examples/pyo3-pytests/src/buf_and_str.rs | 2 ++ examples/pyo3-pytests/src/datetime.rs | 2 ++ examples/pyo3-pytests/src/lib.rs | 4 ++++ pyo3-build-config/src/impl_.rs | 8 ++++---- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 485cbe0c..c43a0471 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ fmt: black . --check clippy: - cargo clippy --features="$(ALL_ADDITIVE_FEATURES)" --tests -- -Dwarnings - cargo clippy --features="abi3 $(ALL_ADDITIVE_FEATURES)" --tests -- -Dwarnings + 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 diff --git a/examples/pyo3-pytests/src/buf_and_str.rs b/examples/pyo3-pytests/src/buf_and_str.rs index 76e53093..47d74d38 100644 --- a/examples/pyo3-pytests/src/buf_and_str.rs +++ b/examples/pyo3-pytests/src/buf_and_str.rs @@ -1,3 +1,5 @@ +#![cfg(not(Py_LIMITED_API))] + //! Objects related to PyBuffer and PyStr use pyo3::buffer::PyBuffer; use pyo3::prelude::*; diff --git a/examples/pyo3-pytests/src/datetime.rs b/examples/pyo3-pytests/src/datetime.rs index a3522b48..0dfc7868 100644 --- a/examples/pyo3-pytests/src/datetime.rs +++ b/examples/pyo3-pytests/src/datetime.rs @@ -1,3 +1,5 @@ +#![cfg(not(Py_LIMITED_API))] + use pyo3::prelude::*; use pyo3::types::{ PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess, PyTuple, diff --git a/examples/pyo3-pytests/src/lib.rs b/examples/pyo3-pytests/src/lib.rs index ed0b8180..3501e84f 100644 --- a/examples/pyo3-pytests/src/lib.rs +++ b/examples/pyo3-pytests/src/lib.rs @@ -12,7 +12,9 @@ pub mod path; pub mod pyclass_iter; pub mod subclassing; +#[cfg(not(Py_LIMITED_API))] use buf_and_str::*; +#[cfg(not(Py_LIMITED_API))] use datetime::*; use dict_iter::*; use misc::*; @@ -24,7 +26,9 @@ use subclassing::*; #[pymodule] fn pyo3_pytests(py: Python, m: &PyModule) -> PyResult<()> { + #[cfg(not(Py_LIMITED_API))] m.add_wrapped(wrap_pymodule!(buf_and_str))?; + #[cfg(not(Py_LIMITED_API))] m.add_wrapped(wrap_pymodule!(datetime))?; m.add_wrapped(wrap_pymodule!(dict_iter))?; m.add_wrapped(wrap_pymodule!(misc))?; diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index b175b974..c48d5569 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -1530,11 +1530,11 @@ mod tests { fn test_venv_interpreter() { let base = OsStr::new("base"); assert_eq!( - venv_interpreter(&base, true), + venv_interpreter(base, true), PathBuf::from_iter(&["base", "Scripts", "python.exe"]) ); assert_eq!( - venv_interpreter(&base, false), + venv_interpreter(base, false), PathBuf::from_iter(&["base", "bin", "python"]) ); } @@ -1543,11 +1543,11 @@ mod tests { fn test_conda_env_interpreter() { let base = OsStr::new("base"); assert_eq!( - conda_env_interpreter(&base, true), + conda_env_interpreter(base, true), PathBuf::from_iter(&["base", "python.exe"]) ); assert_eq!( - conda_env_interpreter(&base, false), + conda_env_interpreter(base, false), PathBuf::from_iter(&["base", "bin", "python"]) ); } From cbe2b2a3618389c42df47c88dea546d612984c7f Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 9 Dec 2021 08:17:08 +0000 Subject: [PATCH 2/2] ci: use makefile for fmt --- .github/workflows/ci.yml | 6 +++--- Makefile | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8808716..f8b7b732 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,16 +15,16 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 - - run: pip install black==20.8b1 + - run: pip install black==21.12b0 - uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal components: rustfmt - name: Check python formatting (black) - run: black --check . + run: make fmt_py - name: Check rust formatting (rustfmt) - run: cargo fmt --all -- --check + run: make fmt_rust clippy: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index c43a0471..fcf40243 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: test test_py publish clippy lint fmt +.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 @@ -14,10 +14,15 @@ test: lint test_py test_py: for example in examples/*/; do TOX_TESTENV_PASSENV=RUSTUP_HOME tox -e py -c $$example || exit 1; done -fmt: - cargo fmt --all -- --check +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