Skip to content

Commit

Permalink
Merge pull request #606 from geeksville/pr-poetry
Browse files Browse the repository at this point in the history
Change build to use poetry
  • Loading branch information
ianmcorvidae authored Jun 26, 2024
2 parents b15e27c + 195f0c9 commit 68836b1
Show file tree
Hide file tree
Showing 17 changed files with 1,705 additions and 213 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,29 @@ jobs:
- "3.10"
- "3.11"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install Python 3
uses: actions/setup-python@v1
uses: actions/setup-python@v5
- name: Uninstall meshtastic
run: |
pip3 uninstall meshtastic
pip3 uninstall -y meshtastic
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip3 install -r requirements.txt
pip3 install poetry
- name: Install meshtastic from local
run: |
pip3 install .
which meshtastic
meshtastic --version
poetry install
poetry run meshtastic --version
- name: Run pylint
run: pylint meshtastic examples/ --ignore-patterns ".*_pb2.pyi?$"
run: poetry run pylint meshtastic examples/ --ignore-patterns ".*_pb2.pyi?$"
- name: Check types with mypy
run: mypy meshtastic/
run: poetry run mypy meshtastic/
- name: Run tests with pytest
run: pytest --cov=meshtastic
run: poetry run pytest --cov=meshtastic
- name: Generate coverage report
run: |
pytest --cov=meshtastic --cov-report=xml
poetry run pytest --cov=meshtastic --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand All @@ -62,11 +61,12 @@ jobs:
- "3.10"
- "3.11"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install Python 3
uses: actions/setup-python@v1
uses: actions/setup-python@v5
- name: Install meshtastic from local
run: |
pip3 install .
which meshtastic
meshtastic --version
python -m pip install --upgrade pip
pip3 install poetry
poetry install
poetry run meshtastic --version
69 changes: 29 additions & 40 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,36 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip3 install poetry
- name: Bump version
run: >-
bin/bump_version.py
poetry version patch
- name: Commit updated version.py
- name: Commit updated version.
id: commit_updated
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git add setup.py
git add pyproject.toml
git commit -m "bump version" && git push || echo "No changes to commit"
git log -n 1 --pretty=format:"%H" | tail -n 1 | awk '{print "::set-output name=sha::"$0}'
- name: Get version
id: get_version
run: >-
bin/show_version.py
poetry version
- name: Create GitHub release
uses: actions/create-release@v1
Expand All @@ -47,26 +57,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
poetry build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
Expand All @@ -79,14 +72,14 @@ jobs:
# needs: release_create
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# uses: actions/checkout@v4
# with:
# ref: ${{ needs.release_create.outputs.new_sha }}

# - name: Set up Python 3.9
# uses: actions/setup-python@v2
# uses: actions/setup-python@v5
# with:
# python-version: 3.9
# python-version: "3.9"

# - name: Setup code signing
# env:
Expand Down Expand Up @@ -125,21 +118,19 @@ jobs:
needs: release_create
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ needs.release_create.outputs.new_sha }}

- name: Set up Python 3.9
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: "3.9"

- name: Build
run: |
pip install pyinstaller
pip install -r requirements.txt
pip install .
pyinstaller -F -n meshtastic --collect-all meshtastic meshtastic/__main__.py
pip install poetry
bin/build-bin.sh
- name: Add ubuntu to release
uses: actions/upload-release-asset@v1
Expand All @@ -166,21 +157,19 @@ jobs:
needs: release_create
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ needs.release_create.outputs.new_sha }}

- name: Set up Python 3.9
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: "3.9"

- name: Build
run: |
pip install pyinstaller
pip install -r requirements.txt
pip install .
pyinstaller -F -n meshtastic --collect-all meshtastic meshtastic/__main__.py
pip install poetry
bin/build-bin.sh
- name: Add windows to release
uses: actions/upload-release-asset@v1
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/update_protobufs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: true

Expand All @@ -18,9 +18,14 @@ jobs:
- name: Download nanopb
run: |
wget https://jpa.kapsi.fi/nanopb/download/nanopb-0.4.6-linux-x86.tar.gz
tar xvzf nanopb-0.4.6-linux-x86.tar.gz
mv nanopb-0.4.6-linux-x86 nanopb-0.4.6
wget https://jpa.kapsi.fi/nanopb/download/nanopb-0.4.8-linux-x86.tar.gz
tar xvzf nanopb-0.4.8-linux-x86.tar.gz
mv nanopb-0.4.8-linux-x86 nanopb-0.4.8
- name: Install poetry (needed by regen-protobufs.sh)
run: |
python -m pip install --upgrade pip
pip3 install poetry
- name: Re-generate protocol buffers
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ __pycache__
examples/__pycache__
meshtastic.spec
.hypothesis/
coverage.xml
9 changes: 9 additions & 0 deletions bin/build-bin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

echo Building ubuntu binary
poetry install
source $(poetry env info --path)/bin/activate
pyinstaller -F -n meshtastic --collect-all meshtastic meshtastic/__main__.py

30 changes: 0 additions & 30 deletions bin/bump_version.py

This file was deleted.

20 changes: 12 additions & 8 deletions bin/prerelease-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ set -e
# You may consider running: "pytest -m smoke1" instead of this test.

echo "Running (crude) prerelease tests to verify sanity"

# Use the python environment created by poetry
source $(poetry env info --path)/bin/activate

echo running hello
python3 tests/hello_world.py
# bin/run.sh --help
# meshtastic --help
echo toggling router
bin/run.sh --set is_router true
bin/run.sh --set is_router false
meshtastic --set is_router true
meshtastic --set is_router false
# TODO: This does not seem to work.
echo setting channel
bin/run.sh --seturl "https://www.meshtastic.org/c/#GAMiENTxuzogKQdZ8Lz_q89Oab8qB0RlZmF1bHQ="
meshtastic --seturl "https://www.meshtastic.org/c/#GAMiENTxuzogKQdZ8Lz_q89Oab8qB0RlZmF1bHQ="
echo setting owner
bin/run.sh --set-owner "Test Build"
meshtastic --set-owner "Test Build"
echo setting position
bin/run.sh --setlat 32.7767 --setlon -96.7970 --setalt 1337
meshtastic --setlat 32.7767 --setlon -96.7970 --setalt 1337
echo dumping info
bin/run.sh --info
meshtastic run meshtastic --info
echo sending closing message
bin/run.sh --sendtext "Sanity complete"
meshtastic --sendtext "Sanity complete"
7 changes: 5 additions & 2 deletions bin/regen-protobufs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#gsed -i 's/import "\//import ".\//g' ./protobufs/meshtastic/*
#gsed -i 's/package meshtastic;//g' ./protobufs/meshtastic/*

./nanopb-0.4.7/generator-bin/protoc -I=protobufs --python_out ./ --mypy_out ./ ./protobufs/meshtastic/*.proto
./nanopb-0.4.7/generator-bin/protoc -I=protobufs --python_out ./meshtastic/ --mypy_out ./meshtastic/ ./protobufs/nanopb.proto
# protoc looks for mypy plugin in the python path
source $(poetry env info --path)/bin/activate

./nanopb-0.4.8/generator-bin/protoc -I=protobufs --python_out ./ --mypy_out ./ ./protobufs/meshtastic/*.proto
./nanopb-0.4.8/generator-bin/protoc -I=protobufs --python_out ./meshtastic/ --mypy_out ./meshtastic/ ./protobufs/nanopb.proto

# workaround for import bug in protoc https://github.com/protocolbuffers/protobuf/issues/1491#issuecomment-690618628

Expand Down
11 changes: 11 additions & 0 deletions bin/run-ci-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# This script lets you run github ci actions locally
# You need to have act installed. You can get it at https://nektosact.com/

# by default it simulates a push event
# other useful options
# -j build-and-publish-ubuntu

# also: we only run one of the 4 matrix tests, because otherwise it absolutely hammers the CPU (so many containers and threads)
act -P ubuntu-latest=-self-hosted --matrix "python-version:3.8" "$@"
2 changes: 0 additions & 2 deletions bin/run.sh

This file was deleted.

20 changes: 0 additions & 20 deletions bin/show_version.py

This file was deleted.

6 changes: 2 additions & 4 deletions bin/test-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ set -e

bin/regen-docs.sh
pandoc --from=markdown --to=rst --output=README README.md
python3 setup.py sdist bdist_wheel
python3 -m twine check dist/*
# test the upload
python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*

poetry publish -r test-pypi --build
echo "view the upload at https://test.pypi.org/ it it looks good upload for real"
7 changes: 5 additions & 2 deletions bin/upload-release.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
rm dist/*
set -e

python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*
poetry build
poetry run pytest
poetry publish
#python3 setup.py sdist bdist_wheel
#python3 -m twine upload dist/*
Loading

0 comments on commit 68836b1

Please sign in to comment.