diff --git a/example.png b/example.png index b038f37..af55fb0 100644 Binary files a/example.png and b/example.png differ diff --git a/git_lines_graph/__init__.py b/git_lines_graph/__init__.py deleted file mode 100644 index 15b6a64..0000000 --- a/git_lines_graph/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .main import * diff --git a/git_lines_graph/main.py b/git_lines_graph/main.py deleted file mode 100755 index b62294b..0000000 --- a/git_lines_graph/main.py +++ /dev/null @@ -1,41 +0,0 @@ -import git -import os -import sys -import click -import pandas as pd -import matplotlib as mpl -import matplotlib.pyplot as plt - - -@click.command() -@click.argument("git_dir", required=True) -@click.option("-b", "--branch", - default=None, - help="branch to browse.") -def main(git_dir, branch): - try: - repo = git.repo.Repo(git_dir) - except: - print("Exception of type: {}\nDir. not a valid git project: {}". - format(sys.exc_info()[0], git_dir)) - exit() - - data = [] - for i in reversed(list(repo.iter_commits(rev=branch))): - diff = i.stats.total - data.append([i.committed_datetime.isoformat(), - diff['insertions'], - diff['deletions']]) - - data = pd.DataFrame(data, columns=["date", "add", "remove"]) - data['delta'] = data['add'] - data['remove'] - data['total'] = data.delta.cumsum() - data.date = pd.to_datetime(data.date) - data.set_index(['date'], inplace=True) - - plt.figure("Code Lines Progress in project {}". - format(os.path.basename(git_dir))) - plt.ylabel("# of lines") - ax = data['total'].plot() - ax.yaxis.set_major_formatter(mpl.ticker.StrMethodFormatter('{x:,.0f}')) - plt.show() diff --git a/pyproject.toml b/pyproject.toml index 07de284..78df852 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,21 @@ +[project] +name = "git-lines-graph" +version = "2.0.0" +description = "Git commit lines graph" +readme = "README.md" +requires-python = ">=3.9" +dependencies = [ + "gitpython>=3.1.43", + "matplotlib>=3.9.2", + "pandas>=2.2.2", +] + +[project.scripts] +git-lines-graph = "git_lines_graph:main" + [build-system] -requires = ["setuptools", "wheel"] -build-backend = "setuptools.build_meta" \ No newline at end of file +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project.urls] +Repository = "https://github.com/danielfleischer/git-commits-lines-graph" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 7d84eb0..0000000 --- a/setup.cfg +++ /dev/null @@ -1,31 +0,0 @@ -[metadata] -name = git-lines-graph -version = 1.0.5 -author = Daniel Fleischer -author_email = danflscr@gmail.com -description = Git commit lines graph -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/danielfleischer/git-commits-lines-graph -classifiers = - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Operating System :: OS Independent - -[options.entry_points] -console_scripts = - git-lines-graph = git_lines_graph.main:main - -[options] -packages = find: -install_requires = - GitPython - click - pandas - matplotlib -python_requires = >=3.6 - -[options.packages.find] -where = . \ No newline at end of file diff --git a/src/git_lines_graph/__init__.py b/src/git_lines_graph/__init__.py new file mode 100755 index 0000000..eec0874 --- /dev/null +++ b/src/git_lines_graph/__init__.py @@ -0,0 +1,41 @@ +import argparse +import os + +import git +import matplotlib as mpl +import matplotlib.pyplot as plt +import pandas as pd + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("git_dir", type=str, help="Git directory") + parser.add_argument("-b", "--branch", type=str, default=None, help="Branch to browse") + + args = parser.parse_args() + git_dir = args.git_dir + branch = args.branch + + try: + repo = git.repo.Repo(git_dir) + except git.exc.InvalidGitRepositoryError as e: + print("Not a valid git project: {}".format(git_dir)) + exit() + + data = [] + for i in reversed(list(repo.iter_commits(rev=branch))): + diff = i.stats.total + data.append([i.committed_datetime.isoformat(), diff["insertions"], diff["deletions"]]) + + data = pd.DataFrame(data, columns=["date", "add", "remove"]) + data["delta"] = data["add"] - data["remove"] + data["total"] = data.delta.cumsum() + data.date = pd.to_datetime(data.date) + data.set_index(["date"], inplace=True) + + with plt.xkcd(): + plt.figure("Code Lines Progress in project {}".format(os.path.basename(git_dir))) + plt.ylabel("# of lines") + ax = data["total"].plot() + ax.yaxis.set_major_formatter(mpl.ticker.StrMethodFormatter("{x:,.0f}")) + plt.show()