Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
refactor: build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nullishamy committed May 19, 2024
1 parent d8a7720 commit df80cc3
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 107 deletions.
120 changes: 53 additions & 67 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os, re, shutil, subprocess, argparse, glob, logging, zipfile

from dataclasses import dataclass
from typing import Literal, List
from typing import Any, Literal, List

from catppuccin import PALETTE
from catppuccin.models import Flavor, Color
Expand Down Expand Up @@ -30,6 +30,20 @@ def id(self) -> str:
return ",".join(self.tweaks)


@dataclass
class Suffix:
true_value: str
test: Any # callback function
false_value: str = ""


IS_DARK = Suffix(true_value="-Dark", test=lambda ctx: ctx.flavor.dark)
IS_LIGHT = Suffix(true_value="-Light", test=lambda ctx: not ctx.flavor.dark)
IS_WINDOW_NORMAL = Suffix(true_value="-Normal", test=lambda ctx: ctx.tweaks.has('normal'))
DARK_LIGHT = Suffix(
true_value="-Dark", false_value="-Light", test=lambda ctx: ctx.flavor.dark
)

@dataclass
class BuildContext:
build_root: str
Expand All @@ -46,26 +60,15 @@ def output_dir(self) -> str:
def build_id(self) -> str:
return f"{self.theme_name}-{self.flavor.identifier}-{self.accent.identifier}-{self.size}+{self.tweaks.id() or 'default'}"

def apply_suffix(self, suffix: Suffix) -> str:
if suffix.test(self):
return suffix.true_value
else:
return suffix.false_value

def build(ctx: BuildContext):
dark_suffix = ""
light_suffix = ""
window_suffix = ""
scheme_suffix = "-Catppuccin"

if ctx.tweaks.has("normal"):
window_suffix = "-Normal"

if ctx.flavor == "latte":
light_suffix = "-Light"
suffix = "-Light"

if ctx.flavor != "":
dark_suffix = "-Dark"
suffix = "-Dark"

def build(ctx: BuildContext):
output_dir = ctx.output_dir()
# [[ -d "${THEME_DIR}" ]] && rm -rf "${THEME_DIR}"
logger.info(f"Building into '{output_dir}'...")

apply_tweaks(ctx)
Expand All @@ -81,7 +84,7 @@ def build(ctx: BuildContext):
file.write("[X-GNOME-Metatheme]\n")
file.write(f"GtkTheme={ctx.build_id()}\n")
file.write(f"MetacityTheme={ctx.build_id()}\n")
file.write(f"IconTheme=Tela-circle{dark_suffix}\n")
file.write(f"IconTheme=Tela-circle{ctx.apply_suffix(IS_DARK)}\n")
file.write(f"CursorTheme={ctx.flavor.name}-cursors\n")
file.write("ButtonLayout=close,minimize,maximize:menu\n")

Expand All @@ -94,7 +97,7 @@ def build(ctx: BuildContext):
[
"sassc",
*SASSC_OPT,
f"{SRC_DIR}/main/gnome-shell/gnome-shell{suffix}.scss",
f"{SRC_DIR}/main/gnome-shell/gnome-shell{ctx.apply_suffix(DARK_LIGHT)}.scss",
f"{output_dir}/gnome-shell/gnome-shell.css",
]
)
Expand All @@ -104,7 +107,7 @@ def build(ctx: BuildContext):
[
"sassc",
*SASSC_OPT,
f"{SRC_DIR}/main/gtk-3.0/gtk{suffix}.scss",
f"{SRC_DIR}/main/gtk-3.0/gtk{ctx.apply_suffix(DARK_LIGHT)}.scss",
f"{output_dir}/gtk-3.0/gtk.css",
]
)
Expand All @@ -123,7 +126,7 @@ def build(ctx: BuildContext):
[
"sassc",
*SASSC_OPT,
f"{SRC_DIR}/main/gtk-4.0/gtk{suffix}.scss",
f"{SRC_DIR}/main/gtk-4.0/gtk{ctx.apply_suffix(DARK_LIGHT)}.scss",
f"{output_dir}/gtk-4.0/gtk.css",
]
)
Expand All @@ -142,14 +145,14 @@ def build(ctx: BuildContext):
[
"sassc",
*SASSC_OPT,
f"{SRC_DIR}/main/cinnamon/cinnamon{suffix}.scss",
f"{SRC_DIR}/main/cinnamon/cinnamon{ctx.apply_suffix(DARK_LIGHT)}.scss",
f"{output_dir}/cinnamon/cinnamon.css",
]
)

os.makedirs(f"{output_dir}/metacity-1", exist_ok=True)
shutil.copyfile(
f"{SRC_DIR}/main/metacity-1/metacity-theme-3{window_suffix}.xml",
f"{SRC_DIR}/main/metacity-1/metacity-theme-3{ctx.apply_suffix(IS_WINDOW_NORMAL)}.xml",
f"{output_dir}/metacity-1/metacity-theme-3.xml",
)
# FIXME: Symlinks aren't working as intended
Expand All @@ -165,20 +168,20 @@ def build(ctx: BuildContext):

os.makedirs(f"{output_dir}/xfwm4", exist_ok=True)
shutil.copyfile(
f"{SRC_DIR}/main/xfwm4/themerc{light_suffix}",
f"{SRC_DIR}/main/xfwm4/themerc{ctx.apply_suffix(IS_LIGHT)}",
f"{output_dir}/xfwm4/themerc",
)

os.makedirs(f"{output_dir}-hdpi/xfwm4", exist_ok=True)
shutil.copyfile(
f"{SRC_DIR}/main/xfwm4/themerc{light_suffix}",
f"{SRC_DIR}/main/xfwm4/themerc{ctx.apply_suffix(IS_LIGHT)}",
f"{output_dir}-hdpi/xfwm4/themerc",
)
subst_text(f"{output_dir}-hdpi/xfwm4/themerc", "button_offset=6", "button_offset=9")

os.makedirs(f"{output_dir}-xhdpi/xfwm4", exist_ok=True)
shutil.copyfile(
f"{SRC_DIR}/main/xfwm4/themerc{light_suffix or ''}",
f"{SRC_DIR}/main/xfwm4/themerc{ctx.apply_suffix(IS_LIGHT)}",
f"{output_dir}-xhdpi/xfwm4/themerc",
)
subst_text(
Expand All @@ -187,11 +190,11 @@ def build(ctx: BuildContext):

if not ctx.flavor.dark:
shutil.copytree(
f"{SRC_DIR}/main/plank/theme-Light{scheme_suffix}/", f"{output_dir}/plank"
f"{SRC_DIR}/main/plank/theme-Light-Catppuccin/", f"{output_dir}/plank"
)
else:
shutil.copytree(
f"{SRC_DIR}/main/plank/theme-Dark{scheme_suffix}/", f"{output_dir}/plank"
f"{SRC_DIR}/main/plank/theme-Dark-Catppuccin/", f"{output_dir}/plank"
)


Expand Down Expand Up @@ -285,31 +288,13 @@ def apply_tweaks(ctx: BuildContext):


def make_assets(ctx: BuildContext):
color_suffix = ""
if not ctx.flavor.dark:
color_suffix = "-Light"
else:
color_suffix = "-Dark"

dark_suffix = ""
if ctx.flavor.dark:
dark_suffix = "-Dark"

light_suffix = ""
if not ctx.flavor.dark:
light_suffix = "-Light"

window_suffix = ""
if ctx.tweaks.has("normal"):
window_suffix = "-Normal"

output_dir = ctx.output_dir()

os.makedirs(f"{output_dir}/cinnamon/assets", exist_ok=True)
for file in glob.glob(f"{SRC_DIR}/assets/cinnamon/theme/*.svg"):
shutil.copy(file, f"{output_dir}/cinnamon/assets")
shutil.copy(
f"{SRC_DIR}/assets/cinnamon/thumbnail{color_suffix}.svg",
f"{SRC_DIR}/assets/cinnamon/thumbnail{ctx.apply_suffix(DARK_LIGHT)}.svg",
f"{output_dir}/cinnamon/thumbnail.png",
)

Expand All @@ -328,11 +313,11 @@ def make_assets(ctx: BuildContext):
dirs_exist_ok=True,
)
shutil.copyfile(
f"{SRC_DIR}/assets/gtk/thumbnail{dark_suffix}.svg",
f"{SRC_DIR}/assets/gtk/thumbnail{ctx.apply_suffix(IS_DARK)}.svg",
f"{output_dir}/gtk-3.0/thumbnail.png",
)
shutil.copyfile(
f"{SRC_DIR}/assets/gtk/thumbnail{dark_suffix}.svg",
f"{SRC_DIR}/assets/gtk/thumbnail{ctx.apply_suffix(IS_DARK)}.svg",
f"{output_dir}/gtk-4.0/thumbnail.png",
)

Expand Down Expand Up @@ -388,37 +373,37 @@ def make_assets(ctx: BuildContext):
for file in glob.glob(f"{SRC_DIR}/assets/cinnamon/common-assets/*.svg"):
shutil.copy(file, f"{output_dir}/cinnamon/assets")

for file in glob.glob(f"{SRC_DIR}/assets/cinnamon/assets-{dark_suffix}/*.svg"):
for file in glob.glob(f"{SRC_DIR}/assets/cinnamon/assets{ctx.apply_suffix(IS_DARK)}/*.svg"):
shutil.copy(file, f"{output_dir}/cinnamon/assets")

for file in glob.glob(f"{SRC_DIR}/assets/gnome-shell/common-assets/*.svg"):
shutil.copy(file, f"{output_dir}/gnome-shell/assets")

for file in glob.glob(f"{SRC_DIR}/assets/gnome-shell/assets-{dark_suffix}/*.svg"):
for file in glob.glob(f"{SRC_DIR}/assets/gnome-shell/assets{ctx.apply_suffix(IS_DARK)}/*.svg"):
shutil.copy(file, f"{output_dir}/gnome-shell/assets")

for file in glob.glob(f"{SRC_DIR}/assets/gtk/symbolics/*.svg"):
shutil.copy(file, f"{output_dir}/gtk-3.0/assets")
shutil.copy(file, f"{output_dir}/gtk-4.0/assets")

for file in glob.glob(f"{SRC_DIR}/assets/metacity-1/assets-{window_suffix}/*.svg"):
for file in glob.glob(f"{SRC_DIR}/assets/metacity-1/assets{ctx.apply_suffix(IS_WINDOW_NORMAL)}/*.svg"):
shutil.copy(file, f"{output_dir}/metacity-1/assets")
shutil.copy(
f"{SRC_DIR}/assets/metacity-1/thumbnail{dark_suffix}.png",
f"{SRC_DIR}/assets/metacity-1/thumbnail{ctx.apply_suffix(IS_DARK)}.png",
f"{output_dir}/metacity-1/thumbnail.png",
)

# TODO: Make our own assets for this and patch them in with the patch system, then code it to be
# {src_dir}/assets/xfwm4/assets{light_suffix}-Catppuccin/
# where assets-Light-Catppuccin will have latte
# nad assets-Catppuccin will have mocha or something
for file in glob.glob(f"{SRC_DIR}/assets/xfwm4/assets{light_suffix}/*.png"):
for file in glob.glob(f"{SRC_DIR}/assets/xfwm4/assets{ctx.apply_suffix(IS_LIGHT)}/*.png"):
shutil.copy(file, f"{output_dir}/xfwm4")

for file in glob.glob(f"{SRC_DIR}/assets/xfwm4/assets{light_suffix}-hdpi/*.png"):
for file in glob.glob(f"{SRC_DIR}/assets/xfwm4/assets{ctx.apply_suffix(IS_LIGHT)}-hdpi/*.png"):
shutil.copy(file, f"{output_dir}-hdpi/xfwm4")

for file in glob.glob(f"{SRC_DIR}/assets/xfwm4/assets{light_suffix}-xhdpi/*.png"):
for file in glob.glob(f"{SRC_DIR}/assets/xfwm4/assets{ctx.apply_suffix(IS_LIGHT)}-xhdpi/*.png"):
shutil.copy(file, f"{output_dir}-xhdpi/xfwm4")


Expand Down Expand Up @@ -556,7 +541,7 @@ def parse_args():
"sapphire",
"blue",
"lavender",
"all"
"all",
],
help="Accent of the theme.",
)
Expand Down Expand Up @@ -599,13 +584,14 @@ def parse_args():

return parser.parse_args()


def main():
args = parse_args()
if args.patch:
apply_colloid_patches()

palette = getattr(PALETTE, args.flavor)
accents=[
accents = [
"rosewater",
"flamingo",
"pink",
Expand All @@ -622,16 +608,16 @@ def main():
"lavender",
]

if args.accent == 'all':
if args.accent == "all":
for accent in accents:
accent = getattr(palette.colors, accent)

tweaks = Tweaks(tweaks=args.tweaks)

if args.zip:
output_format = 'zip'
output_format = "zip"
else:
output_format = 'dir'
output_format = "dir"

ctx = BuildContext(
build_root=args.dest,
Expand All @@ -640,7 +626,7 @@ def main():
accent=accent,
size=args.size,
tweaks=tweaks,
output_format=output_format
output_format=output_format,
)

tweaks_temp()
Expand All @@ -652,9 +638,9 @@ def main():
tweaks = Tweaks(tweaks=args.tweaks)

if args.zip:
output_format = 'zip'
output_format = "zip"
else:
output_format = 'dir'
output_format = "dir"

ctx = BuildContext(
build_root=args.dest,
Expand All @@ -663,7 +649,7 @@ def main():
accent=accent,
size=args.size,
tweaks=tweaks,
output_format=output_format
output_format=output_format,
)

logger.info("Building temp tweaks file")
Expand All @@ -678,4 +664,4 @@ def main():
try:
main()
except Exception as e:
logger.error("Something went wrong when building the theme:", exc_info=e)
logger.error("Something went wrong when building the theme:", exc_info=e)
16 changes: 8 additions & 8 deletions patches/colloid/palette.tera
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@ index 00000000..8a905942
+
+// Red
+$red-light: #{{ palette.red.hex }};
+$red-dark: #{{ palette.red | mod(lightness=30) | get(key="hex") }};
+$red-dark: #{{ palette.red.hex }};
+
+// Pink
+$pink-light: #{{ palette.pink.hex }};
+$pink-dark: #{{ palette.pink | mod(lightness=30) | get(key="hex") }};
+$pink-dark: #{{ palette.pink.hex }};
+
+// Purple
+$purple-light: #{{ palette.mauve.hex }};
+$purple-dark: #{{ palette.mauve | mod(lightness=30) | get(key="hex") }};
+$purple-dark: #{{ palette.mauve.hex }};
+
+// Blue
+$blue-light: #{{ palette.blue.hex }};
+$blue-dark: #{{ palette.blue | mod(lightness=30) | get(key="hex") }};
+$blue-dark: #{{ palette.blue.hex }};
+
+// Teal
+$teal-light: #{{ palette.teal.hex }};
+$teal-dark: #{{ palette.teal | mod(lightness=30) | get(key="hex") }};
+$teal-dark: #{{ palette.teal.hex }};
+
+// Green
+$green-light: #{{ palette.green.hex }};
+$green-dark: #{{ palette.green | mod(lightness=30) | get(key="hex") }};
+$green-dark: #{{ palette.green.hex }};
+
+// Yellow
+$yellow-light: #{{ palette.yellow.hex }};
+$yellow-dark: #{{ palette.yellow | mod(lightness=30) | get(key="hex") }};
+$yellow-dark: #{{ palette.yellow.hex }};
+
+// Orange
+$orange-light: #{{ palette.peach.hex }};
+$orange-dark: #{{ palette.peach | mod(lightness=30) | get(key="hex") }};
+$orange-dark: #{{ palette.peach.hex }};
+
+// Grey
+$grey-050: #{{ palette.text.hex }};
Expand Down
Loading

0 comments on commit df80cc3

Please sign in to comment.