Skip to content

Commit

Permalink
Update submodules & prepare for pypi distribution (#11)
Browse files Browse the repository at this point in the history
- update submodules
- update docs
- use cibuildwheels to only build aarch64 wheels
- check type hinting with mypy tool
- update stubs
- update CI workflows
- allow for manually triggering the workflows.
- match pylint problems to diff using github annotations.
- trim sdist by manually specifying the MANIFEST
- update scanner.py
- change the version str for non-tagged commits
- build CI upload sdist to testPyPi (only from main)
- remove ninja from build reqs in toml
  • Loading branch information
2bndy5 authored Jul 23, 2022
1 parent ff659b5 commit ce6ff01
Show file tree
Hide file tree
Showing 24 changed files with 523 additions and 258 deletions.
47 changes: 37 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Build CI

on: [pull_request, push]
on: [pull_request, push, workflow_dispatch]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: 3.9

Expand All @@ -18,40 +18,67 @@ jobs:
fetch-depth: 0

- name: Install dependencies
# cmake ships with the ubuntu-latest runner
run: |
sudo apt-get install python3-dev graphviz
python3 -m pip install --upgrade pip pylint
python3 -m pip install --upgrade pip pylint mypy
python3 -m pip install -r docs/requirements.txt -r requirements.txt
- name: Build package for docs extraction and linting examples
id: wheel
run: |
python3 setup.py bdist_wheel
python3 -m pip install $(ls dist/pyrf24-*.whl)
python3 setup.py sdist bdist_wheel
python3 -m pip install dist/pyrf24-*.whl
- name: check python typing
run: mypy src

- name: check python examples PEP8 compliance
run: |
pylint examples/*.py --disable=duplicate-code
# duplicate-code error gets flagged because some examples use similar code snippets
run: pylint examples/*.py src/pyrf24/*.py --disable=duplicate-code --output-format=json:pylint.json

- name: Match pylint problems to diff via github annotations
run: python ./.github/workflows/pylint_matcher.py pylint.json

- name: Build docs
working-directory: docs
run: sphinx-build -E -W -b html . _build/html

- name: Save built docs as artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: "pyRF24_docs"
path: ${{ github.workspace }}/docs/_build/html

- name: upload to github pages
# only publish doc changes from main branch
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build/html

- name: Save distributable wheels as artifacts
uses: actions/upload-artifact@v2
with:
name: "pyRF24_pkg_dist"
path: ${{ github.workspace }}/dist

- name: Create sdist for testPyPi
# Doing this again to ensure a fresh build env.
# We don't need to upload a bdist as we can check that locally, but
# sdist is used by the piwheels project to create a bdist for RPi OS
run: |
rm -r dist/ _skbuild
python3 setup.py sdist
- name: Validate distribution
run: |
python3 -m pip install twine
twine check dist/*
python3 -m twine check dist/*
- name: upload to test PyPi
if: github.event_name == 'push' && github.repository == 'nRF24/pyRF24' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.test_pypi_token }}
run: python3 -m twine upload -r testpypi dist/*
69 changes: 69 additions & 0 deletions .github/workflows/pylint_matcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Parse output from clang-tidy's stdout"""
import argparse
import pathlib
import json
from typing import Dict, Union, List
import logging

log_commander = logging.getLogger("PylintMatcher")
log_commander.setLevel(logging.DEBUG) # be sure that log commands are output
console_handler = logging.StreamHandler() # Create special stdout stream handler
console_handler.setFormatter(logging.Formatter("%(message)s")) # no formatted log cmds
log_commander.addHandler(console_handler) # Use special handler for log_commander
log_commander.propagate = False # prevent duplicate messages in the parent logger obj


def annotate_pylint_note(obj: Dict[str, Union[int, str]]) -> str:
"""Translate a 1 notification from pylint to github's checks API.
:param dict obj: The JSON object output by pylint (for 1 notification).
A typical JSON object output from pylint looks like:
.. code-block:: json
{
"type": "error",
"module": "basic_test",
"obj": "",
"line": 3,
"column": 19,
"path": "tests/basic_test.py",
"symbol": "syntax-error",
"message": "invalid syntax (<unknown>, line 3)",
"message-id": "E0001"
}
:Returns:
A `str` that can be used by github's workflow log commands.
"""
priority = {
"convention": "notice",
"refactor": "notice",
"warning": "warning",
"error": "error",
"fatal": "error",
}
return (
"::{level} file={path},line={line},title={path}:{line}:{col} {symbol} [{code}]"
"::{msg}".format(
level=priority[obj["type"]],
path=obj["path"],
line=obj["line"],
col=obj["column"],
symbol=obj["symbol"],
code=obj["message-id"],
msg=obj["message"],
)
)


if __name__ == "__main__":
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("json_output", type=pathlib.Path)
args = arg_parser.parse_args()

pylint_result: List[Dict[str, Union[int, str]]] = json.loads(
pathlib.Path(args.json_output).read_text(encoding="utf-8")
)
for note in pylint_result:
log_commander.info(annotate_pylint_note(note))
43 changes: 31 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
name: Release Actions

on:
workflow_dispatch:
release:
types: [published]

jobs:
upload-pypi:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.7
uses: actions/setup-python@v1
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.9

- name: Checkout Current Repo
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
Expand All @@ -24,20 +25,38 @@ jobs:
sudo apt install python3-dev
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
python3 -m pip install twine
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: aarch64

- name: Build wheels with cibuildwheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_LINUX: aarch64
CIBW_SKIP: cp36* pp* cp311*

- name: Move cross-compiled wheels to dist folder
run: |
mkdir -p dist
mv ./wheelhouse/*.whl ${{ github.workspace }}/dist/
- name: build binary distributable wheel
run: python setup.py bdist_wheel
# sdist for non-supprted platforms will serve as a stub lib install
run: python setup.py sdist

- name: Save distributable wheels as artifacts
uses: actions/upload-artifact@v2
with:
name: "pyRF24_pkg_dist"
path: ${{ github.workspace }}/dist

###### We need a self-hosted runner to build distributable wheels for armv7l
# - name: Publish to PyPi
# env:
# TWINE_USERNAME: __token__
# TWINE_PASSWORD: ${{ secrets.pypi_token }}
# run: |
# twine upload dist/*
- name: Publish to PyPi
# only upload distributions to PyPi when triggered by a published release
if: github.event_name == 'release'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.pypi_token }}
run: twine upload dist/*
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ if(SKBUILD)
message(STATUS "This project is being built using scikit-build & pybind11")
endif()

include(cmake/using_flags.cmake)

add_subdirectory(pybind11)
add_subdirectory(RF24/utility) # configure the RF24_DRIVER
include(cmake/using_flags.cmake)

################################# RF24 #############################

Expand Down
20 changes: 20 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
recursive-include RF24* *
recursive-include cmake *
recursive-include src/pyrf24 *.cpp *.typed
recursive-include pybind11 *
recursive-exclude */.github *
recursive-exclude */docs *
recursive-exclude */examples* *
recursive-exclude */images *
recursive-exclude */tests *
recursive-exclude */build *
recursive-exclude */cmake/toolchains *.cmake
recursive-exclude RF24/utility/AT* *.h *.cpp *.c
recursive-exclude RF24/utility/Teensy *.h
recursive-exclude RF24/utility/Template* *.h
recursive-exclude RF24/utility/rp2 *.h *.cpp *.txt
recursive-exclude RF24*/pyRF24* *
recursive-exclude RF24Network/RPi/pyRF24Network *
global-exclude .clang-format .clang-tidy .git* library.json library.properties Doxyfile keywords.txt Makefile* doxygen-custom.css **.yml **.yaml *.pdf .pylintrc
exclude */*.md */README* RF24/utility/includes.h RF24/configure
include pyproject.toml setup.py CMakeLists.txt
24 changes: 20 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ To build this python package locally, you need to have cloned this library's rep
git clone --recurse-submodules https://github.com/nRF24/pyRF24.git
cd pyRF24
python -m pip install .
python -m pip install . -v
.. hint::
For consecutive build attempts, it is recommended to delete any previous build artifacts
before attempting to build again.

.. code-block:: bash
rm -r _skbuild/ dist/
.. note::
The ``-v`` is optional. Here, we use it to show that pip isn't frozen during the
build process.

Installing the package can take a long time, and you might think that pip is frozen
on the step labeled "Building wheel for pyrf24 (pyproject.toml)". Just wait for about
5 minutes (maybe longer on older/slower variants of Raspberry Pi).
Expand All @@ -81,7 +92,7 @@ it is appropriate to pass an additional argument to the install command:

.. code-block:: bash
python setup.py install -DRF24_DRIVER=RPi
python setup.py bdist_wheel -DRF24_DRIVER=RPi
Building a wheel
-----------------
Expand Down Expand Up @@ -110,7 +121,7 @@ same version of CPython, CPU architecture, and C standard lib.

.. code-block:: bash
rm -r _skbuild/
rm -r _skbuild/ dist/
3. To install a built wheel, simply pass the wheel's path and file name to ``pip install``:

Expand All @@ -120,7 +131,12 @@ same version of CPython, CPU architecture, and C standard lib.
Where the following would be replaced accordingly:

- ``MAJOR.MINOR.PATCH`` is the current version of the pyrf24 package
- ``MAJOR.MINOR.PATCH`` is the current version of the pyrf24 package.

- If not building a tagged commit, then the version will describe the commit relative to
the number of commits since the latest tag. For example, ``0.1.1.post1.dev3`` is
the third commit (``dev3``) since the first "post release" (``post1``) after the
tagged version ``0.1.1``. This adhere's to `PEP440 <https://peps.python.org/pep-0440>`_.
- ``cp3X`` is the version of python used to build the wheel (ie ``cp39`` for CPython 3.9)
The second occurrence of ``cp3X`` describes the CPython ABI compatibility.
- ``ARCH`` is the architecture type of the CPU. This corresponds to the compiler used.
Expand Down
2 changes: 1 addition & 1 deletion RF24
Submodule RF24 updated 149 files
2 changes: 1 addition & 1 deletion RF24Mesh
Submodule RF24Mesh updated 40 files
+165 −0 .clang-format
+60 −15 .github/workflows/build_arduino.yml
+27 −0 .github/workflows/build_linux.yml
+21 −13 .github/workflows/build_platformIO.yml
+27 −0 .github/workflows/build_rp2xxx.yml
+13 −5 .github/workflows/doxygen.yml
+3 −2 .readthedocs.yaml
+10 −3 CMakeLists.txt
+3 −2,262 Doxyfile
+69 −68 RF24Mesh.cpp
+29 −25 RF24Mesh.h
+6 −7 RF24Mesh_config.h
+56 −0 cmake/AutoConfig_RF24_DRIVER.cmake
+12 −26 docs/sphinx/_static/custom_material.css
+2 −2 docs/sphinx/classRF24Mesh.rst
+18 −13 docs/sphinx/conf.py
+145 −0 examples/.clang-format
+14 −7 examples/RF24Mesh_Example/RF24Mesh_Example.ino
+10 −4 examples/RF24Mesh_Example_Master/RF24Mesh_Example_Master.ino
+8 −4 examples/RF24Mesh_Example_Master_Statics/RF24Mesh_Example_Master_Statics.ino
+6 −7 examples/RF24Mesh_Example_Master_To_Nodes/RF24Mesh_Example_Master_To_Nodes.ino
+20 −12 examples/RF24Mesh_Example_Node2Node/RF24Mesh_Example_Node2Node.ino
+20 −11 examples/RF24Mesh_Example_Node2NodeExtra/RF24Mesh_Example_Node2NodeExtra.ino
+11 −5 examples/RF24Mesh_SerialConfig/RF24Mesh_SerialConfig.ino
+0 −31 examples/examples_formatter.conf
+43 −3 examples_RPi/CMakeLists.txt
+45 −37 examples_RPi/RF24Mesh_Example.cpp
+46 −32 examples_RPi/RF24Mesh_Example.py
+39 −38 examples_RPi/RF24Mesh_Example_Master.cpp
+21 −20 examples_RPi/RF24Mesh_Example_Master.py
+4 −4 examples_RPi/ncurses/CMakeLists.txt
+230 −130 examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp
+20 −12 examples_pico/RF24Mesh_Example.cpp
+8 −9 examples_pico/RF24Mesh_Example_Master.cpp
+16 −17 examples_pico/defaultPins.h
+ images/RF24Mesh_Ncurses.JPG
+1 −1 library.json
+1 −1 library.properties
+7 −8 pyRF24Mesh/pyRF24Mesh.cpp
+1 −0 pyRF24Mesh/setup.py
2 changes: 1 addition & 1 deletion RF24Network
Submodule RF24Network updated 43 files
+165 −0 .clang-format
+61 −15 .github/workflows/build_arduino.yml
+21 −13 .github/workflows/build_platformIO.yml
+27 −1 .github/workflows/build_rp2xxx.yml
+13 −5 .github/workflows/doxygen.yml
+29 −2 .github/workflows/linux_build.yml
+3 −2 .readthedocs.yaml
+10 −2 CMakeLists.txt
+0 −2,306 Doxyfile
+176 −160 RF24Network.cpp
+74 −75 RF24Network.h
+122 −126 RF24Network_config.h
+0 −56 RPi/pyRF24Network/examples/dev_test.py
+13 −17 RPi/pyRF24Network/examples/helloworld_rx.py
+14 −10 RPi/pyRF24Network/examples/helloworld_tx.py
+20 −20 RPi/pyRF24Network/pyRF24Network.cpp
+2 −1 RPi/pyRF24Network/setup.py
+56 −0 cmake/AutoConfig_RF24_DRIVER.cmake
+1 −3 docs/main_page.md
+15 −24 docs/sphinx/_static/custom_material.css
+6 −0 docs/sphinx/classRF24Network.rst
+19 −13 docs/sphinx/conf.py
+1 −1 docs/sphinx/examples/Arduino/Network_Ping_Sleep.rst
+145 −0 examples/.clang-format
+25 −25 examples/Network_Ping/Network_Ping.ino
+46 −38 examples/Network_Ping_Sleep/Network_Ping_Sleep.ino
+12 −12 examples/Network_Priority_RX/Network_Priority_RX.ino
+7 −7 examples/Network_Priority_TX/Network_Priority_TX.ino
+0 −31 examples/examples_formatter.conf
+8 −8 examples/helloworld_rx/helloworld_rx.ino
+13 −13 examples/helloworld_rx_advanced/helloworld_rx_advanced.ino
+9 −9 examples/helloworld_tx/helloworld_tx.ino
+14 −14 examples/helloworld_tx_advanced/helloworld_tx_advanced.ino
+42 −4 examples_RPi/CMakeLists.txt
+0 −1 examples_RPi/Makefile
+3 −3 examples_RPi/helloworld_rx.cpp
+3 −2 examples_RPi/helloworld_tx.cpp
+22 −21 examples_RPi/rx-test.cpp
+16 −17 examples_pico/defaultPins.h
+7 −8 examples_pico/helloworld_rx.cpp
+7 −8 examples_pico/helloworld_tx.cpp
+1 −1 library.json
+1 −1 library.properties
7 changes: 7 additions & 0 deletions cmake/using_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ option(MESH_NOMASTER "exclude compiling code that is strictly for master nodes f
option(MESH_DEBUG "enable/disable debugging output for RF24Mesh lib" OFF)
option(MESH_DEBUG_MINIMAL "enable/disable minimal debugging output for RF24Mesh lib" OFF)

# Disabling IRQ support should be always done because
# IRQ support can be handled in python with different libs.
option(RF24_NO_INTERRUPT "disable IRQ support (dependent on pigpio)" ON)
# does not affect pigpio driver though

###############################################
# function to apply flags to applicable targets
function(apply_flags target)
# apply RF24 flags to all targets
if(RF24_NO_INTERRUPT)
target_compile_definitions(${target} PUBLIC RF24_NO_INTERRUPT)
endif()
if(RF24_DEBUG)
message(STATUS "RF24_DEBUG asserted for ${target}")
target_compile_definitions(${target} PUBLIC SERIAL_DEBUG)
Expand Down
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ Indices and tables

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Loading

0 comments on commit ce6ff01

Please sign in to comment.