Skip to content

Commit 9173889

Browse files
Format codebase with black
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent b6ee9ae commit 9173889

16 files changed

+1127
-263
lines changed

git_sim/__main__.py

+199-42
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,136 @@
88
from manim import config, WHITE
99
from manim.utils.file_ops import open_file as open_media_file
1010

11+
1112
def main():
12-
parser = argparse.ArgumentParser("git-sim", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
13-
parser.add_argument("--title", help="Custom title to display at the beginning of the animation", type=str, default="Git Sim, by initialcommit.com")
14-
parser.add_argument("--logo", help="The path to a custom logo to use in the animation intro/outro", type=str, default=os.path.join(str(pathlib.Path(__file__).parent.resolve()), "logo.png"))
15-
parser.add_argument("--outro-top-text", help="Custom text to display above the logo during the outro", type=str, default="Thanks for using Initial Commit!")
16-
parser.add_argument("--outro-bottom-text", help="Custom text to display below the logo during the outro", type=str, default="Learn more at initialcommit.com")
17-
parser.add_argument("--show-intro", help="Add an intro sequence with custom logo and title", action="store_true")
18-
parser.add_argument("--show-outro", help="Add an outro sequence with custom logo and text", action="store_true")
19-
parser.add_argument("--media-dir", help="The path to output the animation data and video file", type=str, default=".")
20-
parser.add_argument("--low-quality", help="Render output video in low quality, useful for faster testing", action="store_true")
21-
parser.add_argument("--light-mode", help="Enable light-mode with white background", action="store_true")
22-
parser.add_argument("--speed", help="A multiple of the standard 1x animation speed (ex: 2 = twice as fast, 0.5 = half as fast)", type=float, default=1.5)
23-
parser.add_argument("--animate", help="Animate the simulation and output as an mp4 video", action="store_true")
24-
parser.add_argument("--max-branches-per-commit", help="Maximum number of branch labels to display for each commit", type=int, default=1)
25-
parser.add_argument("--max-tags-per-commit", help="Maximum number of tags to display for each commit", type=int, default=1)
26-
parser.add_argument("-d", "--disable-auto-open", help="Disable the automatic opening of the image/video file after generation", action="store_true")
27-
parser.add_argument("-r", "--reverse", help="Display commit history in the reverse direction", action="store_true")
13+
parser = argparse.ArgumentParser(
14+
"git-sim", formatter_class=argparse.ArgumentDefaultsHelpFormatter
15+
)
16+
parser.add_argument(
17+
"--title",
18+
help="Custom title to display at the beginning of the animation",
19+
type=str,
20+
default="Git Sim, by initialcommit.com",
21+
)
22+
parser.add_argument(
23+
"--logo",
24+
help="The path to a custom logo to use in the animation intro/outro",
25+
type=str,
26+
default=os.path.join(str(pathlib.Path(__file__).parent.resolve()), "logo.png"),
27+
)
28+
parser.add_argument(
29+
"--outro-top-text",
30+
help="Custom text to display above the logo during the outro",
31+
type=str,
32+
default="Thanks for using Initial Commit!",
33+
)
34+
parser.add_argument(
35+
"--outro-bottom-text",
36+
help="Custom text to display below the logo during the outro",
37+
type=str,
38+
default="Learn more at initialcommit.com",
39+
)
40+
parser.add_argument(
41+
"--show-intro",
42+
help="Add an intro sequence with custom logo and title",
43+
action="store_true",
44+
)
45+
parser.add_argument(
46+
"--show-outro",
47+
help="Add an outro sequence with custom logo and text",
48+
action="store_true",
49+
)
50+
parser.add_argument(
51+
"--media-dir",
52+
help="The path to output the animation data and video file",
53+
type=str,
54+
default=".",
55+
)
56+
parser.add_argument(
57+
"--low-quality",
58+
help="Render output video in low quality, useful for faster testing",
59+
action="store_true",
60+
)
61+
parser.add_argument(
62+
"--light-mode",
63+
help="Enable light-mode with white background",
64+
action="store_true",
65+
)
66+
parser.add_argument(
67+
"--speed",
68+
help="A multiple of the standard 1x animation speed (ex: 2 = twice as fast, 0.5 = half as fast)",
69+
type=float,
70+
default=1.5,
71+
)
72+
parser.add_argument(
73+
"--animate",
74+
help="Animate the simulation and output as an mp4 video",
75+
action="store_true",
76+
)
77+
parser.add_argument(
78+
"--max-branches-per-commit",
79+
help="Maximum number of branch labels to display for each commit",
80+
type=int,
81+
default=1,
82+
)
83+
parser.add_argument(
84+
"--max-tags-per-commit",
85+
help="Maximum number of tags to display for each commit",
86+
type=int,
87+
default=1,
88+
)
89+
parser.add_argument(
90+
"-d",
91+
"--disable-auto-open",
92+
help="Disable the automatic opening of the image/video file after generation",
93+
action="store_true",
94+
)
95+
parser.add_argument(
96+
"-r",
97+
"--reverse",
98+
help="Display commit history in the reverse direction",
99+
action="store_true",
100+
)
28101

29102
subparsers = parser.add_subparsers(dest="subcommand", help="subcommand help")
30103

31104
log = subparsers.add_parser("log", help="log -h")
32-
log.add_argument("--commits", help="The number of commits to display in the simulated log output", type=int, default=5, choices=range(1,13))
105+
log.add_argument(
106+
"--commits",
107+
help="The number of commits to display in the simulated log output",
108+
type=int,
109+
default=5,
110+
choices=range(1, 13),
111+
)
33112

34113
status = subparsers.add_parser("status", help="status -h")
35114

36115
add = subparsers.add_parser("add", help="add -h")
37-
add.add_argument("name", nargs="+", help="The names of one or more files to add to Git's staging area", type=str)
116+
add.add_argument(
117+
"name",
118+
nargs="+",
119+
help="The names of one or more files to add to Git's staging area",
120+
type=str,
121+
)
38122

39123
restore = subparsers.add_parser("restore", help="restore -h")
40-
restore.add_argument("name", nargs="+", help="The names of one or more files to restore", type=str)
124+
restore.add_argument(
125+
"name", nargs="+", help="The names of one or more files to restore", type=str
126+
)
41127

42128
commit = subparsers.add_parser("commit", help="commit -h")
43-
commit.add_argument("-m", "--message", help="The commit message of the new commit", type=str, default="New commit")
129+
commit.add_argument(
130+
"-m",
131+
"--message",
132+
help="The commit message of the new commit",
133+
type=str,
134+
default="New commit",
135+
)
44136

45137
stash = subparsers.add_parser("stash", help="stash -h")
46-
stash.add_argument("name", nargs="*", help="The name of the file to stash changes for", type=str)
138+
stash.add_argument(
139+
"name", nargs="*", help="The name of the file to stash changes for", type=str
140+
)
47141

48142
branch = subparsers.add_parser("branch", help="branch -h")
49143
branch.add_argument("name", help="The name of the new branch", type=str)
@@ -52,47 +146,103 @@ def main():
52146
tag.add_argument("name", help="The name of the new tag", type=str)
53147

54148
reset = subparsers.add_parser("reset", help="reset -h")
55-
reset.add_argument("commit", nargs="?", help="The ref (branch/tag), or commit ID to simulate reset to", type=str, default="HEAD")
56-
reset.add_argument("--mode", help="Either mixed (default), soft, or hard", type=str, default="default")
57-
reset.add_argument("--soft", help="Simulate a soft reset, shortcut for --mode=soft", action="store_true")
58-
reset.add_argument("--mixed", help="Simulate a mixed reset, shortcut for --mode=mixed", action="store_true")
59-
reset.add_argument("--hard", help="Simulate a soft reset, shortcut for --mode=hard", action="store_true")
149+
reset.add_argument(
150+
"commit",
151+
nargs="?",
152+
help="The ref (branch/tag), or commit ID to simulate reset to",
153+
type=str,
154+
default="HEAD",
155+
)
156+
reset.add_argument(
157+
"--mode",
158+
help="Either mixed (default), soft, or hard",
159+
type=str,
160+
default="default",
161+
)
162+
reset.add_argument(
163+
"--soft",
164+
help="Simulate a soft reset, shortcut for --mode=soft",
165+
action="store_true",
166+
)
167+
reset.add_argument(
168+
"--mixed",
169+
help="Simulate a mixed reset, shortcut for --mode=mixed",
170+
action="store_true",
171+
)
172+
reset.add_argument(
173+
"--hard",
174+
help="Simulate a soft reset, shortcut for --mode=hard",
175+
action="store_true",
176+
)
60177

61178
revert = subparsers.add_parser("revert", help="revert -h")
62-
revert.add_argument("commit", nargs="?", help="The ref (branch/tag), or commit ID to simulate revert", type=str, default="HEAD")
179+
revert.add_argument(
180+
"commit",
181+
nargs="?",
182+
help="The ref (branch/tag), or commit ID to simulate revert",
183+
type=str,
184+
default="HEAD",
185+
)
63186

64187
merge = subparsers.add_parser("merge", help="merge -h")
65-
merge.add_argument("branch", nargs=1, type=str, help="The name of the branch to merge into the active checked-out branch")
66-
merge.add_argument("--no-ff", help="Simulate creation of a merge commit in all cases, even when the merge could instead be resolved as a fast-forward", action="store_true")
188+
merge.add_argument(
189+
"branch",
190+
nargs=1,
191+
type=str,
192+
help="The name of the branch to merge into the active checked-out branch",
193+
)
194+
merge.add_argument(
195+
"--no-ff",
196+
help="Simulate creation of a merge commit in all cases, even when the merge could instead be resolved as a fast-forward",
197+
action="store_true",
198+
)
67199

68200
rebase = subparsers.add_parser("rebase", help="rebase -h")
69-
rebase.add_argument("branch", nargs=1, type=str, help="The branch to simulate rebasing the checked-out commit onto")
201+
rebase.add_argument(
202+
"branch",
203+
nargs=1,
204+
type=str,
205+
help="The branch to simulate rebasing the checked-out commit onto",
206+
)
70207

71208
cherrypick = subparsers.add_parser("cherry-pick", help="cherry-pick -h")
72-
cherrypick.add_argument("commit", nargs=1, type=str, help="The ref (branch/tag), or commit ID to simulate cherry-pick onto active branch")
209+
cherrypick.add_argument(
210+
"commit",
211+
nargs=1,
212+
type=str,
213+
help="The ref (branch/tag), or commit ID to simulate cherry-pick onto active branch",
214+
)
73215

74216
if len(sys.argv) == 1:
75217
parser.print_help()
76218
sys.exit(1)
77219

78220
args = parser.parse_args()
79221

80-
if sys.platform == 'linux' or sys.platform == 'darwin':
81-
repo_name = git.Repo(search_parent_directories=True).working_tree_dir.split('/')[-1]
82-
elif sys.platform == 'win32':
83-
repo_name = git.Repo(search_parent_directories=True).working_tree_dir.split('\\')[-1]
222+
if sys.platform == "linux" or sys.platform == "darwin":
223+
repo_name = git.Repo(search_parent_directories=True).working_tree_dir.split(
224+
"/"
225+
)[-1]
226+
elif sys.platform == "win32":
227+
repo_name = git.Repo(search_parent_directories=True).working_tree_dir.split(
228+
"\\"
229+
)[-1]
84230

85231
config.media_dir = os.path.join(os.path.expanduser(args.media_dir), "git-sim_media")
86232
config.verbosity = "ERROR"
87233

88234
# If the env variable is set and no argument provided, use the env variable value
89-
if os.getenv('git_sim_media_dir') and args.media_dir == '.':
90-
config.media_dir = os.path.join(os.path.expanduser(os.getenv('git_sim_media_dir')), "git-sim_media", repo_name)
235+
if os.getenv("git_sim_media_dir") and args.media_dir == ".":
236+
config.media_dir = os.path.join(
237+
os.path.expanduser(os.getenv("git_sim_media_dir")),
238+
"git-sim_media",
239+
repo_name,
240+
)
91241

92-
if ( args.low_quality ):
242+
if args.low_quality:
93243
config.quality = "low_quality"
94244

95-
if ( args.light_mode ):
245+
if args.light_mode:
96246
config.background_color = WHITE
97247

98248
scene = gs.GitSim(args)
@@ -102,9 +252,13 @@ def main():
102252
video = cv2.VideoCapture(str(scene.renderer.file_writer.movie_file_path))
103253
success, image = video.read()
104254
if success:
105-
t = datetime.datetime.fromtimestamp(time.time()).strftime("%m-%d-%y_%H-%M-%S")
255+
t = datetime.datetime.fromtimestamp(time.time()).strftime(
256+
"%m-%d-%y_%H-%M-%S"
257+
)
106258
image_file_name = "git-sim-" + args.subcommand + "_" + t + ".jpg"
107-
image_file_path = os.path.join(os.path.join(config.media_dir, "images"), image_file_name)
259+
image_file_path = os.path.join(
260+
os.path.join(config.media_dir, "images"), image_file_name
261+
)
108262
cv2.imwrite(image_file_path, image)
109263

110264
if not args.disable_auto_open:
@@ -114,7 +268,10 @@ def main():
114268
else:
115269
open_media_file(scene.renderer.file_writer.movie_file_path)
116270
except FileNotFoundError:
117-
print("Error automatically opening media, please manually open the image or video file to view.")
271+
print(
272+
"Error automatically opening media, please manually open the image or video file to view."
273+
)
274+
118275

119276
if __name__ == "__main__":
120277
main()

git_sim/git_sim.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,37 @@ def __init__(self, args):
2020
super().__init__()
2121
self.args = args
2222

23-
if ( self.args.light_mode ):
23+
if self.args.light_mode:
2424
self.fontColor = m.BLACK
2525
else:
2626
self.fontColor = m.WHITE
2727

2828
def construct(self):
29-
if self.args.subcommand == 'log':
29+
if self.args.subcommand == "log":
3030
self.command = GitSimLog(self)
31-
elif self.args.subcommand == 'status':
31+
elif self.args.subcommand == "status":
3232
self.command = GitSimStatus(self)
33-
elif self.args.subcommand == 'add':
33+
elif self.args.subcommand == "add":
3434
self.command = GitSimAdd(self)
35-
elif self.args.subcommand == 'restore':
35+
elif self.args.subcommand == "restore":
3636
self.command = GitSimRestore(self)
37-
elif self.args.subcommand == 'commit':
37+
elif self.args.subcommand == "commit":
3838
self.command = GitSimCommit(self)
39-
elif self.args.subcommand == 'stash':
39+
elif self.args.subcommand == "stash":
4040
self.command = GitSimStash(self)
41-
elif self.args.subcommand == 'branch':
41+
elif self.args.subcommand == "branch":
4242
self.command = GitSimBranch(self)
43-
elif self.args.subcommand == 'tag':
43+
elif self.args.subcommand == "tag":
4444
self.command = GitSimTag(self)
45-
elif self.args.subcommand == 'reset':
45+
elif self.args.subcommand == "reset":
4646
self.command = GitSimReset(self)
47-
elif self.args.subcommand == 'revert':
47+
elif self.args.subcommand == "revert":
4848
self.command = GitSimRevert(self)
49-
elif self.args.subcommand == 'merge':
49+
elif self.args.subcommand == "merge":
5050
self.command = GitSimMerge(self)
51-
elif self.args.subcommand == 'rebase':
51+
elif self.args.subcommand == "rebase":
5252
self.command = GitSimRebase(self)
53-
elif self.args.subcommand == 'cherry-pick':
53+
elif self.args.subcommand == "cherry-pick":
5454
self.command = GitSimCherryPick(self)
5555

5656
self.command.execute()

0 commit comments

Comments
 (0)