Skip to content

Commit ebc3c15

Browse files
authored
Change Inheritance structure (#42)
Refactor inheritance model to make GitSimBaseCommand a manim scene subclass
1 parent a6acf18 commit ebc3c15

16 files changed

+421
-496
lines changed

git_sim/__main__.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,65 @@
1-
import git_sim.git_sim as gs
2-
import os, sys
31
import argparse
2+
import datetime
3+
import os
44
import pathlib
5-
import time, datetime
5+
import subprocess
6+
import sys
7+
import time
8+
from argparse import Namespace
9+
from typing import Type
10+
611
import cv2
712
import git
8-
import subprocess
9-
from manim import config, WHITE
13+
from manim import WHITE, config
1014
from manim.utils.file_ops import open_file as open_media_file
1115

16+
from git_sim.git_sim_add import GitSimAdd
17+
from git_sim.git_sim_base_command import GitSimBaseCommand
18+
from git_sim.git_sim_branch import GitSimBranch
19+
from git_sim.git_sim_cherrypick import GitSimCherryPick
20+
from git_sim.git_sim_commit import GitSimCommit
21+
from git_sim.git_sim_log import GitSimLog
22+
from git_sim.git_sim_merge import GitSimMerge
23+
from git_sim.git_sim_rebase import GitSimRebase
24+
from git_sim.git_sim_reset import GitSimReset
25+
from git_sim.git_sim_restore import GitSimRestore
26+
from git_sim.git_sim_revert import GitSimRevert
27+
from git_sim.git_sim_stash import GitSimStash
28+
from git_sim.git_sim_status import GitSimStatus
29+
from git_sim.git_sim_tag import GitSimTag
30+
31+
32+
def get_scene_for_command(args: Namespace) -> Type[GitSimBaseCommand]:
33+
34+
if args.subcommand == "log":
35+
return GitSimLog
36+
elif args.subcommand == "status":
37+
return GitSimStatus
38+
elif args.subcommand == "add":
39+
return GitSimAdd
40+
elif args.subcommand == "restore":
41+
return GitSimRestore
42+
elif args.subcommand == "commit":
43+
return GitSimCommit
44+
elif args.subcommand == "stash":
45+
return GitSimStash
46+
elif args.subcommand == "branch":
47+
return GitSimBranch
48+
elif args.subcommand == "tag":
49+
return GitSimTag
50+
elif args.subcommand == "reset":
51+
return GitSimReset
52+
elif args.subcommand == "revert":
53+
return GitSimRevert
54+
elif args.subcommand == "merge":
55+
return GitSimMerge
56+
elif args.subcommand == "rebase":
57+
return GitSimRebase
58+
elif args.subcommand == "cherry-pick":
59+
return GitSimCherryPick
60+
61+
raise NotImplementedError(f"command '{args.subcommand}' is not yet implemented.")
62+
1263

1364
def main():
1465
parser = argparse.ArgumentParser(
@@ -257,7 +308,8 @@ def main():
257308
if args.light_mode:
258309
config.background_color = WHITE
259310

260-
scene = gs.GitSim(args)
311+
scene_class = get_scene_for_command(args=args)
312+
scene = scene_class(args=args)
261313
scene.render()
262314

263315
if args.video_format == "webm":

git_sim/git_sim.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

git_sim/git_sim_add.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from argparse import Namespace
23

34
import git
45
import manim as m
@@ -7,8 +8,8 @@
78

89

910
class GitSimAdd(GitSimBaseCommand):
10-
def __init__(self, scene):
11-
super().__init__(scene)
11+
def __init__(self, args: Namespace):
12+
super().__init__(args=args)
1213
self.maxrefs = 2
1314
self.hide_first_tag = True
1415
self.allow_no_commits = True
@@ -18,19 +19,16 @@ def __init__(self, scene):
1819
except TypeError:
1920
pass
2021

21-
for name in self.scene.args.name:
22+
for name in self.args.name:
2223
if name not in [x.a_path for x in self.repo.index.diff(None)] + [
2324
z for z in self.repo.untracked_files
2425
]:
2526
print("git-sim error: No modified file with name: '" + name + "'")
2627
sys.exit()
2728

28-
def execute(self):
29+
def construct(self):
2930
print(
30-
"Simulating: git "
31-
+ self.scene.args.subcommand
32-
+ " "
33-
+ " ".join(self.scene.args.name)
31+
"Simulating: git " + self.args.subcommand + " " + " ".join(self.args.name)
3432
)
3533

3634
self.show_intro()
@@ -55,11 +53,11 @@ def populate_zones(
5553
for x in self.repo.index.diff(None):
5654
if "git-sim_media" not in x.a_path:
5755
secondColumnFileNames.add(x.a_path)
58-
for name in self.scene.args.name:
56+
for name in self.args.name:
5957
if name == x.a_path:
6058
thirdColumnFileNames.add(x.a_path)
6159
secondColumnArrowMap[x.a_path] = m.Arrow(
62-
stroke_width=3, color=self.scene.fontColor
60+
stroke_width=3, color=self.fontColor
6361
)
6462
try:
6563
for y in self.repo.index.diff("HEAD"):
@@ -73,9 +71,9 @@ def populate_zones(
7371
for z in self.repo.untracked_files:
7472
if "git-sim_media" not in z:
7573
firstColumnFileNames.add(z)
76-
for name in self.scene.args.name:
74+
for name in self.args.name:
7775
if name == z:
7876
thirdColumnFileNames.add(z)
7977
firstColumnArrowMap[z] = m.Arrow(
80-
stroke_width=3, color=self.scene.fontColor
78+
stroke_width=3, color=self.fontColor
8179
)

0 commit comments

Comments
 (0)