Skip to content

mavparm: honour use_tabs for params present in only one file - #1275

Open
azrabano23 wants to merge 1 commit into
ArduPilot:masterfrom
azrabano23:fix-796-mavparmdiff-tabs
Open

mavparm: honour use_tabs for params present in only one file#1275
azrabano23 wants to merge 1 commit into
ArduPilot:masterfrom
azrabano23:fix-796-mavparmdiff-tabs

Conversation

@azrabano23

Copy link
Copy Markdown

What was wrong

mavparmdiff.py -t is documented as "use tabs delimiter between columns for the output", but only the header row and the rows for parameters that differ between the two files were tab-delimited. Parameters present in only one file were still printed with the fixed-width, space-padded format, so the output could not be imported into a spreadsheet (issue #796).

With two three-line parameter files (cat -vt shows tabs as ^I):

$ mavparmdiff.py -t p1.parm p2.parm | cat -vt
PARAMETER^IFILE1^IFILE2
ADSB_ENABLE            0.0000
ADSB_TYPE                           0.0000
AHRS_TRIM_X^I-0.0135^I-0.0512

Root cause

In MAVParmDict.diff() the use_tabs flag was only checked in the header branch and in the "value differs" branch. The "only in FILE1" and "only in FILE2" branches always used the %-16.16s %12.4f formats.

The fix

When use_tabs is set, print NAME\tVALUE for params only in FILE1 and NAME\t\tVALUE for params only in FILE2, so the columns line up with the header and the differing-value rows. The space-padded output is unchanged.

$ mavparmdiff.py -t p1.parm p2.parm | cat -vt
PARAMETER^IFILE1^IFILE2
ADSB_ENABLE^I0.0000
ADSB_TYPE^I^I0.0000
AHRS_TRIM_X^I-0.0135^I-0.0512

Verification

Added test_diff_use_tabs in tests/test_mavparm.py, which captures diff(..., use_tabs=True, header=True) output and checks every row is purely tab-delimited. It fails on master (AssertionError on the space-padded rows) and passes with this change.

python3 -m pytest tests/test_mavparm.py -q   # 4 passed
flake8 mavparm.py tests/test_mavparm.py --count --select=E9,F63,F7,F82   # 0

Tested with Python 3.12 on macOS.

Fixes #796

🤖 Generated with Claude Code

`mavparmdiff.py -t` switches the output delimiter to tabs, but
MAVParmDict.diff() only applied use_tabs to the header and to
parameters whose values differ. Parameters present in only one of the
two files were still printed with the fixed-width space-padded format,
so a tab-separated diff could not be imported into a spreadsheet:

    PARAMETER\tFILE1\tFILE2
    ADSB_ENABLE            0.0000
    ADSB_TYPE                           0.0000
    AHRS_TRIM_X\t-0.0135\t-0.0512

Emit "NAME\tVALUE" for params only in FILE1 and "NAME\t\tVALUE" for
params only in FILE2 when use_tabs is set, matching the column layout
of the header and of the differing-value rows. The space-padded format
is unchanged.

Add a regression test that captures diff() output with use_tabs=True
and checks every row is purely tab-delimited.

Fixes ArduPilot#796

Signed-off-by: Azra Bano <azrabano.work@gmail.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

mavparmdiff: use_tabs ignored for parameters not present in both files

1 participant