Skip to content

refactor: code style and linting cleanup#79

Open
igoropaniuk wants to merge 4 commits intoqualcomm-linux:mainfrom
igoropaniuk:refactor/linting-and-style-cleanup
Open

refactor: code style and linting cleanup#79
igoropaniuk wants to merge 4 commits intoqualcomm-linux:mainfrom
igoropaniuk:refactor/linting-and-style-cleanup

Conversation

@igoropaniuk
Copy link
Contributor

Applies automated code-quality tooling across all Python sources.
No functional changes.

  • Extract duplicated helpers (EnsureDirectoryExists, reflect,
    CalcCRC32, PrintBigWarning, PrintBigError) into a shared utils.py
  • Sort imports consistently using isort
  • Fix 95 lint violations (unused imports, bare except, undefined names,
    dead variables, boolean/identity comparisons, trailing semicolons)
    reported by ruff
  • Reformat all sources with black

EnsureDirectoryExists, PrintBigWarning, PrintBigError, reflect, and
CalcCRC32 were defined identically (or near-identically) in both
files.  Keeping two copies means any bug fix or improvement has to be
applied twice, and they have already drifted apart (different except
clauses, debug prints in only one copy).

utils.py now owns the single authoritative implementation of each
function.  PrintBigWarning and PrintBigError accept an optional
log_func parameter (default: print) so msp.py can continue routing
output through device_log without duplicating the banner strings.
msp.py exposes thin wrappers that bind log_func=device_log, leaving
all call sites unchanged.  ptool.py imports directly since it already
used print.  The ptool.py-only debug prints in CalcCRC32 (which
called the ptool-private HexPrettyPrint) are dropped as they were
not present in msp.py and are not part of the algorithm.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Unsorted imports make it harder to spot duplicates and missing
stdlib/third-party separation at a glance. isort enforces a
consistent, deterministic order (stdlib → third-party → local)
with one import per line.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Use ruff [1] linter to find/address reported issues:

- Unused imports (F401): remove codecs, math, time, traceback,
  xml.dom.minidom, Comment/Element/SubElement/tostring, and the
  unused reflect re-export from utils in msp.py.

- Undefined name (F821): log_debug was never defined in ptool.py;
  the single call site in HexPrettyPrint is replaced with print().

- Identity comparisons (E711/E714): replace `== None` with `is None`
  and `not x is None` with `x is not None`.

- Boolean comparisons (E712): replace `== True` / `== False` checks
  with plain truthiness tests or `not` prefix.

- Unused variables (F841): drop dead assignments in both files
  (parser_inst, part, CurrentSector, P, x, header_crc_offset,
  LastPartitionBeginsAt, FileNotFoundShowWarning, SectorsRemaining,
  FileFound, size).

- Semicolon style (E702/E703): split compound `stmt ; stmt` lines
  onto separate lines and remove trailing semicolons throughout
  ptool.py (GPT/MBR/EBR byte-packing loops).

[1] https://github.com/astral-sh/ruff
Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Enforces a consistent, machine-verified code style using black tool [1]
across all Python sources so that future diffs reflect only logic changes
and not incidental whitespace or quoting differences.

[1] https://github.com/psf/black
Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
@igoropaniuk
Copy link
Contributor Author

(node:1) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Repolinter Output

It seems that Repolinter is misconfigured, as this appears to be a check for Node.js (???)

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.

1 participant