SHARE
TWEET

Untitled

a guest Aug 17th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import os
  3. import re
  4. from subprocess import Popen, PIPE
  5. import time
  6.  
  7.  
  8. NUM_PARALLEL_PYLINT_JOBS = 8
  9. PYLINT_PASS_THRESHOLD = 10
  10. NUM_FILES = [10, 25, 50, 100, 150, 200, 400]
  11.  
  12.  
  13. def find_all_python_files(num_files_to_find):
  14.     python_files = []
  15.     for root, dirs, files in os.walk('.'):
  16.         for file in files:
  17.             if file.endswith('.py'):
  18.                 if len(python_files) < num_files_to_find:
  19.                     python_files.append(os.path.join(root, file))
  20.                 else:
  21.                     break
  22.     return python_files
  23.  
  24.  
  25. def run_pylint_on_files(py_files):
  26.     # input: list of filepaths
  27.     py_files = " ".join(py_files)
  28.  
  29.     pylint = Popen(
  30.         ("pylint -j %d -f text %s" % (NUM_PARALLEL_PYLINT_JOBS, py_files)).split(),
  31.         stdout=PIPE)
  32.     pylint.wait()
  33.     output = pylint.stdout.read()
  34.  
  35.     result_re = re.compile(r"Your code has been rated at ([\d\.]+)/10")
  36.     result = float(result_re.findall(output)[0])
  37.  
  38.     if result < PYLINT_PASS_THRESHOLD:
  39.         print 'git: fatal: commit failed, Pylint tests failing.'
  40.     else:
  41.         print 'all good; pylint passed'
  42.  
  43.  
  44. def profile_pylint(filesets, iterations=3):
  45.     times_spent = {}
  46.     for fs in filesets:
  47.         sum_times_spent = 0.0
  48.         for i in range(iterations):
  49.             start_time = time.time()
  50.             run_pylint_on_files(fs)
  51.             end_time = time.time()
  52.             sum_times_spent += (end_time - start_time)
  53.         avg_time_spent = sum_times_spent / iterations
  54.         times_spent[len(fs)] = avg_time_spent
  55.     return times_spent
  56.  
  57.  
  58. filesets = []
  59. for n_files in NUM_FILES:
  60.     files = find_all_python_files(num_files_to_find=n_files)
  61.     filesets.append(files)
  62.  
  63. times_spent = profile_pylint(filesets=filesets, iterations=3)
  64. for t in times_spent:
  65.     print '# Files: {} \t Avg. Seconds Spent: {}'.format(t, times_spent[t])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top