From 2d820c4df83b41369ceb882d0837a289e329e73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Fri, 8 Dec 2023 14:54:00 +0100 Subject: [PATCH 1/2] ci: add readme codeblock checks This adds a CI check, which uses the python package `codeblocks` to extract all python codeblocks from the readme to check them with `mypy` and `pycodestyle`, and also run them with `python` itself. --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8d61d4bb..0ac860af9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,9 @@ name: ci on: [push, pull_request] +env: + X_PYTHON_VERSION: "3.10" + jobs: test: runs-on: ubuntu-latest @@ -46,10 +49,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python 3.10 + - name: Set up Python ${{ env.X_PYTHON_VERSION }} uses: actions/setup-python@v2 with: - python-version: "3.10" + python-version: ${{ env.X_PYTHON_VERSION }} - name: Install Python dependencies run: | python -m pip install --upgrade pip @@ -62,6 +65,30 @@ jobs: run: | pycodestyle --count --max-line-length 120 basyx test + readme-codeblocks: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ env.X_PYTHON_VERSION }} + uses: actions/setup-python@v2 + with: + python-version: ${{ env.X_PYTHON_VERSION }} + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install pycodestyle mypy codeblocks + pip install -r requirements.txt + - name: Check typing with MyPy + run: | + mypy <(codeblocks python README.md) + - name: Check code style with PyCodestyle + run: | + codeblocks --wrap python README.md | pycodestyle --count --max-line-length 120 - + - name: Run readme codeblocks with Python + run: | + codeblocks python README.md | python + package: runs-on: ubuntu-latest From 8bc048bd463f3f74a20a76716e112411b840ef07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Fri, 8 Dec 2023 15:02:20 +0100 Subject: [PATCH 2/2] readme: fix the getting started Fix #124 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 675b0f1e4..60a235cb6 100644 --- a/README.md +++ b/README.md @@ -115,11 +115,11 @@ submodel.submodel_element.add(property) Serialize the `Submodel` to XML: ```python -from basyx.aas.adapter import write_aas_xml_file +from basyx.aas.adapter.xml import write_aas_xml_file data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() data.add(submodel) -with open('Simple_Submodel.xml', 'w', encoding='utf-8') as f: +with open('Simple_Submodel.xml', 'wb') as f: write_aas_xml_file(file=f, data=data) ```