Skip to content

refactor(scripts): logging cleanup, helper extraction, inline None-checks - #2329

Open
igoutta wants to merge 3 commits into
ArduPilot:masterfrom
igoutta:fix/scripts-pdef-regen-and-maintenance
Open

igoutta wants to merge 3 commits into
ArduPilot:masterfrom
igoutta:fix/scripts-pdef-regen-and-maintenance

Conversation

@igoutta

@igoutta igoutta commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Refactor scripts/generate_pdef.xml_metadata.py and
scripts/regenerate_app_screenshots_fully_automated.py for readability and
consistent logging, and add two behavior changes to pdef regeneration
(--git-tag provenance, non-zero exit on failures).

Addresses the six blocking items from review on #2321.

Summary of changes

scripts/generate_pdef.xml_metadata.py

Behavior

  • Pass --git-tag to param_parse.py so the emitter writes the tag
    provenance comment itself. The previous post-processing step (reparse
    XML with lxml, insert a comment at line 3, rewrite) is removed, and
    the lxml runtime dependency is dropped from ensure_dependencies.
  • Run param_parse.py with check=False. The script exits with the
    number of validation warnings, not a boolean, and writes
    apm.pdef.xml before exiting. Treating non-zero as fatal discarded
    valid output. Now: warn, log stdout/stderr at DEBUG, keep the file.
  • Delete any stale apm.pdef.xml before generation so the post-generation
    existence check can't copy an artifact we didn't produce.
  • Restore the ArduPilot repo to the pre-checkout ref after each version
    (captured with git rev-parse HEAD before git checkout). Previously
    the tree was left on the last tag.
  • main returns non-zero when any per-version generation or any rsync
    fails. Previously failures were swallowed and the process exited 0.

Refactor

  • Extract _should_skip_version, _generate_pdefs_for_vehicle,
    _vehicle_dir, _redact_rsync_cmd.
  • get_vehicle_tags no longer os.chdirs; uses cwd=ardupilot_dir and
    a regex filter (^\w+-\d+\.\d+\.\d+$) so multi-digit minors like
    4.10.x aren't silently dropped by the old single-digit pattern.
  • print → logger.* throughout; logger.exception used for error
    paths so the traceback is captured.
  • Add timeout= to all subprocess calls (120s for git tag, 60s for
    git rev-parse, 300s for git checkout, 600s for param_parse.py,
    1800s for rsync).
  • _redact_rsync_cmd strips user:pass@ from rsync URLs before logging,
    so the DEBUG argv line is credential-safe if the URL ever changes.
  • Consolidate the four inline if version[0] == ... continue skip rules
    into _should_skip_version(version) -> bool using (major, minor) < (4, 6).
    The old AP_Periph 3.x exception was unreachable (AP_Periph isn't in
    VEHICLE_TYPES) and is dropped.

scripts/regenerate_app_screenshots_fully_automated.py

Refactor

  • capture_target: dict-based dispatch for _SIMPLE_ACTIONS and
    _VEHICLE_DIR_ACTIONS, frozenset for _VEHICLE_OPENER_HIGHLIGHT, then
    a match statement for the remaining cases.
  • Optional CaptureTarget attributes (current_file, gui_complexity,
    variant) are copied into locals and checked with is None before
    use, so mypy narrows at each call site.
  • New _required_widget_box(parent, predicate, error_msg) consolidates
    the "find descendant, raise if missing, return screen box" pattern
    used by six call sites (_vehicle_opener_highlight_box × 4,
    _find_template_browse_button, _find_create_button).
  • patch.object(tk.Tk, "mainloop", lambda _self: None) →
    return_value=None.
  • except Exception as exc: + logging.exception("...: %s", exc) →
    except Exception: + logging.exception("..."), since
    logger.exception already includes the exception.

Testing

  • mypy scripts/regenerate_app_screenshots_fully_automated.py clean
  • pytest unaffected (scripts-only)
  • Manual dry run of generate_pdef.xml_metadata.py on a pre-4.6 tag
    (skipped) and a 4.7 tag (generated, --git-tag comment present,
    exit code 0)
  • Flight controller hardware — not applicable

@igoutta
igoutta requested a review from amilcarlucas as a code owner November 3, 2026 16:47
@amilcarlucas

Copy link
Copy Markdown
Collaborator

How does this compare to #2327 that I mentioned on #2321 ?

@igoutta

igoutta commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Replacement for #2321. Same refactor — the diff between the two PRs is
three behavior fixes and commit hygiene.

Behavior fixes vs #2321:

  • instructions_popup was dropped when the translation extractor was
    split into helpers; restored.
  • The pre-4.6 skip also required the local file to be missing, so
    pre-4.6 tags could still reach param_parse.py (crash on 3.13+);
    skip is unconditional again.
  • main returned 0 on failure; now returns 1.

Plus review items: proper branch, sign-off, conventional subjects.

The refactor against upstream is unchanged from #2321. Not going to
argue for it here — if any of the refactor decisions (dropping lxml
in favor of --git-tag, collapsing the inline skip ifs into
_should_skip_version, etc.) need rethinking, that's a separate
conversation. Didn't want to change the shape between the two PRs to
make the comparison easier.

@igoutta

igoutta commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

The app needs for a serious reorganization setup. Perhaps rework of the frontend. Nothing crazy, just upgrade Tkinter to the new version 9 and apply the new default skins will do wonders.

@igoutta

igoutta commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

In 12 hours I'll start working on my job again so I'm going to leave it for now but the experience have been good. Love to learn reducing cognitive complexity since always shows hidden bugs.

@amilcarlucas

Copy link
Copy Markdown
Collaborator

The #1761 already upgrades to python 3.15.2 and Tkinter 9
So once that is merged we'll have that. #2327 has been merged, it removed an outdated script.
I also added ArduPilot/ardupilot#35000 to generate documentation fro 4.7.x releases.

@amilcarlucas

amilcarlucas commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Can you please rebase this on master?
Master already uses python 3.15.2 and Tcl/Tk 9.0.4 and scripts/generate_pdef.xml_metadata.py has been deleted from master due to ArduPilot/ardupilot#35000

…ecks

- crawl_ardupilot_wiki.py: split remove_duplicates into per-rule
  predicates and find_all_links into guard helpers, dropping both
  functions from radon C to A/B; logging and exception-handling
  cleanup.
- regenerate_app_screenshots_fully_automated.py: replace _require_attr
  with inline None-checks so mypy can narrow types; separate handler
  variables to avoid incompatible Callable reuse.
- download_motor_diagrams.py: logging cleanup.

Signed-off-by: GA. <igoutta@users.noreply.github.com>
…talog

The process_configuration_steps refactor split the function into _add_text_fields/_add_jump_messages/_add_change_reasons but dropped the instructions_popup branch, so those strings stopped reaching the catalog. Add _add_instructions_popup and call it in the same position as before the refactor.

Signed-off-by: GA. <igoutta@users.noreply.github.com>
@igoutta
igoutta force-pushed the fix/scripts-pdef-regen-and-maintenance branch from bf23e0e to 9503980 Compare November 15, 2026 23:31
@igoutta igoutta changed the title refactor(scripts): logging cleanup and pdef regen bug fix refactor(scripts): logging cleanup, helper extraction, inline None-checks Nov 15, 2026
Comment on lines -172 to +176
except (httpx2.HTTPError, httpx2.InvalidURL) as e:
logging.error("Network error crawling %s: %s", current_url, str(e))
except (httpx2.HTTPError, httpx2.InvalidURL):
logging.exception("Network error crawling %s:", current_url)
broken_urls.add(current_url)
visited_urls.discard(current_url)
except (KeyError, ValueError) as e:
logging.error("URL processing error for %s: %s", current_url, str(e))
except (KeyError, ValueError):
logging.exception("URL processing error for %s:", current_url)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The : after the %s seams superfulous


except OSError:
logger.exception("Failed to download %s: ", filename)
logger.exception("Failed to download %s:", filename)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The : after the %s seams superfluous

Signed-off-by: GA. <igoutta@users.noreply.github.com>
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 44823164767

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Warning

No base build found for commit 8dbe6b8 on master.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 96.142%

Details

  • Patch coverage: No coverable lines changed in this PR.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 31651
Covered Lines: 30430
Line Coverage: 96.14%
Relevant Branches: 9590
Covered Branches: 8740
Branch Coverage: 91.14%
Branches in Coverage %: No
Coverage Strength: 2.87 hits per line

💛 - Coveralls

This branch has not been deployed

No deployments
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.

3 participants