Skip to content

Commit 311b118

Browse files
committed
Autoformatted via Black
* Autoformatted the entire project using black. * Added recommendation on using black or at least some other autoformatter before submitting PRs. * Attempted to make all of the docstrings consistent
1 parent 0d3eb8c commit 311b118

17 files changed

+919
-673
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export _GIT_LOG_OPTIONS="--ignore-all-space --ignore-blank-lines"
259259
#### Git pathspec
260260

261261
You can exclude a directory from the stats by using
262-
[pathspec](https://git-scm.com/docs/gitglossary#gitglossary-aiddefpathspecapathspec)
262+
[pathspec](https://git-scm.com/docs/gitglossary#gitglossary-aiddefpathspecapathspec).
263263

264264
```bash
265265
export _GIT_PATHSPEC=':!directory'
@@ -311,6 +311,22 @@ on getting features added. The current structure is as follows:
311311
- **`git_py_stats/`**: Core package
312312
- **`git_py_stats/tests/`**: Test cases for the various modules
313313
314+
### Code Formatting
315+
316+
This project uses [Black](https://black.readthedocs.io/en/stable/) for code formatting.
317+
To ensure consistency, please try to autoformat your code with one of the various
318+
cool autoformatters out there before submitting a PR.
319+
320+
Here is how to format all Python code with Black before submitting changes:
321+
322+
```bash
323+
pip install black
324+
cd git-py-stats
325+
black .
326+
```
327+
328+
- For more information about Black, refer to the [official documentation](https://black.readthedocs.io/en/stable/).
329+
314330
### Testing
315331
316332
This project uses Python's built-in `unittest` framework for testing.
@@ -369,6 +385,8 @@ To contribute:
369385
4. Push to the branch (`git push origin feature-branch`).
370386
5. Open a pull request.
371387

388+
Please try to adhere to [PEP 8](https://peps.python.org/pep-0008/).
389+
372390
## License
373391

374392
This project is licensed under the MIT License.

git_py_stats/arg_parser.py

+85-63
Original file line numberDiff line numberDiff line change
@@ -26,123 +26,145 @@ def parse_arguments(argv: Optional[List[str]] = None) -> Namespace:
2626
"""
2727

2828
parser = ArgumentParser(
29-
description='Git Py Stats - A Python Implementation of Git Quick Stats.'
29+
description="Git Py Stats - A Python Implementation of Git Quick Stats."
3030
)
3131

3232
# Generate Options
3333
parser.add_argument(
34-
'-T', '--detailed-git-stats',
35-
action='store_true',
36-
help='Give a detailed list of git stats'
34+
"-T",
35+
"--detailed-git-stats",
36+
action="store_true",
37+
help="Give a detailed list of git stats",
3738
)
3839
parser.add_argument(
39-
'-R', '--git-stats-by-branch',
40-
metavar='BRANCH',
41-
help='See detailed list of git stats by branch'
40+
"-R",
41+
"--git-stats-by-branch",
42+
metavar="BRANCH",
43+
help="See detailed list of git stats by branch",
4244
)
4345
parser.add_argument(
44-
'-c', '--changelogs',
45-
action='store_true',
46-
help='See changelogs'
46+
"-c",
47+
"--changelogs",
48+
action="store_true",
49+
help="See changelogs",
4750
)
4851
parser.add_argument(
49-
'-L', '--changelogs-by-author',
52+
"-L",
53+
"--changelogs-by-author",
5054
metavar='"AUTHOR NAME"',
51-
help='See changelogs by author'
55+
help="See changelogs by author",
5256
)
5357
parser.add_argument(
54-
'-S', '--my-daily-stats',
55-
action='store_true',
56-
help='See your current daily stats'
58+
"-S",
59+
"--my-daily-stats",
60+
action="store_true",
61+
help="See your current daily stats",
5762
)
5863
parser.add_argument(
59-
'-V', '--csv-output-by-branch',
60-
action='store_true',
61-
help='Output daily stats by branch in CSV format'
64+
"-V",
65+
"--csv-output-by-branch",
66+
action="store_true",
67+
help="Output daily stats by branch in CSV format",
6268
)
6369
parser.add_argument(
64-
'-j', '--json-output',
65-
action='store_true',
66-
help='Save git log as a JSON formatted file to a specified area'
70+
"-j",
71+
"--json-output",
72+
action="store_true",
73+
help="Save git log as a JSON formatted file to a specified area",
6774
)
6875

6976
# List Options
7077
parser.add_argument(
71-
'-b', '--branch-tree',
72-
action='store_true',
73-
help='Show an ASCII graph of the git repo branch history'
78+
"-b",
79+
"--branch-tree",
80+
action="store_true",
81+
help="Show an ASCII graph of the git repo branch history",
7482
)
7583
parser.add_argument(
76-
'-D', '--branches-by-date',
77-
action='store_true',
78-
help='Show branches by date'
84+
"-D",
85+
"--branches-by-date",
86+
action="store_true",
87+
help="Show branches by date",
7988
)
8089
parser.add_argument(
81-
'-C', '--contributors',
82-
action='store_true',
83-
help='See a list of everyone who contributed to the repo'
90+
"-C",
91+
"--contributors",
92+
action="store_true",
93+
help="See a list of everyone who contributed to the repo",
8494
)
8595
parser.add_argument(
86-
'-n', '--new-contributors',
87-
metavar='DATE',
88-
help='List everyone who made their first contribution since a specified date'
96+
"-n",
97+
"--new-contributors",
98+
metavar="DATE",
99+
help="List everyone who made their first contribution since a specified date",
89100
)
90101
parser.add_argument(
91-
'-a', '--commits-per-author',
92-
action='store_true',
93-
help='Displays a list of commits per author'
102+
"-a",
103+
"--commits-per-author",
104+
action="store_true",
105+
help="Displays a list of commits per author",
94106
)
95107
parser.add_argument(
96-
'-d', '--commits-per-day',
97-
action='store_true',
98-
help='Displays a list of commits per day'
108+
"-d",
109+
"--commits-per-day",
110+
action="store_true",
111+
help="Displays a list of commits per day",
99112
)
100113
parser.add_argument(
101-
'-Y', '--commits-by-year',
102-
action='store_true',
103-
help='Displays a list of commits per year'
114+
"-Y",
115+
"--commits-by-year",
116+
action="store_true",
117+
help="Displays a list of commits per year",
104118
)
105119
parser.add_argument(
106-
'-m', '--commits-by-month',
107-
action='store_true',
108-
help='Displays a list of commits per month'
120+
"-m",
121+
"--commits-by-month",
122+
action="store_true",
123+
help="Displays a list of commits per month",
109124
)
110125
parser.add_argument(
111-
'-w', '--commits-by-weekday',
112-
action='store_true',
113-
help='Displays a list of commits per weekday'
126+
"-w",
127+
"--commits-by-weekday",
128+
action="store_true",
129+
help="Displays a list of commits per weekday",
114130
)
115131
parser.add_argument(
116-
'-W', '--commits-by-author-by-weekday',
132+
"-W",
133+
"--commits-by-author-by-weekday",
117134
metavar='"AUTHOR NAME"',
118-
help='Displays a list of commits per weekday by author'
135+
help="Displays a list of commits per weekday by author",
119136
)
120137
parser.add_argument(
121-
'-o', '--commits-by-hour',
122-
action='store_true',
123-
help='Displays a list of commits per hour'
138+
"-o",
139+
"--commits-by-hour",
140+
action="store_true",
141+
help="Displays a list of commits per hour",
124142
)
125143
parser.add_argument(
126-
'-A', '--commits-by-author-by-hour',
144+
"-A",
145+
"--commits-by-author-by-hour",
127146
metavar='"AUTHOR NAME"',
128-
help='Displays a list of commits per hour by author'
147+
help="Displays a list of commits per hour by author",
129148
)
130149
parser.add_argument(
131-
'-z', '--commits-by-timezone',
132-
action='store_true',
133-
help='Displays a list of commits per timezone'
150+
"-z",
151+
"--commits-by-timezone",
152+
action="store_true",
153+
help="Displays a list of commits per timezone",
134154
)
135155
parser.add_argument(
136-
'-Z', '--commits-by-author-by-timezone',
156+
"-Z",
157+
"--commits-by-author-by-timezone",
137158
metavar='"AUTHOR NAME"',
138-
help='Displays a list of commits per timezone by author'
159+
help="Displays a list of commits per timezone by author",
139160
)
140161

141162
# Suggest Options
142163
parser.add_argument(
143-
'-r', '--suggest-reviewers',
144-
action='store_true',
145-
help='Show the best people to contact to review code'
164+
"-r",
165+
"--suggest-reviewers",
166+
action="store_true",
167+
help="Show the best people to contact to review code",
146168
)
147169

148170
# Help option inherited from argparse by default, no need to impl them.

git_py_stats/config.py

+40-34
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Dict, Union, Optional
88
from git_py_stats.git_operations import run_git_command
99

10+
1011
# TODO: This is a rough equivalent of what the original program does.
1112
# However, that doesn't mean this is the correct way to handle
1213
# this type of operation since these are not much different
@@ -22,12 +23,12 @@ def get_config() -> Dict[str, Union[str, int]]:
2223
These are the original program's environment variables:
2324
2425
Environment Variables:
25-
_GIT_SINCE (str): Equivalent to git's --since flag.
26+
_GIT_SINCE (str): Equivalent to git's --since flag.
2627
If not set, defaults to the first commit date in the repository.
27-
_GIT_UNTIL (str): Equivalent to git's --until flag.
28+
_GIT_UNTIL (str): Equivalent to git's --until flag.
2829
If not set, defaults to the current system date/time upon exec
2930
of the program.
30-
_GIT_PATHSPEC (str): Specifies files or directories to include/exclude in stats.
31+
_GIT_PATHSPEC (str): Specifies files or directories to include/exclude in stats.
3132
Defaults to "--" which means to skip over this option.
3233
_GIT_MERGE_VIEW (str): Merge commit view strategy. Options:
3334
- 'exclusive' to show only merge commits.
@@ -40,6 +41,9 @@ def get_config() -> Dict[str, Union[str, int]]:
4041
- 'legacy' to set the legacy theme
4142
- Empty to set the default theme
4243
44+
Args:
45+
None
46+
4347
Returns:
4448
Dict[str, Union[str, int]]: A dictionary containing the configuration options:
4549
- 'since' (str): Git command option for the start date.
@@ -53,68 +57,70 @@ def get_config() -> Dict[str, Union[str, int]]:
5357
config: Dict[str, Union[str, int]] = {}
5458

5559
# _GIT_SINCE
56-
git_since: Optional[str] = os.environ.get('_GIT_SINCE')
60+
git_since: Optional[str] = os.environ.get("_GIT_SINCE")
5761
if git_since:
58-
config['since'] = f"--since={git_since}"
62+
config["since"] = f"--since={git_since}"
5963
else:
6064
# Get the earliest commit date in the repo
61-
earliest_commit_date: Optional[str] = run_git_command(['git', 'log', '--reverse', '--format=%ad'])
65+
earliest_commit_date: Optional[str] = run_git_command(
66+
["git", "log", "--reverse", "--format=%ad"]
67+
)
6268
if earliest_commit_date:
63-
first_commit_date: str = earliest_commit_date.split('\n')[0]
64-
config['since'] = f"--since='{first_commit_date}'"
69+
first_commit_date: str = earliest_commit_date.split("\n")[0]
70+
config["since"] = f"--since='{first_commit_date}'"
6571
else:
66-
config['since'] = ''
72+
config["since"] = ""
6773

6874
# _GIT_UNTIL
69-
git_until: Optional[str] = os.environ.get('_GIT_UNTIL')
75+
git_until: Optional[str] = os.environ.get("_GIT_UNTIL")
7076
if git_until:
71-
config['until'] = f"--until={git_until}"
77+
config["until"] = f"--until={git_until}"
7278
else:
7379
# Get the current date/time upon exec of the program
74-
now: str = datetime.now().strftime('%a, %d %b %Y %H:%M:%S %Z')
75-
config['until'] = f"--until='{now}'"
80+
now: str = datetime.now().strftime("%a, %d %b %Y %H:%M:%S %Z")
81+
config["until"] = f"--until='{now}'"
7682

7783
# _GIT_PATHSPEC
78-
git_pathspec: Optional[str] = os.environ.get('_GIT_PATHSPEC')
84+
git_pathspec: Optional[str] = os.environ.get("_GIT_PATHSPEC")
7985
if git_pathspec:
80-
config['pathspec'] = f"-- {git_pathspec}"
86+
config["pathspec"] = f"-- {git_pathspec}"
8187
else:
82-
config['pathspec'] = "--"
88+
config["pathspec"] = "--"
8389

8490
# _GIT_MERGE_VIEW
85-
git_merge_view: str = os.environ.get('_GIT_MERGE_VIEW', '').lower()
86-
if git_merge_view == 'exclusive':
87-
config['merges'] = '--merges'
88-
elif git_merge_view == 'enable':
89-
config['merges'] = ''
91+
git_merge_view: str = os.environ.get("_GIT_MERGE_VIEW", "").lower()
92+
if git_merge_view == "exclusive":
93+
config["merges"] = "--merges"
94+
elif git_merge_view == "enable":
95+
config["merges"] = ""
9096
else:
91-
config['merges'] = '--no-merges'
97+
config["merges"] = "--no-merges"
9298

9399
# _GIT_LIMIT
94-
git_limit: Optional[str] = os.environ.get('_GIT_LIMIT')
100+
git_limit: Optional[str] = os.environ.get("_GIT_LIMIT")
95101
if git_limit:
96102
# Slight sanitization, but we're still gonna wild west this a bit
97103
try:
98-
config['limit'] = int(git_limit)
104+
config["limit"] = int(git_limit)
99105
except ValueError:
100106
print("Invalid value for _GIT_LIMIT. Using default value 10.")
101-
config['limit'] = 10
107+
config["limit"] = 10
102108
else:
103-
config['limit'] = 10
109+
config["limit"] = 10
104110

105111
# _GIT_LOG_OPTIONS
106112
# NOTE: We'll need to sanitize our entire git command
107-
git_log_options: Optional[str] = os.environ.get('_GIT_LOG_OPTIONS')
113+
git_log_options: Optional[str] = os.environ.get("_GIT_LOG_OPTIONS")
108114
if git_log_options:
109-
config['log_options'] = git_log_options
115+
config["log_options"] = git_log_options
110116
else:
111-
config['log_options'] = ''
112-
117+
config["log_options"] = ""
118+
113119
# _MENU_THEME
114-
menu_theme: Optional[str] = os.environ.get('_MENU_THEME')
115-
if menu_theme == 'legacy':
116-
config['menu_theme'] = 'legacy'
120+
menu_theme: Optional[str] = os.environ.get("_MENU_THEME")
121+
if menu_theme == "legacy":
122+
config["menu_theme"] = "legacy"
117123
else:
118-
config['menu_theme'] = ''
124+
config["menu_theme"] = ""
119125

120126
return config

0 commit comments

Comments
 (0)