Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Crudely merges Sphinx API documentaion with Radon, Flake8 & Coverage output
- Author: Liam Deacon
- Report generation requires:
- - nose
- - coverage
- - lxml
- - flake8-html
- - radon
- API documentation:
- - sphinx
- '''
- from __future__ import print_function
- from bs4 import BeautifulSoup as Soup
- from json2html import json2html
- import os
- import shutil
- from glob import glob
- index = 'build/sphinx/html/index.html'
- public = 'build/public'
- index_html = Soup(open(index), 'lxml')
- for i, link in enumerate(reversed(index_html.findAll('li'))):
- if link.a.span:
- break
- links = link
- tag = '''
- <li><a class="reference internal" href="{0}/index.html"><span class="std std-ref">{1} Report</span></a></li>
- '''
- reports = ('coverage', 'flake8', 'radon')
- for link in reports:
- soup = Soup(tag.format(link, link.capitalize()), 'lxml')
- links.insert_after(soup.html.body.li)
- shutil.rmtree(public)
- shutil.copytree(os.path.dirname(index), public)
- radon = Soup('<p></p>', 'lxml')
- for name, radon_metric in (('Raw Metrics', 'raw'),
- ('Code Complexity', 'cc'), ('Maintainability Index', 'mi')):
- with open('build/radon/{}.json'.format(radon_metric)) as f:
- table = json2html.convert(f.read())
- section = Soup('<h1>{}</h1><p>{}</p>'.format(name, table), 'lxml')
- radon.find('p').insert_after(section.html.body)
- os.makedirs(os.path.join('build', 'radon'), exist_ok=True)
- with open(os.path.join('build', 'radon', 'index.html'), 'w') as f:
- f.write(str(radon).replace('<p></p>', ''))
- for d in reports:
- _dir = os.path.join(public, d)
- if os.path.exists(_dir):
- shutil.rmtree(_dir)
- shutil.copytree(os.path.join('build', d), _dir)
- print(index_html, file=open(os.path.join(public, 'index.html'), 'w'))
Add Comment
Please, Sign In to add comment