import matplotlib.pyplot as plt
import os
import json
from gitpandas import Repository, ProjectDirectory
import matplotlib

matplotlib.style.use("ggplot")

__author__ = "willmcginnis"


if __name__ == "__main__":
    g = Repository(working_dir=os.path.abspath("../../git-pandas"), verbose=True)

    b = g.cumulative_blame(branch="master", extensions=["py"], ignore_dir=["docs"], limit=None, skip=None)

    ax = b.plot(kind="area", stacked=True)
    plt.title("Cumulative Blame")
    plt.xlabel("date")
    plt.ylabel("LOC")
    box = ax.get_position()
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    ax.legend(loc="center left", bbox_to_anchor=(1, 0.5))
    plt.show()
Пример #2
0
from gitpandas import Repository
import time

from definitions import GIT_PANDAS_DIR

__author__ = 'willmcginnis'


if __name__ == '__main__':
    g = Repository(working_dir=GIT_PANDAS_DIR)

    st = time.time()
    blame = g.cumulative_blame(branch='master', include_globs=['*.py', '*.html', '*.sql', '*.md'], limit=None, skip=None)
    print(blame.head())
    print(time.time() - st)

    st = time.time()
    blame = g.parallel_cumulative_blame(branch='master', include_globs=['*.py', '*.html', '*.sql', '*.md'], limit=None, skip=None, workers=4)
    print(blame.head())
    print(time.time() - st)
Пример #3
0
class TestLocalProperties(unittest.TestCase):
    """

    """

    def setUp(self):
        """

        :return:
        """
        project_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + 'repos'
        repo_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + 'repos' + os.sep + 'repository1'

        if os.path.exists(project_dir):
            shutil.rmtree(project_dir)

        os.makedirs(project_dir)

        if not os.path.exists(repo_dir):
            os.makedirs(repo_dir)

        # create an empty repo (but not bare)
        grepo = git.Repo.init(repo_dir)

        # add a file
        with open(repo_dir + os.sep + 'README.md', 'w') as f:
            f.write('Sample README for a sample project\n')

        # commit it
        grepo.git.add('README.md')
        grepo.git.commit(m='first commit')

        # now add some other files:
        for idx in range(5):
            with open(repo_dir + os.sep + 'file_%d.py' % (idx, ), 'w') as f:
                f.write('import sys\nimport os\n')

            time.sleep(2.0)
            grepo.git.add(all=True)
            grepo.git.commit(m='adding file_%d.py' % (idx, ))

        self.repo = Repository(working_dir=repo_dir, verbose=True)

    def tearDown(self):
        self.repo.__del__()
        project_dir = str(os.path.dirname(os.path.abspath(__file__))) + os.sep + 'repos'
        shutil.rmtree(project_dir)

    def test_repo_name(self):
        self.assertEqual(self.repo.repo_name, 'repository1')

    def test_branches(self):
        branches = list(self.repo.branches()['branch'].values)
        self.assertIn('master', branches)

    def test_tags(self):
        tags = list(self.repo.tags()['tag'].values)
        self.assertEqual(len(tags), 0)

    def test_is_bare(self):
        self.assertFalse(self.repo.is_bare())

    def test_commit_history(self):
        ch = self.repo.commit_history(branch='master')
        self.assertEqual(ch.shape[0], 6)

        ch2 = self.repo.commit_history(branch='master', extensions=['py'])
        self.assertEqual(ch2.shape[0], 5)

        ch3 = self.repo.commit_history(branch='master', limit=3)
        self.assertEqual(ch3.shape[0], 3)

        ch4 = self.repo.commit_history(branch='master', days=5)
        self.assertEqual(ch4.shape[0], 6)

        fch = self.repo.file_change_history(branch='master')
        self.assertEqual(fch.shape[0], 6)

        fch2 = self.repo.file_change_history(branch='master', extensions=['py'])
        self.assertEqual(fch2.shape[0], 5)

        fch3 = self.repo.file_change_history(branch='master', limit=3)
        self.assertEqual(fch3.shape[0], 3)

        fcr = self.repo.file_change_rates(branch='master')
        self.assertEqual(fcr.shape[0], 6)
        self.assertEqual(fcr['unique_committers'].sum(), 6)
        self.assertEqual(fcr['net_change'].sum(), 11)

        # we know this repo doesnt have coverage
        self.assertFalse(self.repo.has_coverage())

        # we know this repo only has one committer
        self.assertEqual(self.repo.bus_factor(by='repository')['bus factor'].values[0], 1)

        # lets do some blaming
        blame = self.repo.blame(extensions=['py'])
        self.assertEqual(blame['loc'].sum(), 10)
        self.assertEqual(blame.shape[0], 1)

        cblame = self.repo.cumulative_blame()
        self.assertEqual(cblame.shape[0], 6)
        self.assertEqual(cblame[cblame.columns.values[0]].sum(), 36)

        revs = self.repo.revs(num_datapoints=2)
        self.assertEqual(revs.shape[0], 2)
        revs = self.repo.revs(limit=2)
        self.assertEqual(revs.shape[0], 2)
        revs = self.repo.revs()
        self.assertEqual(revs.shape[0], 6)
Пример #4
0
class TestLocalProperties(unittest.TestCase):
    """

    """
    def setUp(self):
        """

        :return:
        """
        project_dir = str(os.path.dirname(
            os.path.abspath(__file__))) + os.sep + 'repos'
        repo_dir = str(os.path.dirname(os.path.abspath(
            __file__))) + os.sep + 'repos' + os.sep + 'repository1'

        if os.path.exists(project_dir):
            shutil.rmtree(project_dir)

        os.makedirs(project_dir)

        if not os.path.exists(repo_dir):
            os.makedirs(repo_dir)

        # create an empty repo (but not bare)
        grepo = git.Repo.init(repo_dir)

        # add a file
        with open(repo_dir + os.sep + 'README.md', 'w') as f:
            f.write('Sample README for a sample project\n')

        # commit it
        grepo.git.add('README.md')
        grepo.git.commit(m='first commit')

        # now add some other files:
        for idx in range(5):
            with open(repo_dir + os.sep + 'file_%d.py' % (idx, ), 'w') as f:
                f.write('import sys\nimport os\n')

            time.sleep(2.0)
            grepo.git.add(all=True)
            grepo.git.commit(m='adding file_%d.py' % (idx, ))

        self.repo = Repository(working_dir=repo_dir, verbose=True)

    def tearDown(self):
        self.repo.__del__()
        project_dir = str(os.path.dirname(
            os.path.abspath(__file__))) + os.sep + 'repos'
        shutil.rmtree(project_dir)

    def test_repo_name(self):
        self.assertEqual(self.repo._repo_name(), 'repository1')

    def test_branches(self):
        branches = list(self.repo.branches()['branch'].values)
        self.assertIn('master', branches)

    def test_tags(self):
        tags = list(self.repo.tags()['tag'].values)
        self.assertEqual(len(tags), 0)

    def test_is_bare(self):
        self.assertFalse(self.repo.is_bare())

    def test_commit_history(self):
        ch = self.repo.commit_history(branch='master')
        self.assertEqual(ch.shape[0], 6)

        ch2 = self.repo.commit_history(branch='master', extensions=['py'])
        self.assertEqual(ch2.shape[0], 5)

        ch3 = self.repo.commit_history(branch='master', limit=3)
        self.assertEqual(ch3.shape[0], 3)

        ch4 = self.repo.commit_history(branch='master', days=5)
        self.assertEqual(ch4.shape[0], 6)

        fch = self.repo.file_change_history(branch='master')
        self.assertEqual(fch.shape[0], 6)

        fch2 = self.repo.file_change_history(branch='master',
                                             extensions=['py'])
        self.assertEqual(fch2.shape[0], 5)

        fch3 = self.repo.file_change_history(branch='master', limit=3)
        self.assertEqual(fch3.shape[0], 3)

        fcr = self.repo.file_change_rates(branch='master')
        self.assertEqual(fcr.shape[0], 6)
        self.assertEqual(fcr['unique_committers'].sum(), 6)
        self.assertEqual(fcr['net_change'].sum(), 11)

        # we know this repo doesnt have coverage
        self.assertFalse(self.repo.has_coverage())

        # we know this repo only has one committer
        self.assertEqual(
            self.repo.bus_factor(by='repository')['bus factor'].values[0], 1)

        # lets do some blaming
        blame = self.repo.blame(extensions=['py'])
        self.assertEqual(blame['loc'].sum(), 10)
        self.assertEqual(blame.shape[0], 1)

        cblame = self.repo.cumulative_blame()
        self.assertEqual(cblame.shape[0], 6)
        self.assertEqual(cblame[cblame.columns.values[0]].sum(), 36)

        revs = self.repo.revs(num_datapoints=2)
        self.assertEqual(revs.shape[0], 2)
        revs = self.repo.revs(limit=2)
        self.assertEqual(revs.shape[0], 2)
        revs = self.repo.revs()
        self.assertEqual(revs.shape[0], 6)
import matplotlib.pyplot as plt
import os
import json
from gitpandas import Repository, ProjectDirectory
import matplotlib
matplotlib.style.use('ggplot')

__author__ = 'willmcginnis'

if __name__ == '__main__':
    g = Repository(working_dir=os.path.abspath('../../git-pandas'),
                   verbose=True)

    b = g.cumulative_blame(branch='master',
                           extensions=['py'],
                           ignore_dir=['docs'],
                           limit=None,
                           skip=None)

    ax = b.plot(kind='area', stacked=True)
    plt.title('Cumulative Blame')
    plt.xlabel('date')
    plt.ylabel('LOC')
    box = ax.get_position()
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    plt.show()