Skip to content
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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions pep8radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Copy link
Owner Author

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)


# autopep8 options
parser.add_argument('-p', '--pep8-passes', metavar='n',
default=-1, type=int,
Expand Down Expand Up @@ -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:
Copy link
Owner Author

Choose a reason for hiding this comment

The 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.'
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def version():
if line.startswith('__version__'):
return parse(line).body[0].value.s


def readme():
try:
import pypandoc
Expand All @@ -30,7 +31,7 @@ def readme():
['autopep8 >= 1.0.2'] +
(['argparse'] if version_info < (2, 7) else []) +
['colorama'] +
['docformatter >= 0.6.1']
['docformatter >= 0.6.1'],
)

setup(
Expand Down