-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiprocessing #51
Open
hayd
wants to merge
2
commits into
master
Choose a base branch
from
jobs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Multiprocessing #51
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from difflib import unified_diff | ||
from itertools import takewhile | ||
import glob | ||
from multiprocessing import Manager, Process | ||
import os | ||
import re | ||
import signal | ||
|
@@ -129,6 +130,10 @@ def parse_args(arguments=None): | |
parser.add_argument('--no-color', action='store_true', | ||
help='do not print diffs in color') | ||
|
||
parser.add_argument('-j', '--jobs', type=int, metavar='n', default=0, | ||
help='number of parallel jobs; ' | ||
'match CPU count if value is less than 1') | ||
|
||
# autopep8 options | ||
parser.add_argument('-p', '--pep8-passes', metavar='n', | ||
default=-1, type=int, | ||
|
@@ -246,19 +251,39 @@ def pep8radius(self): | |
|
||
self.p('Applying autopep8 to touched lines in %s file(s).' % n) | ||
|
||
total_lines_changed = 0 | ||
pep8_diffs = [] | ||
for i, file_name in enumerate(self.filenames_diff, start=1): | ||
self.p('%s/%s: %s: ' % (i, n, file_name), end='') | ||
self.p('', min_=2) | ||
mgr = Manager() | ||
lines_changed = mgr.list() | ||
pep8_diffs = mgr.list() | ||
|
||
def pep8_fix(file_name, | ||
lines_changed=lines_changed, | ||
pep8_diffs=pep8_diffs): | ||
p_diff = self.pep8radius_file(file_name) | ||
lines_changed = udiff_lines_fixed(p_diff) if p_diff else 0 | ||
total_lines_changed += lines_changed | ||
self.p('fixed %s lines.' % lines_changed, max_=1) | ||
|
||
lines_changed += [udiff_lines_fixed(p_diff) | ||
if p_diff | ||
else 0] | ||
if p_diff and self.diff: | ||
pep8_diffs.append(p_diff) | ||
pep8_diffs += [p_diff] | ||
|
||
if True: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahem |
||
self.verbose, verbose = 0, self.verbose | ||
procs = [Process(target=pep8_fix, args=(file_name,)) | ||
for file_name in self.filenames_diff] | ||
for p in procs: | ||
p.start() | ||
for p in procs: | ||
p.join() | ||
self.verbose = verbose | ||
|
||
else: | ||
for i, file_name in enumerate(self.filenames_diff, start=1): | ||
self.p('%s/%s: %s: ' % (i, n, file_name), end='') | ||
self.p('', min_=2) | ||
pep8_fix(file_name) | ||
self.p('fixed %s lines.' % lines_changed, max_=1) | ||
|
||
total_lines_changed = sum(lines_changed) | ||
|
||
if self.in_place: | ||
self.p('pep8radius fixed %s lines in %s files.' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not doing this at all (this is a copy of autopep8 arg)