def cumulative_blame(by, file_stub): settings = get_settings() project_dir = settings.get('project_dir', os.getcwd()) extensions = settings.get('extensions', None) ignore_dir = settings.get('ignore_dir', None) repo = ProjectDirectory(working_dir=project_dir) print(extensions) print(ignore_dir) print(by) cb = repo.cumulative_blame(branch='master', extensions=extensions, ignore_dir=ignore_dir, by=by, num_datapoints=100, skip=None, limit=None) cb = cb[~cb.index.duplicated()] t = json.loads(cb.to_json(orient='columns')) d3_data = [] for committer in t.keys(): blob = dict() blob['key'] = committer blob['values'] = [] for data_point in t[committer].keys(): blob['values'].append([int(float(data_point)), t[committer][data_point]]) blob['values'] = sorted(blob['values'], key=lambda x: x[0]) d3_data.append(blob) # dump the data to disk filename = get_file_prefix() + file_stub json.dump(d3_data, open(str(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + os.sep + 'static' + os.sep + 'data' + os.sep + filename, 'w'), indent=4) return True
def cumulative_blame(by, file_stub): settings = get_settings() project_dir = settings.get('project_dir', os.getcwd()) extensions = settings.get('extensions', None) ignore_dir = settings.get('ignore_dir', None) repo = ProjectDirectory(working_dir=project_dir) print(extensions) print(ignore_dir) print(by) cb = repo.cumulative_blame(branch='master', extensions=extensions, ignore_dir=ignore_dir, by=by, num_datapoints=100, skip=None, limit=None) cb = cb[~cb.index.duplicated()] t = json.loads(cb.to_json(orient='columns')) d3_data = [] for committer in t.keys(): blob = dict() blob['key'] = committer blob['values'] = [] for data_point in t[committer].keys(): blob['values'].append( [int(float(data_point)), t[committer][data_point]]) blob['values'] = sorted(blob['values'], key=lambda x: x[0]) d3_data.append(blob) # dump the data to disk filename = get_file_prefix() + file_stub json.dump( d3_data, open( str(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + os.sep + 'static' + os.sep + 'data' + os.sep + filename, 'w'), indent=4) return True
class TestLocalProperties(unittest.TestCase): """ """ def setUp(self): """ :return: """ project_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + "repos" repo1_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + "repos" + os.sep + "repository1" repo2_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + "repos" + os.sep + "repository2" if os.path.exists(project_dir): shutil.rmtree(project_dir) os.makedirs(project_dir) if not os.path.exists(repo1_dir): os.makedirs(repo1_dir) if not os.path.exists(repo2_dir): os.makedirs(repo2_dir) # create an empty repo (but not bare) grepo1 = git.Repo.init(repo1_dir) grepo2 = git.Repo.init(repo2_dir) # add a file with open(repo1_dir + os.sep + "README.md", "w") as f: f.write("Sample README for a sample python project\n") # add a file with open(repo2_dir + os.sep + "README.md", "w") as f: f.write("Sample README for a sample js project\n") # commit them grepo1.git.add("README.md") grepo1.git.commit(m="first commit") grepo2.git.add("README.md") grepo2.git.commit(m="first commit") # now add some other files: for idx in range(5): with open(repo1_dir + os.sep + "file_%d.py" % (idx,), "w") as f: f.write("import sys\nimport os\n") time.sleep(2.0) grepo1.git.add(all=True) grepo1.git.commit(m=' "adding file_%d.py"' % (idx,)) # now add some other files: for idx in range(5): with open(repo2_dir + os.sep + "file_%d.js" % (idx,), "w") as f: f.write('document.write("hello world!");\n') time.sleep(2.0) grepo2.git.add(all=True) grepo2.git.commit(m=' "adding file_%d.js"' % (idx,)) self.projectd_1 = ProjectDirectory(working_dir=[repo1_dir, repo2_dir], verbose=True) self.projectd_2 = ProjectDirectory(working_dir=project_dir, verbose=True) def tearDown(self): self.projectd_1.__del__() self.projectd_2.__del__() project_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + "repos" shutil.rmtree(project_dir) def test_repo_name(self): self.assertIn("repository1", list(self.projectd_1.repo_name()["repository"].values)) self.assertIn("repository2", list(self.projectd_1.repo_name()["repository"].values)) self.assertIn("repository1", list(self.projectd_2.repo_name()["repository"].values)) self.assertIn("repository2", list(self.projectd_2.repo_name()["repository"].values)) def test_branches(self): branches = list(self.projectd_1.branches()["branch"].values) self.assertIn("master", branches) branches = list(self.projectd_2.branches()["branch"].values) self.assertIn("master", branches) def test_tags(self): tags = list(self.projectd_1.tags()["tag"].values) self.assertEqual(len(tags), 0) tags = list(self.projectd_2.tags()["tag"].values) self.assertEqual(len(tags), 0) def test_is_bare(self): bares = self.projectd_1.is_bare()["is_bare"].values for bare in bares: self.assertFalse(bare) bares = self.projectd_2.is_bare()["is_bare"].values for bare in bares: self.assertFalse(bare) def test_commit_history(self): ch = self.projectd_1.commit_history(branch="master") self.assertEqual(ch.shape[0], 12) # Will be deprecated in v2.0.0 ch2 = self.projectd_1.commit_history(branch="master", ignore_globs=["*.[!p][!y]"]) self.assertEqual(ch2.shape[0], 5) ch3 = self.projectd_1.commit_history(branch="master", limit=4) self.assertEqual(ch3.shape[0], 4) ch4 = self.projectd_1.commit_history(branch="master", days=5) self.assertEqual(ch4.shape[0], 12) fch = self.projectd_1.file_change_history(branch="master") self.assertEqual(fch.shape[0], 12) # Will be deprecated in v2.0.0 fch2 = self.projectd_1.file_change_history(branch="master", ignore_globs=["*.[!p][!y]"]) self.assertEqual(fch2.shape[0], 5) # Will be deprecated in v2.0.0 fch4 = self.projectd_1.file_change_history(branch="master", ignore_globs=["*.[!j][!s]"]) self.assertEqual(fch4.shape[0], 5) fch3 = self.projectd_1.file_change_history(branch="master", limit=4) self.assertEqual(fch3.shape[0], 4) fcr = self.projectd_1.file_change_rates(branch="master") self.assertEqual(fcr.shape[0], 12) self.assertEqual(fcr["unique_committers"].sum(), 12) self.assertEqual(fcr["net_change"].sum(), 17) # we know this repo doesnt have coverage coverages = self.projectd_1.has_coverage()["has_coverage"].values for coverage in coverages: self.assertFalse(coverage) # we know this repo only has one committer bf = self.projectd_1.bus_factor(by="projectd") self.assertEqual(bf["bus factor"].values[0], 1) # lets do some blaming blame = self.projectd_1.blame(ignore_globs=["*.[!p][!y]"]) self.assertEqual(blame["loc"].sum(), 10) self.assertEqual(blame.shape[0], 1) cblame = self.projectd_1.cumulative_blame(by="committer") self.assertEqual(cblame.shape[0], 11) self.assertEqual(cblame[cblame.columns.values[0]].sum(), 117) revs = self.projectd_1.revs(num_datapoints=2) self.assertEqual(revs.shape[0], 2) revs = self.projectd_1.revs(limit=2) self.assertEqual(revs.shape[0], 2) revs = self.projectd_1.revs() self.assertEqual(revs.shape[0], 12)
class TestLocalProperties(unittest.TestCase): """ """ def setUp(self): """ :return: """ project_dir = str(os.path.dirname( os.path.abspath(__file__))) + os.sep + 'repos' repo1_dir = str(os.path.dirname(os.path.abspath( __file__))) + os.sep + 'repos' + os.sep + 'repository1' repo2_dir = str(os.path.dirname(os.path.abspath( __file__))) + os.sep + 'repos' + os.sep + 'repository2' if os.path.exists(project_dir): shutil.rmtree(project_dir) os.makedirs(project_dir) if not os.path.exists(repo1_dir): os.makedirs(repo1_dir) if not os.path.exists(repo2_dir): os.makedirs(repo2_dir) # create an empty repo (but not bare) grepo1 = git.Repo.init(repo1_dir) grepo2 = git.Repo.init(repo2_dir) # add a file with open(repo1_dir + os.sep + 'README.md', 'w') as f: f.write('Sample README for a sample python project\n') # add a file with open(repo2_dir + os.sep + 'README.md', 'w') as f: f.write('Sample README for a sample js project\n') # commit them grepo1.git.add('README.md') grepo1.git.commit(m='first commit') grepo2.git.add('README.md') grepo2.git.commit(m='first commit') # now add some other files: for idx in range(5): with open(repo1_dir + os.sep + 'file_%d.py' % (idx, ), 'w') as f: f.write('import sys\nimport os\n') time.sleep(2.0) grepo1.git.add(all=True) grepo1.git.commit(m=' "adding file_%d.py"' % (idx, )) # now add some other files: for idx in range(5): with open(repo2_dir + os.sep + 'file_%d.js' % (idx, ), 'w') as f: f.write('document.write("hello world!");\n') time.sleep(2.0) grepo2.git.add(all=True) grepo2.git.commit(m=' "adding file_%d.js"' % (idx, )) self.projectd_1 = ProjectDirectory(working_dir=[repo1_dir, repo2_dir], verbose=True) self.projectd_2 = ProjectDirectory(working_dir=project_dir, verbose=True) def tearDown(self): self.projectd_1.__del__() self.projectd_2.__del__() project_dir = str(os.path.dirname( os.path.abspath(__file__))) + os.sep + 'repos' shutil.rmtree(project_dir) def test_repo_name(self): self.assertIn('repository1', list(self.projectd_1._repo_name()['repository'].values)) self.assertIn('repository2', list(self.projectd_1._repo_name()['repository'].values)) self.assertIn('repository1', list(self.projectd_2._repo_name()['repository'].values)) self.assertIn('repository2', list(self.projectd_2._repo_name()['repository'].values)) def test_branches(self): branches = list(self.projectd_1.branches()['branch'].values) self.assertIn('master', branches) branches = list(self.projectd_2.branches()['branch'].values) self.assertIn('master', branches) def test_tags(self): tags = list(self.projectd_1.tags()['tag'].values) self.assertEqual(len(tags), 0) tags = list(self.projectd_2.tags()['tag'].values) self.assertEqual(len(tags), 0) def test_is_bare(self): bares = self.projectd_1.is_bare()['is_bare'].values for bare in bares: self.assertFalse(bare) bares = self.projectd_2.is_bare()['is_bare'].values for bare in bares: self.assertFalse(bare) def test_commit_history(self): ch = self.projectd_1.commit_history(branch='master') self.assertEqual(ch.shape[0], 12) ch2 = self.projectd_1.commit_history(branch='master', extensions=['py']) self.assertEqual(ch2.shape[0], 5) ch3 = self.projectd_1.commit_history(branch='master', limit=4) self.assertEqual(ch3.shape[0], 4) ch4 = self.projectd_1.commit_history(branch='master', days=5) self.assertEqual(ch4.shape[0], 12) fch = self.projectd_1.file_change_history(branch='master') self.assertEqual(fch.shape[0], 12) fch2 = self.projectd_1.file_change_history(branch='master', extensions=['py']) self.assertEqual(fch2.shape[0], 5) fch4 = self.projectd_1.file_change_history(branch='master', extensions=['js']) self.assertEqual(fch4.shape[0], 5) fch3 = self.projectd_1.file_change_history(branch='master', limit=4) self.assertEqual(fch3.shape[0], 4) fcr = self.projectd_1.file_change_rates(branch='master') self.assertEqual(fcr.shape[0], 12) self.assertEqual(fcr['unique_committers'].sum(), 12) self.assertEqual(fcr['net_change'].sum(), 17) # we know this repo doesnt have coverage coverages = self.projectd_1.has_coverage()['has_coverage'].values for coverage in coverages: self.assertFalse(coverage) # we know this repo only has one committer bf = self.projectd_1.bus_factor(by='projectd') self.assertEqual(bf['bus factor'].values[0], 1) # lets do some blaming blame = self.projectd_1.blame(extensions=['py']) self.assertEqual(blame['loc'].sum(), 10) self.assertEqual(blame.shape[0], 1) cblame = self.projectd_1.cumulative_blame(by='committer') self.assertEqual(cblame.shape[0], 11) self.assertEqual(cblame[cblame.columns.values[0]].sum(), 117) revs = self.projectd_1.revs(num_datapoints=2) self.assertEqual(revs.shape[0], 2) revs = self.projectd_1.revs(limit=2) self.assertEqual(revs.shape[0], 2) revs = self.projectd_1.revs() self.assertEqual(revs.shape[0], 12)
from gitpandas.utilities.plotting import plot_cumulative_blame from gitpandas import ProjectDirectory g = ProjectDirectory(working_dir=['git://github.com/rhiever/tpot.git']) blame = g.cumulative_blame(branch='master', extensions=['py', 'html', 'sql', 'md'], by='committer', limit=None, skip=None) plot_cumulative_blame(blame)
class TestLocalProperties(unittest.TestCase): """ """ def setUp(self): """ :return: """ project_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + 'repos' repo1_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + 'repos' + os.sep + 'repository1' repo2_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + 'repos' + os.sep + 'repository2' if os.path.exists(project_dir): shutil.rmtree(project_dir) os.makedirs(project_dir) if not os.path.exists(repo1_dir): os.makedirs(repo1_dir) if not os.path.exists(repo2_dir): os.makedirs(repo2_dir) # create an empty repo (but not bare) grepo1 = git.Repo.init(repo1_dir) grepo2 = git.Repo.init(repo2_dir) # add a file with open(repo1_dir + os.sep + 'README.md', 'w') as f: f.write('Sample README for a sample python project\n') # add a file with open(repo2_dir + os.sep + 'README.md', 'w') as f: f.write('Sample README for a sample js project\n') # commit them grepo1.git.add('README.md') grepo1.git.commit(m='first commit') grepo2.git.add('README.md') grepo2.git.commit(m='first commit') # now add some other files: for idx in range(5): with open(repo1_dir + os.sep + 'file_%d.py' % (idx, ), 'w') as f: f.write('import sys\nimport os\n') time.sleep(2.0) grepo1.git.add(all=True) grepo1.git.commit(m=' "adding file_%d.py"' % (idx, )) # now add some other files: for idx in range(5): with open(repo2_dir + os.sep + 'file_%d.js' % (idx, ), 'w') as f: f.write('document.write("hello world!");\n') time.sleep(2.0) grepo2.git.add(all=True) grepo2.git.commit(m=' "adding file_%d.js"' % (idx, )) self.projectd_1 = ProjectDirectory(working_dir=[repo1_dir, repo2_dir], verbose=True) self.projectd_2 = ProjectDirectory(working_dir=project_dir, verbose=True) def tearDown(self): self.projectd_1.__del__() self.projectd_2.__del__() project_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + 'repos' shutil.rmtree(project_dir) def test_repo_name(self): self.assertIn('repository1', list(self.projectd_1._repo_name()['repository'].values)) self.assertIn('repository2', list(self.projectd_1._repo_name()['repository'].values)) self.assertIn('repository1', list(self.projectd_2._repo_name()['repository'].values)) self.assertIn('repository2', list(self.projectd_2._repo_name()['repository'].values)) def test_branches(self): branches = list(self.projectd_1.branches()['branch'].values) self.assertIn('master', branches) branches = list(self.projectd_2.branches()['branch'].values) self.assertIn('master', branches) def test_tags(self): tags = list(self.projectd_1.tags()['tag'].values) self.assertEqual(len(tags), 0) tags = list(self.projectd_2.tags()['tag'].values) self.assertEqual(len(tags), 0) def test_is_bare(self): bares = self.projectd_1.is_bare()['is_bare'].values for bare in bares: self.assertFalse(bare) bares = self.projectd_2.is_bare()['is_bare'].values for bare in bares: self.assertFalse(bare) def test_commit_history(self): ch = self.projectd_1.commit_history(branch='master') self.assertEqual(ch.shape[0], 12) ch2 = self.projectd_1.commit_history(branch='master', extensions=['py']) self.assertEqual(ch2.shape[0], 5) ch3 = self.projectd_1.commit_history(branch='master', limit=4) self.assertEqual(ch3.shape[0], 4) ch4 = self.projectd_1.commit_history(branch='master', days=5) self.assertEqual(ch4.shape[0], 12) fch = self.projectd_1.file_change_history(branch='master') self.assertEqual(fch.shape[0], 12) fch2 = self.projectd_1.file_change_history(branch='master', extensions=['py']) self.assertEqual(fch2.shape[0], 5) fch4 = self.projectd_1.file_change_history(branch='master', extensions=['js']) self.assertEqual(fch4.shape[0], 5) fch3 = self.projectd_1.file_change_history(branch='master', limit=4) self.assertEqual(fch3.shape[0], 4) fcr = self.projectd_1.file_change_rates(branch='master') self.assertEqual(fcr.shape[0], 12) self.assertEqual(fcr['unique_committers'].sum(), 12) self.assertEqual(fcr['net_change'].sum(), 17) # we know this repo doesnt have coverage coverages = self.projectd_1.has_coverage()['has_coverage'].values for coverage in coverages: self.assertFalse(coverage) # we know this repo only has one committer bf = self.projectd_1.bus_factor(by='projectd') self.assertEqual(bf['bus factor'].values[0], 1) # lets do some blaming blame = self.projectd_1.blame(extensions=['py']) self.assertEqual(blame['loc'].sum(), 10) self.assertEqual(blame.shape[0], 1) cblame = self.projectd_1.cumulative_blame(by='committer') self.assertEqual(cblame.shape[0], 11) self.assertEqual(cblame[cblame.columns.values[0]].sum(), 117) revs = self.projectd_1.revs(num_datapoints=2) self.assertEqual(revs.shape[0], 2) revs = self.projectd_1.revs(limit=2) self.assertEqual(revs.shape[0], 2) revs = self.projectd_1.revs() self.assertEqual(revs.shape[0], 12)
from gitpandas.utilities.plotting import plot_cumulative_blame from gitpandas import ProjectDirectory __author__ = 'willmcginnis' if __name__ == '__main__': g = ProjectDirectory(working_dir=['git://github.com/rhiever/tpot.git']) blame = g.cumulative_blame(branch='master', extensions=['py', 'html', 'sql', 'md'], by='committer', limit=None, skip=None) plot_cumulative_blame(blame)
from gitpandas.utilities.plotting import plot_cumulative_blame from gitpandas import GitHubProfile, ProjectDirectory __author__ = 'willmcginnis' if __name__ == '__main__': #g = GitHubProfile(username='******', ignore_forks=True, verbose=True) g = ProjectDirectory(working_dir='/Users/willmcginnis/Documents/Helton/projects/webapps/salesproph') blame = g.cumulative_blame(branch='master', extensions=['py', 'html', 'sql', 'md'], by='project', ignore_dir=['docs'], limit=None, skip=None) plot_cumulative_blame(blame)
from gitpandas.utilities.plotting import plot_cumulative_blame from gitpandas import GitHubProfile, ProjectDirectory __author__ = 'willmcginnis' if __name__ == '__main__': #g = GitHubProfile(username='******', ignore_forks=True, verbose=True) g = ProjectDirectory( working_dir= '/Users/willmcginnis/Documents/Helton/projects/webapps/salesproph') blame = g.cumulative_blame(branch='master', extensions=['py', 'html', 'sql', 'md'], by='project', ignore_dir=['docs'], limit=None, skip=None) plot_cumulative_blame(blame)