Skip to content

Format repeated input filenames only once - #1343

Open
vinsymoyya wants to merge 1 commit into
google:mainfrom
vinsymoyya:improve/deduplicate-format-inputs
Open

vinsymoyya wants to merge 1 commit into
google:mainfrom
vinsymoyya:improve/deduplicate-format-inputs

Conversation

@vinsymoyya

Copy link
Copy Markdown

Fixes #1342.

YAPF formats every occurrence of a filename, so overlapping inputs such as yapf -r src src/example.py emit the same source twice. Repeated inputs also duplicate diffs and submit redundant parallel jobs.

Deduplicate filename strings once at the FormatFiles boundary, preserving first-occurrence order for sequential formatting. This benefits both CLI and direct callers. Document the behavior and add real CLI tests for repeated file arguments, ordering, recursive overlaps, and parallel mode. Path spellings and alias resolution remain unchanged.

Validation on Windows, Python 3.12.13:

  • The new tests fail on upstream main for repeated arguments and for recursive overlap in sequential and parallel modes, then pass with the improvement.
  • python -m pytest -q: 613 passed, 2 subtests passed.
  • Changed Python files pass flake8, isort, and YAPF formatting; git diff --check passes.
  • Compared actual CLI runs on an archive of upstream main and this branch: ten repeated inputs produce ten formatting jobs upstream and one here; two repeated inputs produce two diffs upstream and one here. In-place output and quiet-mode exit codes remain correct.

Deduplication uses exact filename strings; differently spelled paths to the same file remain distinct.

Upstream CI and maintainer review are pending.

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.

Avoid duplicate formatting work for repeated or overlapping file inputs

1 participant