-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: change palette data structure to match json, add codegen (#29)
Co-authored-by: Raffaele Mancuso <raffaele.mancuso4@unibo.it>
- Loading branch information
1 parent
1759fd2
commit 8695144
Showing
22 changed files
with
3,138 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,6 @@ on: | |
push: | ||
paths: | ||
- "**.py" | ||
pull_request: | ||
paths: | ||
- "**.py" | ||
jobs: | ||
lint: | ||
strategy: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,6 @@ on: | |
push: | ||
paths: | ||
- '**.py' | ||
pull_request: | ||
paths: | ||
- "**.py" | ||
jobs: | ||
test: | ||
strategy: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Code generation script for creating the global palette constant.""" | ||
from __future__ import annotations | ||
|
||
import json | ||
from pathlib import Path | ||
from typing import Any, cast | ||
|
||
from catppuccin.models import HSL, RGB, Color, Flavor, FlavorColors, Palette | ||
|
||
HEADER = '''"""Catppuccin palette definition.""" | ||
from catppuccin.models import HSL, RGB, Color, Flavor, FlavorColors, Palette''' | ||
|
||
|
||
def load_palette_json() -> dict[str, Any]: | ||
"""Load palette data from `./palette.json`.""" | ||
with Path("palette.json").open() as f: | ||
return cast(dict[str, Any], json.load(f)) | ||
|
||
|
||
def make_color(fields: dict[str, Any]) -> Color: | ||
"""Create a Color instance from a set of fields.""" | ||
return Color( | ||
name=fields["name"], | ||
order=fields["order"], | ||
hex=fields["hex"], | ||
rgb=RGB(**fields["rgb"]), | ||
hsl=HSL(**fields["hsl"]), | ||
accent=fields["accent"], | ||
) | ||
|
||
|
||
def make_flavor(fields: dict[str, Any]) -> Flavor: | ||
"""Create a Flavor instance from a set of fields.""" | ||
return Flavor( | ||
name=fields["name"], | ||
order=fields["order"], | ||
dark=fields["dark"], | ||
colors=FlavorColors( | ||
**{ | ||
color_name: make_color(color_data) | ||
for color_name, color_data in fields["colors"].items() | ||
} | ||
), | ||
) | ||
|
||
|
||
def codegen() -> str: | ||
"""Generate contents of `catppuccin/palette.py`.""" | ||
palette_json = load_palette_json() | ||
palette = Palette( | ||
*[make_flavor(flavor_data) for flavor_data in palette_json.values()] | ||
) | ||
|
||
lines = [ | ||
HEADER, | ||
f"PALETTE = {palette!r}", | ||
] | ||
|
||
return "\n".join(lines) | ||
|
||
|
||
if __name__ == "__main__": | ||
with Path("catppuccin/palette.py").open("w") as f: | ||
source = codegen() | ||
print(source, file=f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""🐍 Soothing pastel theme for Python.""" | ||
from catppuccin.colour import Colour | ||
from catppuccin.flavour import Flavour | ||
|
||
__all__ = ["Colour", "Flavour"] | ||
|
||
from catppuccin.palette import PALETTE | ||
|
||
__all__ = ["PALETTE"] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.