Skip to content

Commit

Permalink
fixup! perf: Add test creating prfiling data
Browse files Browse the repository at this point in the history
  • Loading branch information
dummy committed Mar 23, 2024
1 parent 99496aa commit 9e63757
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ actions = \
docs-deploy \
format \
help \
profile \
release \
run \
setup \
Expand Down
43 changes: 43 additions & 0 deletions duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from contextlib import contextmanager
from importlib.metadata import version as pkgversion
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING, Iterator

from duty import duty
Expand All @@ -15,6 +16,15 @@
if TYPE_CHECKING:
from duty.context import Context

from cProfile import Profile
from pstats import SortKey, Stats
from typing import TYPE_CHECKING

from git_changelog import Changelog
from git_changelog.commit import AngularConvention

if TYPE_CHECKING:
from tests.helpers import GitRepo

PY_SRC_PATHS = (Path(_) for _ in ("src", "tests", "duties.py", "scripts"))
PY_SRC_LIST = tuple(str(_) for _ in PY_SRC_PATHS)
Expand Down Expand Up @@ -283,3 +293,36 @@ def update_config(filename: str) -> None:

for filename in ("launch.json", "settings.json", "tasks.json"):
ctx.run(update_config, args=[filename], title=f"Update .vscode/{filename}")


@duty
def profile(ctx: Context, merge: int = 15) -> None:
"""Profile the parsing and grouping of commits.
Parameters:
merge: Number of times to merge a branch in the temporary repository.
"""
try:
from tests.helpers import GitRepo
except ModuleNotFoundError:
import sys

sys.path.insert(0, str(Path(__file__).parent))
from tests.helpers import GitRepo

def merge_branches(repo: GitRepo, branch: str = "feat", times: int = 15) -> None:
for _ in range(times):
repo.branch(branch)
repo.checkout(branch)
repo.commit(f"feat: {branch}")
repo.checkout("main")
repo.merge(branch)
repo.git("branch", "-d", branch)

with TemporaryDirectory() as tmp_dir:
repo = GitRepo(Path(tmp_dir) / "repo")
ctx.run(merge_branches, args=(repo, "feat", merge), title="Creating temporary repository")

with Profile() as profile:
Changelog(repo.path, convention=AngularConvention)
Stats(profile).strip_dirs().sort_stats(SortKey.TIME).print_stats()
1 change: 1 addition & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, repo: Path) -> None:
repo: Path to the git repository.
"""
self.path = repo
self.path.mkdir(parents=True, exist_ok=True)
self.git("init", "-b", "main")
self.git("config", "user.name", "dummy")
self.git("config", "user.email", "dummy@example.com")
Expand Down
45 changes: 0 additions & 45 deletions tests/test_perf.py

This file was deleted.

0 comments on commit 9e63757

Please sign in to comment.