Skip to content

Add xmsconan format command for C++ and Python#78

Open
wdolinar wants to merge 1 commit into
masterfrom
format/format-code
Open

Add xmsconan format command for C++ and Python#78
wdolinar wants to merge 1 commit into
masterfrom
format/format-code

Conversation

@wdolinar

@wdolinar wdolinar commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

Adds an xmsconan format subcommand that formats C++ with clang-format and Python with yapf, with both formatters bundled as dependencies so the command works out of the box after pip install xmsconan.

  • Walks the given paths (default: cwd), collecting C++ (.cpp/.cxx/.cc/.h/.hpp/.hxx) and Python (.py), skipping build/vcs/cache dirs plus tests/fixtures (matched by trailing path components at any depth) and _package.
  • Formats in place by default; --check reports diffs and exits non-zero without modifying files (CI gate). --cpp-only / --py-only / repeatable --exclude DIR modifiers.
  • PATH-independent tool resolution: clang-format via the wheel's bundled binary (get_executable), yapf via python -m yapf in the same interpreter.
  • C++ uses the repo's own .clang-format; Python uses a fixed style {based_on_style: facebook, column_limit: 120} with --no-local-style.

Changes

  • xmsconan/format_tools/ — new package implementing the command.
  • xmsconan/cli.pyformat registered in the COMMANDS dispatcher.
  • pyproject.tomlclang-format + yapf added to dependencies; xmsconan_format console script.

Documentation

Per this repo's doc-drift policy, user-facing docs are updated in this PR:

  • README.md — Unified CLI table row.
  • docs/USAGE.md — CLI table row + new §20 "Formatting code".

Testing

  • flake8 . — clean.
  • python -m pytest tests/ — 552 passed, 5 skipped (env-gated integration + platform-specific).
  • New tests/test_format.py (16 tests): discovery/exclusions (incl. subpath + explicit-root fixture protection), apply mode, --check, language filters, PATH-independent resolution, missing-binary + apply-mode error, and main() exit code.
  • Manual smoke test: --check → apply → --check round-trip verified on a scratch tree.

Add an `xmsconan format` subcommand that formats C++ with clang-format
and Python with yapf. It walks the given paths (default: cwd), skipping
build/vcs/cache directories plus tests/fixtures and _package, and formats
in place; --check reports diffs and exits non-zero without modifying
files. Tool resolution is PATH-independent (bundled clang-format binary;
`python -m yapf`). C++ uses the repo's own .clang-format; Python uses a
fixed style (facebook base, 120 columns, --no-local-style). A mistyped
input path fails loud (FormatToolError) rather than exiting 0.

- Add clang-format and yapf to project dependencies and an
  xmsconan_format console script.
- Register "format" in the cli.py COMMANDS dispatcher.
- Document the command in README.md and docs/USAGE.md (new section 20).
- Add tests/test_format.py (flake8 clean; 37 format tests, 558 total).
@wdolinar wdolinar force-pushed the format/format-code branch from 0e92ab0 to deb3f59 Compare June 7, 2026 05:01
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