Skip to content

Commit

Permalink
Updates (#1)
Browse files Browse the repository at this point in the history
- pyproject.toml
- xkcd style.
- argparse.
  • Loading branch information
danielfleischer authored Sep 19, 2024
2 parents 028298e + ec1bce5 commit 49a493e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 75 deletions.
Binary file modified example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion git_lines_graph/__init__.py

This file was deleted.

41 changes: 0 additions & 41 deletions git_lines_graph/main.py

This file was deleted.

22 changes: 20 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project.urls]
Repository = "https://github.com/danielfleischer/git-commits-lines-graph"
31 changes: 0 additions & 31 deletions setup.cfg

This file was deleted.

41 changes: 41 additions & 0 deletions src/git_lines_graph/__init__.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 49a493e

Please sign in to comment.