Skip to content

Commit 906d7cc

Browse files
author
Álvaro Justen aka Turicas
committed
Changes all scripts to modules
1 parent fe24d07 commit 906d7cc

13 files changed

+372
-379
lines changed

get_repos.py

-36
This file was deleted.

main.py

-167
This file was deleted.

plot_graphs.py

-64
This file was deleted.

pyquality/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# coding: utf-8
2+
3+
'''Rich reports for Python code quality'''
4+
5+
from .git_utils import *
6+
from .graphs import plot_graphs
7+
from .main import analyse_repository
8+
from .report import render_report
9+
from .template import default_template
10+
from .video import render_project_history

pyquality/cli.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
import argparse
5+
import os
6+
import sys
7+
8+
import pyquality
9+
10+
11+
path_join = os.path.join
12+
13+
def main():
14+
parser = argparse.ArgumentParser(description=pyquality.__doc__)
15+
parser.add_argument('repository', help='Path or URL to the Git repository')
16+
args = parser.parse_args()
17+
18+
repository = args.repository
19+
repository_path = repository
20+
if not os.path.exists(repository):
21+
repository_path = os.path.basename(repository).replace('.git', '')
22+
pyquality.git_clone(repository, repository_path)
23+
repository_name = os.path.basename(repository_path)
24+
25+
results_path = path_join(os.path.curdir,
26+
'results-{}'.format(repository_name))
27+
# TODO: be able to change results path
28+
if not os.path.exists(results_path):
29+
os.mkdir(results_path)
30+
31+
tags_filename = path_join(results_path, repository_name + '-tags.csv')
32+
ratios_filename = path_join(results_path, repository_name + '-pep8-{}.csv')
33+
pyquality.analyse_repository(repository_path, tags_filename,
34+
ratios_filename)
35+
36+
graph_filename = path_join(results_path, repository_name + '-{}.png')
37+
pyquality.plot_graphs(repository_name, tags_filename, ratios_filename,
38+
graph_filename)
39+
40+
video_filename = path_join(results_path, repository_name)
41+
pyquality.render_project_history(repository_name, video_filename,
42+
tags_filename, results_path)
43+
44+
report_filename = path_join(results_path, repository_name + '-report.html')
45+
pyquality.render_report(repository_name, tags_filename,
46+
ratios_filename, video_filename,
47+
pyquality.default_template, report_filename)
48+
49+
50+
if __name__ == '__main__':
51+
main()

pyquality/git_utils.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# coding: utf-8
2+
3+
import subprocess
4+
5+
import requests
6+
7+
8+
def git_clone(repository_url, path_to_save):
9+
''' Clone a Git repository using `git` binary '''
10+
subprocess.call(['git', 'clone', repository_url, path_to_save])
11+
12+
13+
def git_tag_list(repo_path):
14+
return subprocess.check_output("git tag -l".split(), cwd=repo_path).splitlines()
15+
16+
17+
def git_checkout(repo_path, rev):
18+
return subprocess.call(["git", "checkout", rev], cwd=repo_path)
19+
20+
21+
def git_reset_head(repo_path):
22+
return subprocess.call("git reset --hard".split(), cwd=repo_path)
23+
24+
25+
def git_current_branch(repo_path):
26+
return subprocess.check_output("git rev-parse --abbrev-ref "
27+
"HEAD".split(), cwd=repo_path).strip()
28+
29+
30+
def git_count_authors(repo_path):
31+
return len(subprocess.check_output("git shortlog -s -n".split(),
32+
cwd=repo_path).splitlines())
33+
34+
35+
def git_count_commits(repo_path):
36+
return int(subprocess.check_output("git rev-list HEAD --count".split(),
37+
cwd=repo_path).strip())
38+
39+
40+
def git_last_commit_date(repo_path):
41+
return subprocess.check_output('git log -1 --format="%ad"'.split(),
42+
cwd=repo_path).strip()[1:-1]
43+
44+
45+
def github_list_repositories(page, query='language:python', sort='stars'):
46+
# We're using the legacy search api
47+
# (http://developer.github.com/v3/search/legacy/), maybe we should use the
48+
# preview of the new api
49+
# (http://developer.github.com/changes/2013-07-19-preview-the-new-search-api/
50+
# https://gist.github.com/jasonrudolph/6065289)
51+
search_url = "https://api.github.com/legacy/repos/search/{}"
52+
params['start_page'] = page
53+
response = requests.get(search_url.format(query), params=params)
54+
55+
projects = []
56+
for repo in response.json()['repositories']:
57+
project_name = repo["name"]
58+
project_url = repo["url"]
59+
projects.append({'name': project_name, 'url': project_url})
60+
61+
return projects

0 commit comments

Comments
 (0)