Guest User

Untitled

a guest
Mar 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. '''
  2. Crudely merges Sphinx API documentaion with Radon, Flake8 & Coverage output
  3.  
  4. Author: Liam Deacon
  5.  
  6. Report generation requires:
  7. - nose
  8. - coverage
  9. - lxml
  10. - flake8-html
  11. - radon
  12.  
  13. API documentation:
  14. - sphinx
  15. '''
  16. from __future__ import print_function
  17. from bs4 import BeautifulSoup as Soup
  18. from json2html import json2html
  19.  
  20. import os
  21. import shutil
  22. from glob import glob
  23.  
  24. index = 'build/sphinx/html/index.html'
  25. public = 'build/public'
  26.  
  27. index_html = Soup(open(index), 'lxml')
  28.  
  29. for i, link in enumerate(reversed(index_html.findAll('li'))):
  30. if link.a.span:
  31. break
  32. links = link
  33.  
  34. tag = '''
  35. <li><a class="reference internal" href="{0}/index.html"><span class="std std-ref">{1} Report</span></a></li>
  36. '''
  37.  
  38. reports = ('coverage', 'flake8', 'radon')
  39.  
  40. for link in reports:
  41. soup = Soup(tag.format(link, link.capitalize()), 'lxml')
  42. links.insert_after(soup.html.body.li)
  43.  
  44. shutil.rmtree(public)
  45. shutil.copytree(os.path.dirname(index), public)
  46.  
  47. radon = Soup('<p></p>', 'lxml')
  48. for name, radon_metric in (('Raw Metrics', 'raw'),
  49. ('Code Complexity', 'cc'), ('Maintainability Index', 'mi')):
  50. with open('build/radon/{}.json'.format(radon_metric)) as f:
  51. table = json2html.convert(f.read())
  52. section = Soup('<h1>{}</h1><p>{}</p>'.format(name, table), 'lxml')
  53. radon.find('p').insert_after(section.html.body)
  54. os.makedirs(os.path.join('build', 'radon'), exist_ok=True)
  55. with open(os.path.join('build', 'radon', 'index.html'), 'w') as f:
  56. f.write(str(radon).replace('<p></p>', ''))
  57.  
  58.  
  59. for d in reports:
  60. _dir = os.path.join(public, d)
  61. if os.path.exists(_dir):
  62. shutil.rmtree(_dir)
  63. shutil.copytree(os.path.join('build', d), _dir)
  64. print(index_html, file=open(os.path.join(public, 'index.html'), 'w'))
Add Comment
Please, Sign In to add comment