Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import re
- from subprocess import Popen, PIPE
- import time
- NUM_PARALLEL_PYLINT_JOBS = 8
- PYLINT_PASS_THRESHOLD = 10
- NUM_FILES = [10, 25, 50, 100, 150, 200, 400]
- def find_all_python_files(num_files_to_find):
- python_files = []
- for root, dirs, files in os.walk('.'):
- for file in files:
- if file.endswith('.py'):
- if len(python_files) < num_files_to_find:
- python_files.append(os.path.join(root, file))
- else:
- break
- return python_files
- def run_pylint_on_files(py_files):
- # input: list of filepaths
- py_files = " ".join(py_files)
- pylint = Popen(
- ("pylint -j %d -f text %s" % (NUM_PARALLEL_PYLINT_JOBS, py_files)).split(),
- stdout=PIPE)
- pylint.wait()
- output = pylint.stdout.read()
- result_re = re.compile(r"Your code has been rated at ([\d\.]+)/10")
- result = float(result_re.findall(output)[0])
- if result < PYLINT_PASS_THRESHOLD:
- print 'git: fatal: commit failed, Pylint tests failing.'
- else:
- print 'all good; pylint passed'
- def profile_pylint(filesets, iterations=3):
- times_spent = {}
- for fs in filesets:
- sum_times_spent = 0.0
- for i in range(iterations):
- start_time = time.time()
- run_pylint_on_files(fs)
- end_time = time.time()
- sum_times_spent += (end_time - start_time)
- avg_time_spent = sum_times_spent / iterations
- times_spent[len(fs)] = avg_time_spent
- return times_spent
- filesets = []
- for n_files in NUM_FILES:
- files = find_all_python_files(num_files_to_find=n_files)
- filesets.append(files)
- times_spent = profile_pylint(filesets=filesets, iterations=3)
- for t in times_spent:
- print '# Files: {} \t Avg. Seconds Spent: {}'.format(t, times_spent[t])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement