Skip to content

Use pydantic settings #52

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 35 additions & 35 deletions git_sim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,106 +21,106 @@
import git_sim.stash
import git_sim.status
import git_sim.tag
from git_sim.settings import ImgFormat, Settings, VideoFormat
from git_sim.settings import ImgFormat, VideoFormat, settings

app = typer.Typer()


@app.callback(no_args_is_help=True)
def main(
animate: bool = typer.Option(
Settings.animate,
settings.animate,
help="Animate the simulation and output as an mp4 video",
),
auto_open: bool = typer.Option(
Settings.auto_open,
settings.auto_open,
"--auto-open",
" /-d",
help="Enable / disable the automatic opening of the image/video file after generation",
),
img_format: ImgFormat = typer.Option(
Settings.img_format,
settings.img_format,
help="Output format for the image files.",
),
light_mode: bool = typer.Option(
Settings.light_mode,
settings.light_mode,
"--light-mode",
help="Enable light-mode with white background",
),
logo: pathlib.Path = typer.Option(
Settings.logo,
settings.logo,
help="The path to a custom logo to use in the animation intro/outro",
),
low_quality: bool = typer.Option(
Settings.low_quality,
settings.low_quality,
"--low-quality",
help="Render output video in low quality, useful for faster testing",
),
max_branches_per_commit: int = typer.Option(
Settings.max_branches_per_commit,
settings.max_branches_per_commit,
help="Maximum number of branch labels to display for each commit",
),
max_tags_per_commit: int = typer.Option(
Settings.max_tags_per_commit,
settings.max_tags_per_commit,
help="Maximum number of tags to display for each commit",
),
media_dir: pathlib.Path = typer.Option(
Settings.media_dir,
settings.media_dir,
help="The path to output the animation data and video file",
),
outro_bottom_text: str = typer.Option(
Settings.outro_bottom_text,
settings.outro_bottom_text,
help="Custom text to display below the logo during the outro",
),
outro_top_text: str = typer.Option(
Settings.outro_top_text,
settings.outro_top_text,
help="Custom text to display above the logo during the outro",
),
reverse: bool = typer.Option(
Settings.reverse,
settings.reverse,
"--reverse",
"-r",
help="Display commit history in the reverse direction",
),
show_intro: bool = typer.Option(
Settings.show_intro,
settings.show_intro,
help="Add an intro sequence with custom logo and title",
),
show_outro: bool = typer.Option(
Settings.show_outro,
settings.show_outro,
help="Add an outro sequence with custom logo and text",
),
speed: float = typer.Option(
Settings.speed,
settings.speed,
help="A multiple of the standard 1x animation speed (ex: 2 = twice as fast, 0.5 = half as fast)",
),
title: str = typer.Option(
Settings.title,
settings.title,
help="Custom title to display at the beginning of the animation",
),
video_format: VideoFormat = typer.Option(
Settings.video_format.value,
settings.video_format.value,
help="Output format for the animation files.",
case_sensitive=False,
),
):
Settings.animate = animate
Settings.auto_open = auto_open
Settings.img_format = img_format
Settings.light_mode = light_mode
Settings.logo = logo
Settings.low_quality = low_quality
Settings.max_branches_per_commit = max_branches_per_commit
Settings.max_tags_per_commit = max_tags_per_commit
Settings.media_dir = media_dir
Settings.outro_bottom_text = outro_bottom_text
Settings.outro_top_text = outro_top_text
Settings.reverse = reverse
Settings.show_intro = show_intro
Settings.show_outro = show_outro
Settings.speed = speed
Settings.title = title
Settings.video_format = video_format
settings.animate = animate
settings.auto_open = auto_open
settings.img_format = img_format
settings.light_mode = light_mode
settings.logo = logo
settings.low_quality = low_quality
settings.max_branches_per_commit = max_branches_per_commit
settings.max_tags_per_commit = max_tags_per_commit
settings.media_dir = media_dir
settings.outro_bottom_text = outro_bottom_text
settings.outro_top_text = outro_top_text
settings.reverse = reverse
settings.show_intro = show_intro
settings.show_outro = show_outro
settings.speed = speed
settings.title = title
settings.video_format = video_format


app.command()(git_sim.add.add)
Expand Down
4 changes: 2 additions & 2 deletions git_sim/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from git_sim.animations import handle_animations
from git_sim.git_sim_base_command import GitSimBaseCommand
from git_sim.settings import Settings
from git_sim.settings import settings


class Add(GitSimBaseCommand):
Expand All @@ -30,7 +30,7 @@ def __init__(self, files: list[str]):

def construct(self):
print(
f"{Settings.INFO_STRING} {type(self).__name__.lower()} {' '.join(self.files)}"
f"{settings.INFO_STRING} {type(self).__name__.lower()} {' '.join(self.files)}"
)

self.show_intro()
Expand Down
26 changes: 9 additions & 17 deletions git_sim/animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from manim import WHITE, Scene, config
from manim.utils.file_ops import open_file

from git_sim.settings import Settings
from git_sim.settings import settings


def handle_animations(scene: Scene) -> None:
Expand All @@ -25,30 +25,22 @@ def handle_animations(scene: Scene) -> None:
).working_tree_dir.split("\\")[-1]

config.media_dir = os.path.join(
os.path.expanduser(Settings.media_dir), "git-sim_media"
os.path.expanduser(settings.media_dir), "git-sim_media"
)
config.verbosity = "ERROR"

# If the env variable is set and no argument provided, use the env variable value
if os.getenv("git_sim_media_dir") and Settings.media_dir == ".":
config.media_dir = os.path.join(
os.path.expanduser(os.getenv("git_sim_media_dir")),
"git-sim_media",
repo_name,
)

if Settings.low_quality:
if settings.low_quality:
config.quality = "low_quality"

if Settings.light_mode:
if settings.light_mode:
config.background_color = WHITE

t = datetime.datetime.fromtimestamp(time.time()).strftime("%m-%d-%y_%H-%M-%S")
config.output_file = "git-sim-" + inspect.stack()[1].function + "_" + t + ".mp4"

scene.render()

if Settings.video_format == "webm":
if settings.video_format == "webm":
webm_file_path = str(scene.renderer.file_writer.movie_file_path)[:-3] + "webm"
cmd = f"ffmpeg -y -i {scene.renderer.file_writer.movie_file_path} -hide_banner -loglevel error -c:v libvpx-vp9 -crf 50 -b:v 0 -b:a 128k -c:a libopus {webm_file_path}"
print("Converting video output to .webm format...")
Expand All @@ -60,7 +52,7 @@ def handle_animations(scene: Scene) -> None:
os.remove(scene.renderer.file_writer.movie_file_path)
scene.renderer.file_writer.movie_file_path = webm_file_path

if not Settings.animate:
if not settings.animate:
video = cv2.VideoCapture(str(scene.renderer.file_writer.movie_file_path))
success, image = video.read()
if success:
Expand All @@ -70,7 +62,7 @@ def handle_animations(scene: Scene) -> None:
+ "_"
+ t
+ "."
+ Settings.img_format
+ settings.img_format
)
image_file_path = os.path.join(
os.path.join(config.media_dir, "images"), image_file_name
Expand All @@ -80,9 +72,9 @@ def handle_animations(scene: Scene) -> None:
else:
print("Output video location:", scene.renderer.file_writer.movie_file_path)

if Settings.auto_open:
if settings.auto_open:
try:
if not Settings.animate:
if not settings.animate:
open_file(image_file_path)
else:
open_file(scene.renderer.file_writer.movie_file_path)
Expand Down
8 changes: 4 additions & 4 deletions git_sim/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from git_sim.animations import handle_animations
from git_sim.git_sim_base_command import GitSimBaseCommand
from git_sim.settings import Settings
from git_sim.settings import settings


class Branch(GitSimBaseCommand):
Expand All @@ -12,7 +12,7 @@ def __init__(self, name: str):
self.name = name

def construct(self):
print(f"{Settings.INFO_STRING} {type(self).__name__.lower()} {self.name}")
print(f"{settings.INFO_STRING} {type(self).__name__.lower()} {self.name}")

self.show_intro()
self.get_commits()
Expand All @@ -39,8 +39,8 @@ def construct(self):

fullbranch = m.VGroup(branchRec, branchText)

if Settings.animate:
self.play(m.Create(fullbranch), run_time=1 / Settings.speed)
if settings.animate:
self.play(m.Create(fullbranch), run_time=1 / settings.speed)
else:
self.add(fullbranch)

Expand Down
4 changes: 2 additions & 2 deletions git_sim/cherrypick.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from git_sim.animations import handle_animations
from git_sim.git_sim_base_command import GitSimBaseCommand
from git_sim.settings import Settings
from git_sim.settings import settings


class CherryPick(GitSimBaseCommand):
Expand Down Expand Up @@ -35,7 +35,7 @@ def __init__(self, commit: str, edit: str):

def construct(self):
print(
f"{Settings.INFO_STRING} {type(self).__name__.lower()} {self.commit}"
f"{settings.INFO_STRING} {type(self).__name__.lower()} {self.commit}"
+ ((' -e "' + self.edit + '"') if self.edit else "")
)

Expand Down
6 changes: 3 additions & 3 deletions git_sim/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import git
import manim as m
import typer
from git_sim.animations import handle_animations
from git_sim.settings import Settings

from git_sim.animations import handle_animations
from git_sim.git_sim_base_command import GitSimBaseCommand
from git_sim.settings import settings


class Commit(GitSimBaseCommand):
Expand All @@ -32,7 +32,7 @@ def __init__(self, message: str, amend: bool):

def construct(self):
print(
f"{Settings.INFO_STRING} {type(self).__name__.lower()} {'--amend ' if self.amend else ''}"
f"{settings.INFO_STRING } {type(self).__name__.lower()} {'--amend ' if self.amend else ''}"
+ '-m "'
+ self.message
+ '"'
Expand Down
Loading