Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LoC(lines of code) tracker #62

Merged
merged 37 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f551f61
Removing .zip files
Jun 18, 2024
6638e1d
Merge branch 'software-gardening:main' into main
willdavidson05 Jun 21, 2024
8acb0ed
Changing add_entropy function name
Jun 21, 2024
5ea57fc
Removing print statments after cofnirming functionality
Jun 24, 2024
6f011e0
Adding comments
Jun 24, 2024
747c6a8
Allowing pre-commit to pass
Jun 24, 2024
3943413
Ensuring proper test, and adding docstring
Jun 24, 2024
d832b11
pre-commit
Jun 24, 2024
3988069
pre-commit
Jun 24, 2024
33fae5b
Creating proper test cases
Jun 24, 2024
d09425c
Simplifying total_lines_changed
Jun 24, 2024
42ea9cb
Adding return types and changing LoC tracker function
Jun 25, 2024
6ec8025
Changing file names
Jun 25, 2024
c680e6a
Changing file names
Jun 25, 2024
c958ff6
Changing file names
Jun 25, 2024
1fed3ba
Changing file name
Jun 25, 2024
34b19de
Changing file name
Jun 25, 2024
130db5e
Adding
Jun 26, 2024
2994813
Making LoC file based rather than commit file base
Jun 26, 2024
f963d9f
Pre-commit checks
Jun 26, 2024
61c66bc
Deleting comments
Jun 27, 2024
f693c18
pre-commit
Jun 27, 2024
588a344
Remvoing get_all_commit_logs
Jun 27, 2024
4588621
adding docustring
Jun 27, 2024
51cc282
pre-commit changes
Jun 27, 2024
8297b08
Changing + to -
Jun 27, 2024
23bbdbf
Stylistic changes
Jun 27, 2024
f68874f
Grammatical errors
Jun 27, 2024
7777117
pre-commit
Jun 27, 2024
98534ef
Commiting changes
Jun 28, 2024
a076bdf
Documentation changes, utilizing list comprehension
Jun 28, 2024
7446ba1
editing test case for dict return value
Jun 28, 2024
708e445
Doc changes
Jun 28, 2024
8aae488
Doc changes
Jun 28, 2024
7ef9110
Typo in doc
Jun 28, 2024
ca15bc9
Typo in doc
Jun 28, 2024
baf94d9
Edit doc string
Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/almanack/LoC_tracker.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider generalizing the name for this module to help invite further work where / when needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do! I have been thinking about a new name, and the best I have is code_tracker.py. Let me know what you think of this! I'm not sure how I feel about it yet.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
This module calculates the absolute value of lines of code (LoC) changed (added or removed)
in the given Git repository.
"""

import git


def calculate_loc_changes(repo_path: str):
willdavidson05 marked this conversation as resolved.
Show resolved Hide resolved
willdavidson05 marked this conversation as resolved.
Show resolved Hide resolved
"""
Finds the total number of code lines changed

Args:
repo_path(str): The path to the git repository
Returns:
int: Total number of lines added or removed
"""
repo = git.Repo(repo_path)

total_lines_changed = 0
willdavidson05 marked this conversation as resolved.
Show resolved Hide resolved

for commit in repo.iter_commits():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to tie in almanack.git_parser.get_commit_logs here somehow to help introduce flexibility when it comes to certain commit segments or time periods (instead of only in full summary)? Perhaps it could come in the form of an expansion of the data structure found within that function (another dictionary key-value pair, for example). For example, we might expect that earlier in a project's lifespan the amount of change will be higher than later on. These counts from the earlier time periods might inadvertently effect calculations for later time periods under certain circumstances.

Copy link
Member Author

@willdavidson05 willdavidson05 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the idea Dave! I was able to implement get_commit_logs by adding in attributes to my function, but wanted to see what you think?

# Retrieve commit statistics
diff_stat = commit.stats.total
total_lines_changed += diff_stat["lines"]
return total_lines_changed
6 changes: 3 additions & 3 deletions tests/data/almanack/entropy/add_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import git

from .add_entropy import add_entropy
from .add_entropy import insert_entropy


def commit_changes(directory: str, message: str):
Expand Down Expand Up @@ -44,8 +44,8 @@ def create_repositories(base_path: str):
# Commit baseline content
commit_changes(repo_path, "Initial commit with baseline content")

# Run the add_entropy.py scriptwhat
add_entropy(base_path)
# Run the add_entropy.py script
willdavidson05 marked this conversation as resolved.
Show resolved Hide resolved
insert_entropy(base_path)

# Commit changes after adding entropy
for dir_name in ["high_entropy", "low_entropy"]:
Expand Down
2 changes: 1 addition & 1 deletion tests/data/almanack/entropy/add_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def add_entropy_to_file(file_path: str, lines_of_code: str):
"""


def add_entropy(base_path):
def insert_entropy(base_path):
willdavidson05 marked this conversation as resolved.
Show resolved Hide resolved
entropy_levels = {
base_path / "high_entropy/high_entropy.md": high_entropy_code,
base_path / "low_entropy/low_entropy.md": low_entropy_code,
Expand Down
14 changes: 14 additions & 0 deletions tests/test_Loc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Testing LoC_tracker functionality for calculating total lines changed in a given repository.
"""

import pathlib

from almanack.LoC_tracker import calculate_loc_changes


def test_calculate_loc_changes(repository_paths: dict[str, pathlib.Path]):
# repository_paths.items() returns a dictionary
for _, repo_path in repository_paths.items():
# Check that the changes are non-negative for each repository
assert calculate_loc_changes(repo_path) > 0