From a1aedafd4151495d61876ef35cbc79fad01be29a Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Wed, 11 Sep 2024 09:06:55 +0200 Subject: [PATCH 01/21] removing duplicate from example --- examples/example_parsing_user_data.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/example_parsing_user_data.rs b/examples/example_parsing_user_data.rs index 6b25a59..8c1928c 100644 --- a/examples/example_parsing_user_data.rs +++ b/examples/example_parsing_user_data.rs @@ -2,7 +2,6 @@ use m_bus_parser::user_data::DataRecords; fn main() { /* Data block 1: unit 0, storage No 0, no tariff, instantaneous volume, 12565 l (24 bit integer) */ - /* Data block 2: unit 0, storage No 0, no tariff, instantaneous volume, 12565 l (24 bit integer) */ let data = vec![0x03, 0x13, 0x15, 0x31, 0x00, 0x03, 0x13, 0x15, 0x31, 0x00]; let result = DataRecords::try_from(data.as_slice()); assert!(result.is_ok()); From 8b3ead140121f1456c35dd2c2541be05f1d347c5 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Wed, 11 Sep 2024 09:07:27 +0200 Subject: [PATCH 02/21] adding first stub of bindings --- Cargo.toml | 2 +- python/.gitignore | 1 + python/Cargo.toml | 15 +++++++++++++++ python/README.md | 8 ++++++++ python/pyproject.toml | 17 +++++++++++++++++ python/src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 python/.gitignore create mode 100644 python/Cargo.toml create mode 100644 python/README.md create mode 100644 python/pyproject.toml create mode 100644 python/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 51124c6..e5a811f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ serde = { version = "1.0", features = ["derive"], optional = true } bitflags = "2.4.2" arrayvec = { version = "0.7.4", default-features = false } [workspace] -members = ["cli", "wasm"] +members = ["cli", "wasm","python"] exclude = ["examples/cortex-m"] [[bench]] diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/python/.gitignore @@ -0,0 +1 @@ +/target diff --git a/python/Cargo.toml b/python/Cargo.toml new file mode 100644 index 0000000..18ece6d --- /dev/null +++ b/python/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "py-m-bus-parser" +version = "0.1.1" +edition = "2021" +homepage = "https://maebli.github.io/" +repository = "https://github.com/maebli/m-bus-parser" + +[dependencies] +m-bus-parser = { path = "..", version = "0.0.13", features = ["std", "serde"] } +serde_json = "1.0" +pyo3 = { version = "0.22.2", features = ["extension-module"] } +hex = "0.4.2" + +[lib] +name = "m_bus_parser" \ No newline at end of file diff --git a/python/README.md b/python/README.md new file mode 100644 index 0000000..f56cacc --- /dev/null +++ b/python/README.md @@ -0,0 +1,8 @@ +# Python bindings [WIP] + +Rust lib aims to be accessible from a Python module. This is done by using the `PyO3` crate. + +## Development + +- `pipx install maturin` to install `maturin` globally. +- `maturin develop` to build the Rust lib and create a Python module in the current environment. diff --git a/python/pyproject.toml b/python/pyproject.toml new file mode 100644 index 0000000..7192672 --- /dev/null +++ b/python/pyproject.toml @@ -0,0 +1,17 @@ +[tool.poetry] +name = "py-m-bus-parser" +version = "0.1.0" +description = "Python bindings for m-bus-parser written in Rust" +readme = "README.md" +website = "github.com/maebli/m-bus-parser" +authors = ["Michael Aebli"] +license = "MIT" + + +[tool.poetry.dependencies] +python = "^3.9" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/python/src/lib.rs b/python/src/lib.rs new file mode 100644 index 0000000..a917d73 --- /dev/null +++ b/python/src/lib.rs @@ -0,0 +1,39 @@ +use hex; +use m_bus_parser::user_data::DataRecords; +use pyo3::prelude::*; +use serde_json; + +#[pyfunction] +fn parse_application_layer(data_record: &str) -> PyResult { + // Decode the hex string into bytes + match hex::decode(data_record) { + Ok(bytes) => { + // Try to parse the bytes into DataRecords + match DataRecords::try_from(bytes.as_slice()) { + Ok(records) => { + // Serialize the records to JSON using Serde + match serde_json::to_string(&records) { + Ok(json) => Ok(json), + Err(e) => Err(PyErr::new::(format!( + "Failed to serialize records to JSON: {}", + e + ))), + } + } + Err(_) => Err(PyErr::new::( + "Failed to parse data record", + )), + } + } + Err(e) => Err(PyErr::new::(format!( + "Failed to decode hex: {}", + e + ))), + } +} + +#[pymodule] +fn py_m_bus_parser(m: &Bound<'_, PyModule>) -> PyResult<()> { + m.add_function(wrap_pyfunction!(parse_application_layer, m)?)?; + Ok(()) +} From 473b0b4635e16e36008cf7058ef32950562451e2 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Wed, 11 Sep 2024 10:14:21 +0200 Subject: [PATCH 03/21] adding a further function works now --- python/Cargo.toml | 4 ++-- python/README.md | 3 +++ python/pyproject.toml | 16 ++++++---------- python/src/lib.rs | 9 ++++++++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/python/Cargo.toml b/python/Cargo.toml index 18ece6d..cdb4b05 100644 --- a/python/Cargo.toml +++ b/python/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "py-m-bus-parser" +name = "pymbusparser" version = "0.1.1" edition = "2021" homepage = "https://maebli.github.io/" @@ -12,4 +12,4 @@ pyo3 = { version = "0.22.2", features = ["extension-module"] } hex = "0.4.2" [lib] -name = "m_bus_parser" \ No newline at end of file +name = "pymbusparser" \ No newline at end of file diff --git a/python/README.md b/python/README.md index f56cacc..4928318 100644 --- a/python/README.md +++ b/python/README.md @@ -6,3 +6,6 @@ Rust lib aims to be accessible from a Python module. This is done by using the ` - `pipx install maturin` to install `maturin` globally. - `maturin develop` to build the Rust lib and create a Python module in the current environment. +- Currently this creates a release in the target directory that is one hierachy up. This is not ideal and will be fixed in the future. +- after calling the maturin develop command cd one up and `pip install target/..` and then run `python` and `from pymbusparser import pymbus` to test the module. +- to test inside `REPL` run `python` and then `import p \ No newline at end of file diff --git a/python/pyproject.toml b/python/pyproject.toml index 7192672..6354283 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,17 +1,13 @@ -[tool.poetry] -name = "py-m-bus-parser" +[project] +name = "pymbusparser" version = "0.1.0" description = "Python bindings for m-bus-parser written in Rust" readme = "README.md" -website = "github.com/maebli/m-bus-parser" -authors = ["Michael Aebli"] +# name and email +authors = [{name = "Michael Aebli", email = ""}] license = "MIT" -[tool.poetry.dependencies] -python = "^3.9" - - [build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" +requires = ["maturin>=1.0,<2.0"] +build-backend = "maturin" \ No newline at end of file diff --git a/python/src/lib.rs b/python/src/lib.rs index a917d73..0fe17a8 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -1,4 +1,5 @@ use hex; +use m_bus_parser::serialize_mbus_data; use m_bus_parser::user_data::DataRecords; use pyo3::prelude::*; use serde_json; @@ -32,8 +33,14 @@ fn parse_application_layer(data_record: &str) -> PyResult { } } +#[pyfunction] +pub fn m_bus_parse(data: &str, format: &str) -> String { + serialize_mbus_data(data, format) +} + #[pymodule] -fn py_m_bus_parser(m: &Bound<'_, PyModule>) -> PyResult<()> { +fn pymbusparser(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(parse_application_layer, m)?)?; + m.add_function(wrap_pyfunction!(m_bus_parse, m)?)?; Ok(()) } From d96c498bce6bee68950672635d56b92548487ff9 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Wed, 11 Sep 2024 10:15:37 +0200 Subject: [PATCH 04/21] changing version to 0.0.0 --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 6354283..39c0356 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pymbusparser" -version = "0.1.0" +version = "0.0.0" description = "Python bindings for m-bus-parser written in Rust" readme = "README.md" # name and email From 7cab1762fa6a743d6371f887674e19dd7a858339 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Wed, 11 Sep 2024 10:19:19 +0200 Subject: [PATCH 05/21] trying to fix publish of py package --- python/Cargo.toml | 2 +- python/pyproject.toml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/python/Cargo.toml b/python/Cargo.toml index cdb4b05..c6e1d8c 100644 --- a/python/Cargo.toml +++ b/python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pymbusparser" -version = "0.1.1" +version = "0.0.0" edition = "2021" homepage = "https://maebli.github.io/" repository = "https://github.com/maebli/m-bus-parser" diff --git a/python/pyproject.toml b/python/pyproject.toml index 39c0356..13d0db8 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -2,8 +2,7 @@ name = "pymbusparser" version = "0.0.0" description = "Python bindings for m-bus-parser written in Rust" -readme = "README.md" -# name and email +homepage = "https://maebli.github.io/" authors = [{name = "Michael Aebli", email = ""}] license = "MIT" From 0027bc4f2893ef382c343a6e2c2314fc8a9bf0fc Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Wed, 11 Sep 2024 10:55:53 +0200 Subject: [PATCH 06/21] improving docu --- python/README.md | 11 ----------- python/README_python.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) delete mode 100644 python/README.md create mode 100644 python/README_python.md diff --git a/python/README.md b/python/README.md deleted file mode 100644 index 4928318..0000000 --- a/python/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Python bindings [WIP] - -Rust lib aims to be accessible from a Python module. This is done by using the `PyO3` crate. - -## Development - -- `pipx install maturin` to install `maturin` globally. -- `maturin develop` to build the Rust lib and create a Python module in the current environment. -- Currently this creates a release in the target directory that is one hierachy up. This is not ideal and will be fixed in the future. -- after calling the maturin develop command cd one up and `pip install target/..` and then run `python` and `from pymbusparser import pymbus` to test the module. -- to test inside `REPL` run `python` and then `import p \ No newline at end of file diff --git a/python/README_python.md b/python/README_python.md new file mode 100644 index 0000000..2283225 --- /dev/null +++ b/python/README_python.md @@ -0,0 +1,35 @@ +# Python bindings [WIP] + +Rust lib aims to be accessible from a Python module. This is done by using the `PyO3` crate. + +## Development + +- `pipx install maturin` to install `maturin` globally. +- `maturin develop` to build the Rust lib and create a Python module in the current environment. +- Currently this creates a release in the target directory that is one hierachy up. This is not ideal and will be fixed in the future. +- after calling the maturin develop command cd one up and `pip install target/..` and then run `python` and `from pymbusparser import pymbus` to test the module. +- to test inside `REPL` run `python` and then `import p + +## Publishing + +- `maturin publish` +- username = __token__ +- passwrod = api key from pypi + +## Usage + +`pip install pymbusparser` + +```python +from pymbusparser import m_bus_parse,parse_application_layer + +print(m_bus_parse("68 3D 3D 68 08 01 72 00 51 20 02 82 4D 02 04 00 88 00 00 04 07 00 00 00 00 0C 15 03 00 00 00 0B 2E 00 00 00 0B 3B 00 00 00 0A 5A 88 12 0A 5E 16 05 0B 61 23 77 00 02 6C 8C 11 02 27 37 0D 0F 60 00 67 16","table")) + +print(m_bus_parse("68 3D 3D 68 08 01 72 00 51 20 02 82 4D 02 04 00 88 00 00 04 07 00 00 00 00 0C 15 03 00 00 00 0B 2E 00 00 00 0B 3B 00 00 00 0A 5A 88 12 0A 5E 16 05 0B 61 23 77 00 02 6C 8C 11 02 27 37 0D 0F 60 00 67 16","json")) + +print(m_bus_parse("68 3D 3D 68 08 01 72 00 51 20 02 82 4D 02 04 00 88 00 00 04 07 00 00 00 00 0C 15 03 00 00 00 0B 2E 00 00 00 0B 3B 00 00 00 0A 5A 88 12 0A 5E )16 05 0B 61 23 77 00 02 6C 8C 11 02 27 37 0D 0F 60 00 67 16","yml")) + +# note this is not as pretty as the function before, still TODO, currently it just outputs structs of RUST in string +print(parse_application_layer("2f2f0413fce0f5052f2f2f2f2f2f2f2f")) + +``` \ No newline at end of file From 3d4b621cb2f6c6759f894cb2f218a18bfbea65f6 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Mon, 16 Sep 2024 18:06:04 +0200 Subject: [PATCH 07/21] adding a publish step tot he pipeline --- .github/workflows/rust.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4fde777..716054e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -123,7 +123,17 @@ jobs: cd cli/src cargo publish --token ${{ secrets.CRATESTOKEN }} - + publish-python-bindings: + needs: build-library + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/python-v') + steps: + - name: Install maturin + run: python -m pip install maturin + - name: Build Python bindings + run: maturin build + - name: Publish Python bindings to PyPI + run: maturin publish publish-wasm: needs: build-wasm runs-on: ubuntu-latest From e81834bb261e9220471b805366a45bbedd9022e3 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 13:52:30 +0200 Subject: [PATCH 08/21] changing release --- .github/workflows/rust.yml | 6 +++--- python/pyproject.toml | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 716054e..cb12a75 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -126,12 +126,12 @@ jobs: publish-python-bindings: needs: build-library runs-on: ubuntu-latest + container: + image: ghcr.io/pyo3/maturin if: startsWith(github.ref, 'refs/tags/python-v') steps: - - name: Install maturin - run: python -m pip install maturin - name: Build Python bindings - run: maturin build + run: maturin build --release --target x86_64-unknown-linux-gnu --target aarch64-unknown-linux-gnu --target x86_64-pc-windows-gnu --target universal2-apple-darwin - name: Publish Python bindings to PyPI run: maturin publish publish-wasm: diff --git a/python/pyproject.toml b/python/pyproject.toml index 13d0db8..af9a143 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,10 +1,11 @@ [project] name = "pymbusparser" -version = "0.0.0" +version = "0.0.1" description = "Python bindings for m-bus-parser written in Rust" homepage = "https://maebli.github.io/" authors = [{name = "Michael Aebli", email = ""}] license = "MIT" +readme = "README_python.md" [build-system] From 206efa8bf5d04c8edf466a4d765c94ea4c149f2d Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 14:13:25 +0200 Subject: [PATCH 09/21] fixing license and adding manual pipeline trigger --- .github/workflows/rust.yml | 1 + python/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cb12a75..b45df42 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -9,6 +9,7 @@ on: - 'wasm-v*' pull_request: branches: [main] + workflow_dispatch: jobs: build-library: diff --git a/python/pyproject.toml b/python/pyproject.toml index af9a143..068ca86 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -4,7 +4,7 @@ version = "0.0.1" description = "Python bindings for m-bus-parser written in Rust" homepage = "https://maebli.github.io/" authors = [{name = "Michael Aebli", email = ""}] -license = "MIT" +license = { text = "MIT" } readme = "README_python.md" From b5ff2c2ad85ed4f8571a84c32e0e53c78c20ab1e Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 14:23:10 +0200 Subject: [PATCH 10/21] adding generated workflow in seperate file as one file is getting bloated --- .github/workflows/python.yml | 169 +++++++++++++++++++++++++++++++++++ .github/workflows/rust.yml | 12 --- python/Cargo.toml | 4 +- 3 files changed, 171 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/python.yml diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 0000000..e87cca4 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,169 @@ +# This file is autogenerated by maturin v1.7.1 +# To update, run +# +# maturin generate-ci github +# +name: CI + +on: + push: + branches: + - main + - master + tags: + - '*' + pull_request: + workflow_dispatch: + +permissions: + contents: read + +jobs: + linux: + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: ubuntu-latest + target: x86_64 + - runner: ubuntu-latest + target: x86 + - runner: ubuntu-latest + target: aarch64 + - runner: ubuntu-latest + target: armv7 + - runner: ubuntu-latest + target: s390x + - runner: ubuntu-latest + target: ppc64le + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + args: --release --out dist --find-interpreter + sccache: 'true' + manylinux: auto + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-linux-${{ matrix.platform.target }} + path: dist + + musllinux: + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: ubuntu-latest + target: x86_64 + - runner: ubuntu-latest + target: x86 + - runner: ubuntu-latest + target: aarch64 + - runner: ubuntu-latest + target: armv7 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + args: --release --out dist --find-interpreter + sccache: 'true' + manylinux: musllinux_1_2 + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-musllinux-${{ matrix.platform.target }} + path: dist + + windows: + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: windows-latest + target: x64 + - runner: windows-latest + target: x86 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + architecture: ${{ matrix.platform.target }} + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + args: --release --out dist --find-interpreter + sccache: 'true' + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-windows-${{ matrix.platform.target }} + path: dist + + macos: + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: macos-12 + target: x86_64 + - runner: macos-14 + target: aarch64 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + args: --release --out dist --find-interpreter + sccache: 'true' + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-macos-${{ matrix.platform.target }} + path: dist + + sdist: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build sdist + uses: PyO3/maturin-action@v1 + with: + command: sdist + args: --out dist + - name: Upload sdist + uses: actions/upload-artifact@v4 + with: + name: wheels-sdist + path: dist + + release: + name: Release + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + needs: [linux, musllinux, windows, macos, sdist] + steps: + - uses: actions/download-artifact@v4 + - name: Publish to PyPI + uses: PyO3/maturin-action@v1 + env: + MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} + with: + command: upload + args: --non-interactive --skip-existing wheels-*/* \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b45df42..373d88f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -123,18 +123,6 @@ jobs: run: | cd cli/src cargo publish --token ${{ secrets.CRATESTOKEN }} - - publish-python-bindings: - needs: build-library - runs-on: ubuntu-latest - container: - image: ghcr.io/pyo3/maturin - if: startsWith(github.ref, 'refs/tags/python-v') - steps: - - name: Build Python bindings - run: maturin build --release --target x86_64-unknown-linux-gnu --target aarch64-unknown-linux-gnu --target x86_64-pc-windows-gnu --target universal2-apple-darwin - - name: Publish Python bindings to PyPI - run: maturin publish publish-wasm: needs: build-wasm runs-on: ubuntu-latest diff --git a/python/Cargo.toml b/python/Cargo.toml index c6e1d8c..8c1d30f 100644 --- a/python/Cargo.toml +++ b/python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pymbusparser" -version = "0.0.0" +version = "0.0.1" edition = "2021" homepage = "https://maebli.github.io/" repository = "https://github.com/maebli/m-bus-parser" @@ -8,7 +8,7 @@ repository = "https://github.com/maebli/m-bus-parser" [dependencies] m-bus-parser = { path = "..", version = "0.0.13", features = ["std", "serde"] } serde_json = "1.0" -pyo3 = { version = "0.22.2", features = ["extension-module"] } +pyo3 = { version = "0.22.2", features = ["extension-module","generate-import-lib"] } hex = "0.4.2" [lib] From f7be0e3bc2b98a22a24f76482a814cf3f3528af3 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 14:24:28 +0200 Subject: [PATCH 11/21] always running action for testing purposes --- .github/workflows/python.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index e87cca4..1d6f8f5 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -8,8 +8,7 @@ name: CI on: push: branches: - - main - - master + - '*' tags: - '*' pull_request: From 23986769f97f54ddfd71ef0af027a55ac7e220ab Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 14:31:58 +0200 Subject: [PATCH 12/21] renaming pipeline --- .github/workflows/python.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 1d6f8f5..ce08521 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -3,14 +3,12 @@ # # maturin generate-ci github # -name: CI +name: Python Bindings CI on: push: branches: - '*' - tags: - - '*' pull_request: workflow_dispatch: From 14c9810fe0c5d715dcec7919a144938f505b0df6 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 14:39:55 +0200 Subject: [PATCH 13/21] changing working dir --- .github/workflows/python.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index ce08521..14abb08 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -50,6 +50,7 @@ jobs: with: name: wheels-linux-${{ matrix.platform.target }} path: dist + working-directory: ./python musllinux: runs-on: ${{ matrix.platform.runner }} @@ -76,11 +77,13 @@ jobs: args: --release --out dist --find-interpreter sccache: 'true' manylinux: musllinux_1_2 + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-musllinux-${{ matrix.platform.target }} path: dist + working-directory: ./python windows: runs-on: ${{ matrix.platform.runner }} @@ -103,11 +106,13 @@ jobs: target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-windows-${{ matrix.platform.target }} path: dist + working-directory: ./python macos: runs-on: ${{ matrix.platform.runner }} @@ -129,11 +134,13 @@ jobs: target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-macos-${{ matrix.platform.target }} path: dist + working-directory: ./python sdist: runs-on: ubuntu-latest @@ -144,11 +151,14 @@ jobs: with: command: sdist args: --out dist + working-directory: ./python - name: Upload sdist uses: actions/upload-artifact@v4 with: - name: wheels-sdist + name: whee + ls-sdist path: dist + working-directory: ./python release: name: Release @@ -163,4 +173,5 @@ jobs: MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} with: command: upload - args: --non-interactive --skip-existing wheels-*/* \ No newline at end of file + args: --non-interactive --skip-existing wheels-*/* + working-directory: ./python \ No newline at end of file From 215f64b3a5b21e186b0b7cb437ac865829c11a86 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 14:41:02 +0200 Subject: [PATCH 14/21] reverting bad change --- .github/workflows/python.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 14abb08..864ac78 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -155,8 +155,7 @@ jobs: - name: Upload sdist uses: actions/upload-artifact@v4 with: - name: whee - ls-sdist + name: wheels-sdist path: dist working-directory: ./python From 437d51d65e833fdd0e7bbed98a56fd488742c2b5 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 14:45:03 +0200 Subject: [PATCH 15/21] trying again to set dir correctly --- .github/workflows/python.yml | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 864ac78..c81a446 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -18,6 +18,9 @@ permissions: jobs: linux: runs-on: ${{ matrix.platform.runner }} + defaults: + run: + working-directory: ./python strategy: matrix: platform: @@ -50,10 +53,12 @@ jobs: with: name: wheels-linux-${{ matrix.platform.target }} path: dist - working-directory: ./python musllinux: runs-on: ${{ matrix.platform.runner }} + defaults: + run: + working-directory: ./python strategy: matrix: platform: @@ -77,16 +82,17 @@ jobs: args: --release --out dist --find-interpreter sccache: 'true' manylinux: musllinux_1_2 - working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-musllinux-${{ matrix.platform.target }} path: dist - working-directory: ./python windows: runs-on: ${{ matrix.platform.runner }} + defaults: + run: + working-directory: ./python strategy: matrix: platform: @@ -106,16 +112,17 @@ jobs: target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' - working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-windows-${{ matrix.platform.target }} path: dist - working-directory: ./python macos: runs-on: ${{ matrix.platform.runner }} + defaults: + run: + working-directory: ./python strategy: matrix: platform: @@ -134,16 +141,17 @@ jobs: target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' - working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-macos-${{ matrix.platform.target }} path: dist - working-directory: ./python sdist: runs-on: ubuntu-latest + defaults: + run: + working-directory: ./python steps: - uses: actions/checkout@v4 - name: Build sdist @@ -151,17 +159,18 @@ jobs: with: command: sdist args: --out dist - working-directory: ./python - name: Upload sdist uses: actions/upload-artifact@v4 with: name: wheels-sdist path: dist - working-directory: ./python release: name: Release runs-on: ubuntu-latest + defaults: + run: + working-directory: ./python if: startsWith(github.ref, 'refs/tags/') needs: [linux, musllinux, windows, macos, sdist] steps: @@ -172,5 +181,4 @@ jobs: MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} with: command: upload - args: --non-interactive --skip-existing wheels-*/* - working-directory: ./python \ No newline at end of file + args: --non-interactive --skip-existing wheels-*/* \ No newline at end of file From 8124654281fa5e71963ce5c8f83ca87533a4251b Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 14:49:03 +0200 Subject: [PATCH 16/21] Revert "trying again to set dir correctly" This reverts commit 437d51d65e833fdd0e7bbed98a56fd488742c2b5. --- .github/workflows/python.yml | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c81a446..864ac78 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -18,9 +18,6 @@ permissions: jobs: linux: runs-on: ${{ matrix.platform.runner }} - defaults: - run: - working-directory: ./python strategy: matrix: platform: @@ -53,12 +50,10 @@ jobs: with: name: wheels-linux-${{ matrix.platform.target }} path: dist + working-directory: ./python musllinux: runs-on: ${{ matrix.platform.runner }} - defaults: - run: - working-directory: ./python strategy: matrix: platform: @@ -82,17 +77,16 @@ jobs: args: --release --out dist --find-interpreter sccache: 'true' manylinux: musllinux_1_2 + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-musllinux-${{ matrix.platform.target }} path: dist + working-directory: ./python windows: runs-on: ${{ matrix.platform.runner }} - defaults: - run: - working-directory: ./python strategy: matrix: platform: @@ -112,17 +106,16 @@ jobs: target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-windows-${{ matrix.platform.target }} path: dist + working-directory: ./python macos: runs-on: ${{ matrix.platform.runner }} - defaults: - run: - working-directory: ./python strategy: matrix: platform: @@ -141,17 +134,16 @@ jobs: target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-macos-${{ matrix.platform.target }} path: dist + working-directory: ./python sdist: runs-on: ubuntu-latest - defaults: - run: - working-directory: ./python steps: - uses: actions/checkout@v4 - name: Build sdist @@ -159,18 +151,17 @@ jobs: with: command: sdist args: --out dist + working-directory: ./python - name: Upload sdist uses: actions/upload-artifact@v4 with: name: wheels-sdist path: dist + working-directory: ./python release: name: Release runs-on: ubuntu-latest - defaults: - run: - working-directory: ./python if: startsWith(github.ref, 'refs/tags/') needs: [linux, musllinux, windows, macos, sdist] steps: @@ -181,4 +172,5 @@ jobs: MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} with: command: upload - args: --non-interactive --skip-existing wheels-*/* \ No newline at end of file + args: --non-interactive --skip-existing wheels-*/* + working-directory: ./python \ No newline at end of file From eb4462343394deee8a6b1a5ccfae76b6771139c7 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 14:58:55 +0200 Subject: [PATCH 17/21] trying yet again --- .github/workflows/python.yml | 51 ++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 864ac78..24eed58 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,8 +1,3 @@ -# This file is autogenerated by maturin v1.7.1 -# To update, run -# -# maturin generate-ci github -# name: Python Bindings CI on: @@ -18,6 +13,9 @@ permissions: jobs: linux: runs-on: ${{ matrix.platform.runner }} + defaults: + run: + working-directory: ./python strategy: matrix: platform: @@ -45,15 +43,18 @@ jobs: args: --release --out dist --find-interpreter sccache: 'true' manylinux: auto + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-linux-${{ matrix.platform.target }} - path: dist - working-directory: ./python + path: ./python/dist musllinux: runs-on: ${{ matrix.platform.runner }} + defaults: + run: + working-directory: ./python strategy: matrix: platform: @@ -77,16 +78,18 @@ jobs: args: --release --out dist --find-interpreter sccache: 'true' manylinux: musllinux_1_2 - working-directory: ./python + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-musllinux-${{ matrix.platform.target }} - path: dist - working-directory: ./python + path: ./python/dist windows: runs-on: ${{ matrix.platform.runner }} + defaults: + run: + working-directory: ./python strategy: matrix: platform: @@ -106,16 +109,18 @@ jobs: target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' - working-directory: ./python + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-windows-${{ matrix.platform.target }} - path: dist - working-directory: ./python + path: ./python/dist macos: runs-on: ${{ matrix.platform.runner }} + defaults: + run: + working-directory: ./python strategy: matrix: platform: @@ -134,16 +139,18 @@ jobs: target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' - working-directory: ./python + working-directory: ./python - name: Upload wheels uses: actions/upload-artifact@v4 with: name: wheels-macos-${{ matrix.platform.target }} - path: dist - working-directory: ./python + path: ./python/dist sdist: runs-on: ubuntu-latest + defaults: + run: + working-directory: ./python steps: - uses: actions/checkout@v4 - name: Build sdist @@ -151,21 +158,25 @@ jobs: with: command: sdist args: --out dist - working-directory: ./python + working-directory: ./python - name: Upload sdist uses: actions/upload-artifact@v4 with: name: wheels-sdist - path: dist - working-directory: ./python + path: ./python/dist release: name: Release runs-on: ubuntu-latest + defaults: + run: + working-directory: ./python if: startsWith(github.ref, 'refs/tags/') needs: [linux, musllinux, windows, macos, sdist] steps: - uses: actions/download-artifact@v4 + with: + path: ./python - name: Publish to PyPI uses: PyO3/maturin-action@v1 env: @@ -173,4 +184,4 @@ jobs: with: command: upload args: --non-interactive --skip-existing wheels-*/* - working-directory: ./python \ No newline at end of file + working-directory: ./python \ No newline at end of file From 77b095a13ea7c817492c9862682fc8c294586248 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 15:10:22 +0200 Subject: [PATCH 18/21] fixing condition --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 24eed58..bfc32f8 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -171,7 +171,7 @@ jobs: defaults: run: working-directory: ./python - if: startsWith(github.ref, 'refs/tags/') + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/python-v*') needs: [linux, musllinux, windows, macos, sdist] steps: - uses: actions/download-artifact@v4 From d6309bd17a623d4682e0661b385a26a939670caf Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 15:10:29 +0200 Subject: [PATCH 19/21] removing condition for now --- .github/workflows/python.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index bfc32f8..5b9e487 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -171,7 +171,6 @@ jobs: defaults: run: working-directory: ./python - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/python-v*') needs: [linux, musllinux, windows, macos, sdist] steps: - uses: actions/download-artifact@v4 From 79d36c32ea8b733ef7f45a7cd832485fff8cde12 Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 17:25:15 +0200 Subject: [PATCH 20/21] adding shield for release --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 89f8c72..2f26981 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Discord](https://img.shields.io/badge/Discord-Join%20Now-blue?style=flat&logo=Discord)](https://discord.gg/FfmecQ4wua) [![Crates.io](https://img.shields.io/crates/v/m-bus-parser.svg)](https://crates.io/crates/m-bus-parser) [![Downloads](https://img.shields.io/crates/d/m-bus-parser.svg)](https://crates.io/crates/m-bus-parser) [![License](https://img.shields.io/crates/l/m-bus-parser.svg)](https://crates.io/crates/m-bus-parser) [![Documentation](https://docs.rs/m-bus-parser/badge.svg)](https://docs.rs/m-bus-parser) [![Build Status](https://github.com/maebli/m-bus-parser/actions/workflows/rust.yml/badge.svg)](https://github.com/maebli/m-bus-parser/actions/workflows/rust.yml) + ### Introduction *For contributing see [CONTRIBUTING.md](./CONTRIBUTING.md)* @@ -35,6 +36,10 @@ The source is in the wasm folder in this repos There is a cli, the source is in the sub folder "cli" and is published on crates.io [https://crates.io/crates/m-bus-parser-cli](https://crates.io/crates/m-bus-parser-cli). +### Python bindings +[![PyPI version](https://badge.fury.io/py/pymbusparser.png)](https://badge.fury.io/py/pymbusparser) + +The are some python bindings, the source is in the sub folder "python" and is published on pypi [https://pypi.org/project/pymbusparser/](https://pypi.org/project/pymbusparser/). ### Visualization of Library Function From 97c73333ff44e847ffa07334e537a88c80c5d48d Mon Sep 17 00:00:00 2001 From: Michael Aebli Date: Tue, 17 Sep 2024 17:39:23 +0200 Subject: [PATCH 21/21] fixing build trigger --- .github/workflows/python.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 5b9e487..d30f0d7 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -2,9 +2,8 @@ name: Python Bindings CI on: push: - branches: - - '*' - pull_request: + tags: + - 'python-v*' workflow_dispatch: permissions: