Optimize passing multiple paths to usort CLI #161
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, when passing multiple paths to the usort CLI, it would
call
usort_path()
separately for each path given, preventing anychance of parallel processing. This means
usort check usort/**/*.py
would take ~10X longer than
usort check usort
, and also results indouble formatting if a path appeared or was a child of multiple
arguments:
With the changes from #160, this is partially masked by removing the
cost of starting child processes, but still results in linear time
increase when passing many arguments:
This builds on #160 by updating
usort_path()
to optionally take aniterable of Path objects, and materializes a set of paths to sort before
actually starting child processes. This allows maximum utilization of
multiprocessing, and also eliminates any double-formatting if the CLI
arguments include any overlap of paths: