Skip to content

refactor(sim): make lora mesh cli importable#67

Merged
GUVWAF merged 1 commit into
meshtastic:masterfrom
Komzpa:codex/split-cli-import-hygiene
May 3, 2026
Merged

refactor(sim): make lora mesh cli importable#67
GUVWAF merged 1 commit into
meshtastic:masterfrom
Komzpa:codex/split-cli-import-hygiene

Conversation

@Komzpa

@Komzpa Komzpa commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • make loraMesh.py importable by moving CLI startup into main() and lazy-loading simulation/GUI plumbing
  • add --no-gui, --simtime-seconds, and --period-seconds for headless smoke/CI runs
  • defer config, RNG, and logging mutations until CLI input resolves into an accepted scenario
  • document the headless CLI path and add parser/import regression tests

Validation

  • .venv/bin/python -m unittest tests.test_lora_mesh_cli
  • .venv/bin/python -m unittest
  • /home/kom/.local/bin/ruff check loraMesh.py lib/config.py tests/test_lora_mesh_cli.py
  • .venv/bin/python -m compileall -q .
  • .venv/bin/python -u loraMesh.py 2 --no-gui --simtime-seconds 5 --period-seconds 0.5
  • git diff --check

Split from draft rollup #64.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e82dfedcf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread loraMesh.py
Comment on lines +60 to +63
if parsed_arguments.period_seconds is not None:
if not math.isfinite(parsed_arguments.period_seconds) or parsed_arguments.period_seconds <= 0:
parser.error("--period-seconds must be a positive finite number")
period = int(parsed_arguments.period_seconds * conf.ONE_SECOND_INTERVAL)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject sub-millisecond period overrides

The new --period-seconds path validates only the float input and then truncates to milliseconds with int(...); values between 0 and 0.001 seconds become 0 here, which later propagates into node configs and causes expovariate(1.0 / period) to divide by zero in MeshNode.get_next_time during simulation startup. This makes a CLI invocation that passes validation fail at runtime, so the parser should reject values that round to < 1 tick (and similarly for simtime if zero-length runs are not intended).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, well probably good to check for less than let's say 0.01 seconds here, because that is ridiculously low for LoRa anyway.

Comment thread loraMesh.py
# Keep the heavier simulation/GUI import out of module import. That makes
# CLI parsing unit-testable and lets CI/tools import loraMesh without
# starting Matplotlib/Tk plumbing as a side effect.
from lib.discrete_event_sim import DiscreteEventSim

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid importing Tk stack on --no-gui runs

run_simulation always imports DiscreteEventSim before checking conf.GUI_ENABLED, but lib/discrete_event_sim.py imports lib.gui at module load time; lib.gui hard-requires TkAgg and exits if Tk is unavailable. As a result, --no-gui still fails in headless/CI environments without tkinter, which contradicts the new headless CLI behavior introduced in this change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed correct, DiscreteEventSim currently always requires lib.gui.

@GUVWAF

GUVWAF commented May 2, 2026

Copy link
Copy Markdown
Member

Thanks for this split, this is much easier to go through. I like the additional parameters, and also that you can run it without using Tk. Can you have a look at the two comments? They seem both valid to me.

@Komzpa
Komzpa force-pushed the codex/split-cli-import-hygiene branch from 6e82dfe to 82ffb41 Compare May 2, 2026 20:54

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82ffb41c7c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread loraMesh.py Outdated
Comment on lines +51 to +54
simtime = conf.SIMTIME
period = conf.PERIOD
gui_enabled = conf.GUI_ENABLED
plot_enabled = conf.PLOT

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reset per-run CLI defaults instead of reusing mutated config

The new importable entrypoint now allows multiple main()/parse_params() calls in one process, but this code derives option defaults from the already-mutated conf object (SIMTIME, PERIOD, GUI_ENABLED, PLOT). After one run with overrides (for example --no-gui or --simtime-seconds), a later run without those flags silently inherits the previous values, producing incorrect experiment settings and headless behavior unexpectedly. This is a regression in the new reusable CLI flow because accepted runs are no longer isolated from each other.

Useful? React with 👍 / 👎.

@Komzpa
Komzpa force-pushed the codex/split-cli-import-hygiene branch from 82ffb41 to e39a2ac Compare May 2, 2026 21:08

@GUVWAF GUVWAF left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I tested this and it looks good to merge now!

@GUVWAF
GUVWAF merged commit c4ede44 into meshtastic:master May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants