From 7d881f0214f9761990e52595d33246700c4da15c Mon Sep 17 00:00:00 2001 From: Tim Orling Date: Sat, 16 Dec 2023 21:41:33 -0800 Subject: oeqa: add "maturin develop" SDK test case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'maturin develop' first checks that a virtual environment has been created, which is a good test for our python3 SDK environment ;) Source for guessing-game lifted from https://www.maturin.rs/tutorial The test case is expected to fetch any necessary crates, build a development version of the crate and package it as a wheel Needs at a minimum the following in e.g. local.conf: TOOLCHAIN_HOST_TASK:append = " nativesdk-python3-maturin" SDK_INCLUDE_TOOLCHAIN = '1' SDK_TOOLCHAIN_LANGS += 'rust' The output of 'maturin develop' should be something like: ... 🔗 Found pyo3 bindings with abi3 support for Python ≥ 3.8 🐍 Not using a specific python interpreter 📡 Using build options features from pyproject.toml ... Compiling guessing-game v0.1.0 (/path/to/guessing-game) Finished dev [unoptimized + debuginfo] target(s) in 7.14s 📦 Built wheel for abi3 Python ≥ 3.8 to /path/to/tmpdir/guessing_game-0.1.0-cp38-abi3-linux_x86_64.whl 🛠 Installed guessing-game-0.1.0 (From OE-Core rev: 5265dd0b102cd7f3c6bb2ae1b18e9f625b834b39) Signed-off-by: Tim Orling Signed-off-by: Richard Purdie --- meta/lib/oeqa/sdk/cases/maturin.py | 48 +++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'meta/lib/oeqa/sdk') diff --git a/meta/lib/oeqa/sdk/cases/maturin.py b/meta/lib/oeqa/sdk/cases/maturin.py index 14245bc36e..ea10f568b2 100644 --- a/meta/lib/oeqa/sdk/cases/maturin.py +++ b/meta/lib/oeqa/sdk/cases/maturin.py @@ -4,9 +4,12 @@ # SPDX-License-Identifier: MIT # +import os +import shutil import unittest -from oeqa.sdk.case import OESDKTestCase +from oeqa.core.utils.path import remove_safe +from oeqa.sdk.case import OESDKTestCase from oeqa.utils.subprocesstweak import errors_have_output errors_have_output() @@ -31,3 +34,46 @@ class MaturinTest(OESDKTestCase): output, r" - CPython %s (.+)/usr/bin/python%s$" % (python_version, python_version), ) + + +class MaturinDevelopTest(OESDKTestCase): + @classmethod + def setUpClass(self): + targetdir = os.path.join(self.tc.sdk_dir, "guessing-game") + try: + shutil.rmtree(targetdir) + except FileNotFoundError: + pass + shutil.copytree( + os.path.join(self.tc.files_dir, "maturin/guessing-game"), targetdir + ) + + def setUp(self): + machine = self.td.get("MACHINE") + if not ( + self.tc.hasHostPackage("nativesdk-python3-maturin") + or self.tc.hasHostPackage("python3-maturin-native") + ): + raise unittest.SkipTest("No python3-maturin package in the SDK") + if not ( + self.tc.hasHostPackage("packagegroup-rust-cross-canadian-%s" % machine) + ): + raise unittest.SkipTest( + "Testing 'maturin develop' requires Rust cross-canadian in the SDK" + ) + + def test_maturin_develop(self): + """ + This test case requires: + (1) that a .venv can been created. + (2) a functional 'rustc' and 'cargo' + """ + self._run("cd %s/guessing-game; python3 -m venv .venv" % self.tc.sdk_dir) + cmd = "cd %s/guessing-game; maturin develop" % self.tc.sdk_dir + output = self._run(cmd) + self.assertRegex(output, r"🔗 Found pyo3 bindings with abi3 support for Python ≥ 3.8") + self.assertRegex(output, r"🐍 Not using a specific python interpreter") + self.assertRegex(output, r"📡 Using build options features from pyproject.toml") + self.assertRegex(output, r"Compiling guessing-game v0.1.0") + self.assertRegex(output, r"📦 Built wheel for abi3 Python ≥ 3.8") + self.assertRegex(output, r"🛠 Installed guessing-game-0.1.0") -- cgit v1.2.3-54-g00ecf