Skip to content

Commit

Permalink
fix: resolve python imports, package pyinstaller exec correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Jan 9, 2025
1 parent 23e24af commit e7711d2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ if ! uv pip install pyinstaller -q; then
exit 1
fi

uv run pyinstaller --onefile --hidden-import="googleapiclient" src/main.py
uv run pyinstaller --onefile --hidden-import="googleapiclient" -p src src/main.py
tar -czvf dist/archive.tar.gz ./dist/main
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
viam-sdk
adafruit-circuitpython-mcp3xxx
google-api-python-client
RPi.GPIO
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi

source $VENV_NAME/bin/activate

if ! uv pip sync requirements.txt; then
if ! uv pip install -r requirements.txt; then
echo "unable to sync requirements to venv"
exit 1
fi
7 changes: 0 additions & 7 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
"""
This file registers the model with the Python SDK.
"""

from viam.components.sensor import Sensor
from viam.resource.registry import Registry, ResourceCreatorRegistration

from .mcp300x import mcp300x

Registry.register_resource_creator(Sensor.SUBTYPE, mcp300x.MODEL, ResourceCreatorRegistration(mcp300x.new, mcp300x.validate))
12 changes: 10 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import asyncio

from viam.components.sensor import Sensor
from viam.resource.registry import Registry, ResourceCreatorRegistration
from viam.module.module import Module
from .mcp300x import mcp300x
from mcp300x import mcp3xxx


async def main():
"""This function creates and starts a new module, after adding all desired resources.
Resources must be pre-registered. For an example, see the `__init__.py` file.
"""
Registry.register_resource_creator(
Sensor.SUBTYPE,
mcp3xxx.MODEL,
ResourceCreatorRegistration(mcp3xxx.new, mcp3xxx.validate),
)
module = Module.from_args()
module.add_model_from_registry(Sensor.SUBTYPE, mcp300x.MODEL)
module.add_model_from_registry(Sensor.SUBTYPE, mcp3xxx.MODEL)
await module.start()


if __name__ == "__main__":
asyncio.run(main())
6 changes: 0 additions & 6 deletions src/mcp300x.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ def reconfigure(
self.channel_map = dict(config.attributes.fields["channel_map"].struct_value)
LOGGER.debug(f"Channel map is {self.channel_map}")

if getattr(self, "spi") is not None:
self.spi.deinit()

if getattr(self, "cs") is not None:
self.cs.deinit()

# Sensor Pin Logic
# Creates the SPI bus
self.spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
Expand Down

0 comments on commit e7711d2

Please sign in to comment.