diff --git a/.github/workflows/test_client.yaml b/.github/workflows/test_client.yaml index e179d307b..f6139dce1 100644 --- a/.github/workflows/test_client.yaml +++ b/.github/workflows/test_client.yaml @@ -84,5 +84,7 @@ jobs: python-version: "3.13" - name: Install tox run: pip install tox - - name: Run tox - run: tox + - name: Lint + run: tox run -e lint + - name: Unit + run: tox run -e unit diff --git a/.github/workflows/tics.yml b/.github/workflows/tics.yml index 74e9926df..cb8c5c51b 100644 --- a/.github/workflows/tics.yml +++ b/.github/workflows/tics.yml @@ -23,7 +23,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y pipx pkgconf libssl-dev build-essential + sudo apt-get install -y pipx pkgconf python3-maturin libssl-dev build-essential # Client - name: Install Rust toolchain @@ -39,6 +39,9 @@ jobs: - name: Build (client) working-directory: client run: cargo build --all-features + - name: Install (client pybindings) + working-directory: client + run: pip install . --break-system-packages # Server - name: Set up uv diff --git a/client/.gitignore b/client/.gitignore index f3d5d011e..8b4aad15e 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -5,3 +5,7 @@ __pycache__/ *.profraw *.profdata coverage* +.tox/ +.ruff_cache/ +.mypy_cache/ +.venv/ diff --git a/client/CONTRIBUTING.md b/client/CONTRIBUTING.md index 4d8ffbf48..44d7005d0 100644 --- a/client/CONTRIBUTING.md +++ b/client/CONTRIBUTING.md @@ -34,15 +34,14 @@ sudo snap connect hwctl:system-observe ## Use Python Bindings The `hwlib` library can be used in Python code as well. We're using the -[`pyo3`][pyo3] library to create Python bindings; to build them, you need to -have [`maturin`][maturin] installed on your system. It requires a virtual -environment to be configured to work with it: +[`pyo3`][pyo3] library to create Python bindings and [`maturin`][maturin] to +build the Python library. It requires a virtual environment to be configured to +work with it: ```shell -virtualenv venv -source venv/bin/activate -pip install maturin -maturin develop --features pybindings +python3 -m venv .venv +source .venv/bin/activate +pip install . ``` Now you can use the library in your Python code. The library requires root diff --git a/client/pyproject.toml b/client/pyproject.toml new file mode 100644 index 000000000..493e1f974 --- /dev/null +++ b/client/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = ["maturin>=1.9,<2.0"] +build-backend = "maturin" + +[tool.maturin] +features = ["pybindings"] diff --git a/client/tox.ini b/client/tox.ini index 3dd94fe61..e201b693a 100644 --- a/client/tox.ini +++ b/client/tox.ini @@ -1,17 +1,25 @@ [tox] -envlist = py -skipsdist = true +env_list = format, lint, unit +[testenv:format] +description = Apply coding standards to code +deps = + ruff +commands = + ruff check --fix + ruff format -[testenv] +[testenv:lint] +description = Check code against coding stle standards deps = - black ruff +commands = + ruff check + ruff format --check + +[testenv:unit] +description = Run unit tests +deps = pytest - maturin -commands_pre = - {envbindir}/maturin develop --features pybindings commands = - {envbindir}/python -m black --check pytests/ - {envbindir}/python -m ruff check pytests/ - {envbindir}/python -m pytest pytests/ + pytest pytests