Skip to content

Commit ef4b534

Browse files
committed
Merge branch 'pr-moveproto' into pr-powermon
2 parents b063d33 + 3e8a807 commit ef4b534

77 files changed

Lines changed: 1681 additions & 1910 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/update_protobufs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jobs:
3737
git config --global user.email '[email protected]'
3838
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
3939
git add protobufs
40-
git add meshtastic
40+
git add meshtastic/protobuf
4141
git commit -m "Update protobuf submodule" && git push || echo "No changes to commit"

bin/regen-protobufs.sh

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,53 @@
11
#!/bin/bash
22

3+
set -e
4+
35
#Uncomment to run hack
46
#gsed -i 's/import "\//import ".\//g' ./protobufs/meshtastic/*
57
#gsed -i 's/package meshtastic;//g' ./protobufs/meshtastic/*
68

79
# protoc looks for mypy plugin in the python path
810
source $(poetry env info --path)/bin/activate
911

10-
./nanopb-0.4.8/generator-bin/protoc -I=protobufs --python_out ./ --mypy_out ./ ./protobufs/meshtastic/*.proto
11-
./nanopb-0.4.8/generator-bin/protoc -I=protobufs --python_out ./meshtastic/ --mypy_out ./meshtastic/ ./protobufs/nanopb.proto
12+
# Put our temp files in the poetry build directory
13+
TMPDIR=./build/meshtastic/protofixup
14+
echo "Fixing up protobuf paths in ${TMPDIR} temp directory"
15+
16+
17+
# Ensure a clean build
18+
rm -r "${TMPDIR}"
1219

13-
# workaround for import bug in protoc https://github.com/protocolbuffers/protobuf/issues/1491#issuecomment-690618628
20+
INDIR=${TMPDIR}/in/meshtastic/protobuf
21+
OUTDIR=${TMPDIR}/out
22+
PYIDIR=${TMPDIR}/out
23+
mkdir -p "${OUTDIR}" "${INDIR}" "${PYIDIR}"
24+
cp ./protobufs/meshtastic/*.proto "${INDIR}"
1425

26+
# OS-X sed is apparently a little different and expects an arg for -i
1527
if [[ $OSTYPE == 'darwin'* ]]; then
16-
sed -i '' -E 's/^(import.*_pb2)/from . \1/' meshtastic/*.py
17-
# automate the current workaround (may be related to Meshtastic-protobufs issue #27 https://github.com/meshtastic/protobufs/issues/27)
18-
sed -i '' -E "s/^None = 0/globals()['None'] = 0/" meshtastic/mesh_pb2.py
28+
SEDCMD="sed -i '' -E"
1929
else
20-
sed -i -e 's/^import.*_pb2/from . \0/' meshtastic/*.py
21-
# automate the current workaround (may be related to Meshtastic-protobufs issue #27 https://github.com/meshtastic/protobufs/issues/27)
22-
sed -i -e "s/^None = 0/globals()['None'] = 0/" meshtastic/mesh_pb2.py
30+
SEDCMD="sed -i -E"
2331
fi
32+
33+
34+
# change the package names to meshtastic.protobuf
35+
$SEDCMD 's/^package meshtastic;/package meshtastic.protobuf;/' "${INDIR}/"*.proto
36+
# fix the imports to match
37+
$SEDCMD 's/^import "meshtastic\//import "meshtastic\/protobuf\//' "${INDIR}/"*.proto
38+
39+
# Generate the python files
40+
./nanopb-0.4.8/generator-bin/protoc -I=$TMPDIR/in --python_out "${OUTDIR}" "--mypy_out=${PYIDIR}" $INDIR/*.proto
41+
42+
# Change "from meshtastic.protobuf import" to "from . import"
43+
$SEDCMD 's/^from meshtastic.protobuf import/from . import/' "${OUTDIR}"/meshtastic/protobuf/*pb2*.py[i]
44+
45+
# Create a __init__.py in the out directory
46+
touch "${OUTDIR}/meshtastic/protobuf/__init__.py"
47+
48+
# Copy to the source controlled tree
49+
mkdir -p meshtastic/protobuf
50+
rm -rf meshtastic/protobuf/*pb2*.py
51+
cp "${OUTDIR}/meshtastic/protobuf"/* meshtastic/protobuf
52+
53+
exit 0

meshtastic/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ def onConnection(interface, topic=pub.AUTO_TOPIC): # called when we (re)connect
8282
from pubsub import pub # type: ignore[import-untyped]
8383
from tabulate import tabulate
8484

85-
from meshtastic import (
85+
from meshtastic.node import Node
86+
from meshtastic.util import DeferredExecution, Timeout, catchAndIgnore, fixme, stripnl
87+
88+
from .protobuf import (
8689
admin_pb2,
8790
apponly_pb2,
8891
channel_pb2,
@@ -94,10 +97,10 @@ def onConnection(interface, topic=pub.AUTO_TOPIC): # called when we (re)connect
9497
remote_hardware_pb2,
9598
storeforward_pb2,
9699
telemetry_pb2,
100+
)
101+
from . import (
97102
util,
98103
)
99-
from meshtastic.node import Node
100-
from meshtastic.util import DeferredExecution, Timeout, catchAndIgnore, fixme, stripnl
101104

102105
# Note: To follow PEP224, comments should be after the module variable.
103106

meshtastic/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import meshtastic.test
2121
import meshtastic.util
2222
from meshtastic import mt_config
23-
from meshtastic import channel_pb2, config_pb2, portnums_pb2, remote_hardware, BROADCAST_ADDR
23+
from meshtastic.protobuf import channel_pb2, config_pb2, portnums_pb2
24+
from meshtastic import remote_hardware, BROADCAST_ADDR
2425
from meshtastic.version import get_active_version
2526
from meshtastic.ble_interface import BLEInterface
2627
from meshtastic.mesh_interface import MeshInterface

meshtastic/admin_pb2.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

meshtastic/apponly_pb2.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

meshtastic/atak_pb2.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

meshtastic/channel_pb2.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

meshtastic/clientonly_pb2.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)