From 48c16a687809b47d1c35f52373f375ff5e19cae9 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Mon, 26 Jun 2023 22:26:37 +0100 Subject: [PATCH 1/2] move pyo3-ffi-check into its own workspace --- .github/workflows/build.yml | 2 +- Cargo.toml | 2 -- noxfile.py | 25 +++++++++++++------------ pyo3-ffi-check/Cargo.toml | 7 ++++++- pyo3-ffi-check/macro/Cargo.toml | 2 +- pyo3-ffi-check/src/main.rs | 3 ++- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3cde2f87..49e49102 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -136,10 +136,10 @@ jobs: - '.github/workflows/build.yml' - name: Run pyo3-ffi-check - run: nox -s ffi-check # pypy 3.7 and 3.8 are not PEP 3123 compliant so fail checks here, nor # is pypy 3.9 on windows if: ${{ steps.ffi-changes.outputs.changed == 'true' && inputs.rust == 'stable' && inputs.python-version != 'pypy3.7' && inputs.python-version != 'pypy3.8' && !(inputs.python-version == 'pypy3.9' && contains(inputs.os, 'windows')) }} + run: nox -s ffi-check - name: Test cross compilation diff --git a/Cargo.toml b/Cargo.toml index cefc8652..253e2c8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -179,8 +179,6 @@ harness = false [workspace] members = [ "pyo3-ffi", - "pyo3-ffi-check", - "pyo3-ffi-check/macro", "pyo3-build-config", "pyo3-macros", "pyo3-macros-backend", diff --git a/noxfile.py b/noxfile.py index bde39621..6fe7a8f7 100644 --- a/noxfile.py +++ b/noxfile.py @@ -34,7 +34,7 @@ def test_rust(session: nox.Session): _run_cargo_test(session) _run_cargo_test(session, features="abi3") - if not "skip-full" in session.posargs: + if "skip-full" not in session.posargs: _run_cargo_test(session, features="full") _run_cargo_test(session, features="abi3 full") @@ -76,7 +76,8 @@ def fmt(session: nox.Session): @nox.session(name="fmt-rust", venv_backend="none") def fmt_rust(session: nox.Session): - _run(session, "cargo", "fmt", "--all", "--check", external=True) + _run_cargo(session, "fmt", "--all", "--check") + _run_cargo(session, "fmt", *_FFI_CHECK, "--all", "--check") @nox.session(name="fmt-py") @@ -103,9 +104,6 @@ def _clippy(session: nox.Session, *, env: Dict[str, str] = None) -> bool: *feature_set, "--all-targets", "--workspace", - # linting pyo3-ffi-check requires docs to have been built or - # the macros will error; doesn't seem worth it on CI - "--exclude=pyo3-ffi-check", "--", "--deny=warnings", external=True, @@ -146,9 +144,6 @@ def check_all(session: nox.Session) -> None: *feature_set, "--all-targets", "--workspace", - # linting pyo3-ffi-check requires docs to have been built or - # the macros will error; doesn't seem worth it on CI - "--exclude=pyo3-ffi-check", external=True, env=env, ) @@ -339,8 +334,6 @@ def format_guide(session: nox.Session): for path in Path("guide").glob("**/*.md"): session.log("Working on %s", path) - content = path.read_text() - lines = iter(path.read_text().splitlines(True)) new_lines = [] @@ -534,8 +527,9 @@ def set_minimal_package_versions(session: nox.Session): @nox.session(name="ffi-check") def ffi_check(session: nox.Session): - session.run("cargo", "doc", "-p", "pyo3-ffi", "--no-deps", external=True) - _run(session, "cargo", "run", "-p", "pyo3-ffi-check", external=True) + _run_cargo(session, "doc", *_FFI_CHECK, "-p", "pyo3-ffi", "--no-deps") + _run_cargo(session, "clippy", "--workspace", "--all-targets", *_FFI_CHECK) + _run_cargo(session, "run", *_FFI_CHECK) @lru_cache() @@ -617,6 +611,10 @@ def _run(session: nox.Session, *args: str, **kwargs: Any) -> None: print("::endgroup::", file=sys.stderr) +def _run_cargo(session: nox.Session, *args: str, **kwargs: Any) -> None: + _run(session, "cargo", *args, **kwargs, external=True) + + def _run_cargo_test( session: nox.Session, *, @@ -685,3 +683,6 @@ suppress_build_script_link_lines=true for version in PYPY_VERSIONS: _job_with_config("PyPy", version) + + +_FFI_CHECK = ("--manifest-path", "pyo3-ffi-check/Cargo.toml") diff --git a/pyo3-ffi-check/Cargo.toml b/pyo3-ffi-check/Cargo.toml index d08a1910..776add0c 100644 --- a/pyo3-ffi-check/Cargo.toml +++ b/pyo3-ffi-check/Cargo.toml @@ -13,5 +13,10 @@ path = "../pyo3-ffi" features = ["extension-module"] # A lazy way of skipping linking in most cases (as we don't use any runtime symbols) [build-dependencies] -bindgen = "0.65.1" +bindgen = "0.66.1" pyo3-build-config = { path = "../pyo3-build-config" } + +[workspace] +members = [ + "macro" +] diff --git a/pyo3-ffi-check/macro/Cargo.toml b/pyo3-ffi-check/macro/Cargo.toml index c2243f30..359e7337 100644 --- a/pyo3-ffi-check/macro/Cargo.toml +++ b/pyo3-ffi-check/macro/Cargo.toml @@ -11,4 +11,4 @@ proc-macro = true glob = "0.3" quote = "1" proc-macro2 = "1" -scraper = "0.12" +scraper = "0.17" diff --git a/pyo3-ffi-check/src/main.rs b/pyo3-ffi-check/src/main.rs index 36af5c16..91a7dca6 100644 --- a/pyo3-ffi-check/src/main.rs +++ b/pyo3-ffi-check/src/main.rs @@ -78,7 +78,8 @@ fn main() { non_camel_case_types, non_upper_case_globals, dead_code, - improper_ctypes + improper_ctypes, + clippy::all )] mod bindings { include!(concat!(env!("OUT_DIR"), "/bindings.rs")); From a0aa9ce92e52552a00310ba80d6b1c17ae86662a Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:57:01 +0100 Subject: [PATCH 2/2] use _run_cargo helper in noxfile --- noxfile.py | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/noxfile.py b/noxfile.py index 6fe7a8f7..52303a2f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -49,11 +49,10 @@ def test_py(session: nox.Session) -> None: @nox.session(venv_backend="none") def coverage(session: nox.Session) -> None: session.env.update(_get_coverage_env()) - _run(session, "cargo", "llvm-cov", "clean", "--workspace", external=True) + _run_cargo(session, "llvm-cov", "clean", "--workspace") test(session) - _run( + _run_cargo( session, - "cargo", "llvm-cov", "--package=pyo3", "--package=pyo3-build-config", @@ -64,7 +63,6 @@ def coverage(session: nox.Session) -> None: "--codecov", "--output-path", "coverage.json", - external=True, ) @@ -97,16 +95,14 @@ def _clippy(session: nox.Session, *, env: Dict[str, str] = None) -> bool: env = env or os.environ for feature_set in _get_feature_sets(): try: - _run( + _run_cargo( session, - "cargo", "clippy", *feature_set, "--all-targets", "--workspace", "--", "--deny=warnings", - external=True, env=env, ) except Exception: @@ -134,17 +130,14 @@ def check_all(session: nox.Session) -> None: def _check(env: Dict[str, str]) -> None: nonlocal success - env = env or os.environ for feature_set in _get_feature_sets(): try: - _run( + _run_cargo( session, - "cargo", "check", *feature_set, "--all-targets", "--workspace", - external=True, env=env, ) except Exception: @@ -308,9 +301,8 @@ def docs(session: nox.Session) -> None: rustdoc_flags.append(session.env.get("RUSTDOCFLAGS", "")) session.env["RUSTDOCFLAGS"] = " ".join(rustdoc_flags) - _run( + _run_cargo( session, - "cargo", *toolchain_flags, "doc", "--lib", @@ -319,7 +311,6 @@ def docs(session: nox.Session) -> None: "--no-deps", "--workspace", *cargo_flags, - external=True, ) @@ -380,9 +371,8 @@ def format_guide(session: nox.Session): @nox.session(name="address-sanitizer", venv_backend="none") def address_sanitizer(session: nox.Session): - _run( + _run_cargo( session, - "cargo", "+nightly", "test", "--release", @@ -395,7 +385,6 @@ def address_sanitizer(session: nox.Session): "RUSTDOCFLAGS": "-Zsanitizer=address", "ASAN_OPTIONS": "detect_leaks=0", }, - external=True, ) @@ -471,15 +460,9 @@ def set_minimal_package_versions(session: nox.Session): # possible version, so that this matches what CI will resolve to. for project in projects: if project is None: - _run(session, "cargo", "update", external=True) + _run_cargo(session, "update") else: - _run( - session, - "cargo", - "update", - f"--manifest-path={project}/Cargo.toml", - external=True, - ) + _run_cargo(session, "update", f"--manifest-path={project}/Cargo.toml") for project in projects: lock_file = Path(project or "") / "Cargo.lock" @@ -513,15 +496,13 @@ def set_minimal_package_versions(session: nox.Session): # supported on MSRV for project in projects: if project is None: - _run(session, "cargo", "metadata", silent=True, external=True) + _run_cargo(session, "metadata", silent=True) else: - _run( + _run_cargo( session, - "cargo", "metadata", f"--manifest-path={project}/Cargo.toml", silent=True, - external=True, ) @@ -636,7 +617,7 @@ def _run_cargo_test( def _run_cargo_publish(session: nox.Session, *, package: str) -> None: - _run(session, "cargo", "publish", f"--package={package}", external=True) + _run_cargo(session, "publish", f"--package={package}") def _run_cargo_set_package_version(