diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 0000000..6697a0b --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,33 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Set up Python 3.13 + uses: actions/setup-python@v3 + with: + python-version: "3.13" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install black pytest meshtastic + - name: Lint with black + run: | + black --check ./ + - name: Test with pytest + run: | + pytest diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 967749b..0b4ff0c 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -27,8 +27,10 @@ jobs: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true working-directory: ./web - - name: Set up dependencies + - name: Set up dependencies run: bundle install + - name: Run rufo + run: bundle exec rufo --check . - name: Run tests run: | mkdir -p tmp/test-results diff --git a/data/mesh.py b/data/mesh.py index 314d67b..8848d2c 100644 --- a/data/mesh.py +++ b/data/mesh.py @@ -45,7 +45,9 @@ def _post_json(path: str, payload: dict): return url = f"{INSTANCE}{path}" data = json.dumps(payload).encode("utf-8") - req = urllib.request.Request(url, data=data, headers={"Content-Type": "application/json"}) + req = urllib.request.Request( + url, data=data, headers={"Content-Type": "application/json"} + ) if API_TOKEN: req.add_header("Authorization", f"Bearer {API_TOKEN}") try: @@ -290,13 +292,17 @@ def main(): node_items = _node_items_snapshot(nodes) if node_items is None: if DEBUG: - print("[debug] skipping node snapshot; nodes changed during iteration") + print( + "[debug] skipping node snapshot; nodes changed during iteration" + ) else: for node_id, n in node_items: try: upsert_node(node_id, n) except Exception as e: - print(f"[warn] failed to update node snapshot for {node_id}: {e}") + print( + f"[warn] failed to update node snapshot for {node_id}: {e}" + ) if DEBUG: print(f"[debug] node object: {n!r}") except Exception as e: diff --git a/tests/test_mesh.py b/tests/test_mesh.py index c61f433..1915d8f 100644 --- a/tests/test_mesh.py +++ b/tests/test_mesh.py @@ -30,7 +30,9 @@ def mesh_module(monkeypatch): meshtastic_mod.serial_interface = serial_interface_mod monkeypatch.setitem(sys.modules, "meshtastic", meshtastic_mod) - monkeypatch.setitem(sys.modules, "meshtastic.serial_interface", serial_interface_mod) + monkeypatch.setitem( + sys.modules, "meshtastic.serial_interface", serial_interface_mod + ) # Stub pubsub.pub pubsub_mod = types.ModuleType("pubsub") @@ -121,7 +123,9 @@ def test_node_to_dict_handles_nested_structures(mesh_module): def test_store_packet_dict_posts_text_message(mesh_module, monkeypatch): mesh = mesh_module captured = [] - monkeypatch.setattr(mesh, "_post_json", lambda path, payload: captured.append((path, payload))) + monkeypatch.setattr( + mesh, "_post_json", lambda path, payload: captured.append((path, payload)) + ) packet = { "id": 123, @@ -160,7 +164,9 @@ def test_store_packet_dict_posts_text_message(mesh_module, monkeypatch): def test_store_packet_dict_ignores_non_text(mesh_module, monkeypatch): mesh = mesh_module captured = [] - monkeypatch.setattr(mesh, "_post_json", lambda *args, **kwargs: captured.append(args)) + monkeypatch.setattr( + mesh, "_post_json", lambda *args, **kwargs: captured.append(args) + ) packet = { "id": 456, diff --git a/web/app.rb b/web/app.rb index d3a9717..2bed0eb 100644 --- a/web/app.rb +++ b/web/app.rb @@ -28,7 +28,7 @@ set :views, File.join(__dir__, "views") SITE_NAME = ENV.fetch("SITE_NAME", "Meshtastic Berlin") DEFAULT_CHANNEL = ENV.fetch("DEFAULT_CHANNEL", "#MediumFast") -DEFAULT_FREQUENCY= ENV.fetch("DEFAULT_FREQUENCY", "868MHz") +DEFAULT_FREQUENCY = ENV.fetch("DEFAULT_FREQUENCY", "868MHz") MAP_CENTER_LAT = ENV.fetch("MAP_CENTER_LAT", "52.502889").to_f MAP_CENTER_LON = ENV.fetch("MAP_CENTER_LON", "13.404194").to_f MAX_NODE_DISTANCE_KM = ENV.fetch("MAX_NODE_DISTANCE_KM", "137").to_f @@ -290,12 +290,12 @@ end get "/" do erb :index, locals: { - site_name: SITE_NAME, - default_channel: DEFAULT_CHANNEL, - default_frequency: DEFAULT_FREQUENCY, - map_center_lat: MAP_CENTER_LAT, - map_center_lon: MAP_CENTER_LON, - max_node_distance_km: MAX_NODE_DISTANCE_KM, - matrix_room: MATRIX_ROOM - } + site_name: SITE_NAME, + default_channel: DEFAULT_CHANNEL, + default_frequency: DEFAULT_FREQUENCY, + map_center_lat: MAP_CENTER_LAT, + map_center_lon: MAP_CENTER_LON, + max_node_distance_km: MAX_NODE_DISTANCE_KM, + matrix_room: MATRIX_ROOM, + } end