Skip to content
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

feat: brand_yaml Python package #12

Merged
merged 119 commits into from
Oct 4, 2024
Merged
Changes from 110 commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
e356b24
python: init package with BrandMeta
gadenbuie Aug 30, 2024
59d866f
feat: update brand.spec.yml
gadenbuie Aug 30, 2024
7a6575e
feat: Add `brand.schema.json`
gadenbuie Aug 30, 2024
1ed32e7
chore(examples): add brand-posit.yml
gadenbuie Aug 30, 2024
fd21186
rename: _meta.py --> _brand_meta.py
gadenbuie Aug 30, 2024
2e27ecf
feat: BrandLightDark and BrandStringLightDark
gadenbuie Aug 30, 2024
34fad22
chore(3.9): Use `Union[]` type
gadenbuie Aug 30, 2024
6fa19a4
chore(python): Add eval-type-backport dependency
gadenbuie Aug 30, 2024
4007a3b
tests(BrandMeta): Test empty `meta`
gadenbuie Aug 30, 2024
4afca73
chore(BrandMeta) clean up types
gadenbuie Aug 30, 2024
111221b
feat(BrandLogo)[WIP]: Add brand.logo
gadenbuie Aug 30, 2024
022b440
feat: recursive "with_" replacement at creation time
gadenbuie Sep 3, 2024
3b0fb98
feat: Support reading data with `with:` and replace in `with`
gadenbuie Sep 3, 2024
22e9a0c
tests(BrandLogo): Add brand logo tests
gadenbuie Sep 3, 2024
ac539ce
docs(BrandLogo): fix attributes syntax
gadenbuie Sep 3, 2024
e101501
feat(BrandWith): Always revalidate instances
gadenbuie Sep 3, 2024
e7ea787
test(BrandWith): Add more nested `with` tests
gadenbuie Sep 3, 2024
5dd45c3
chore: Add TODO about recursing into nested BrandWith instances
gadenbuie Sep 3, 2024
9478b91
chore(BrandLogo): forbid extra fields
gadenbuie Sep 3, 2024
e48b534
feat(BrandColor): Add brand.color
gadenbuie Sep 3, 2024
7fcdce3
fix: whitespace
gadenbuie Sep 4, 2024
362f4be
chore(examples): Full meta.name for Posit
gadenbuie Sep 4, 2024
74573c2
fix: Replace `with` on assignment, too
gadenbuie Sep 4, 2024
81405e8
chore(BrandLogo): Use generic `BrandLightDark`
gadenbuie Sep 4, 2024
2c3d0ec
chore: revalidate instances and validate assignment
gadenbuie Sep 4, 2024
dd3a5b8
feat(logging): Add pkg logging
gadenbuie Sep 5, 2024
aa4a13f
feat(BrandWith): Check for circular references, improve recursrive wi…
gadenbuie Sep 5, 2024
0c6d3c7
chore: Simplify file names
gadenbuie Sep 5, 2024
6439e21
chore: rename brand_yaml._utils --> brand_yaml._defs
gadenbuie Sep 5, 2024
2a74927
chore: Generalize definition resolution beyond just `self.with_`
gadenbuie Sep 5, 2024
b7e534a
chore: log format and logging in tests
gadenbuie Sep 5, 2024
4083205
chore: configure ruff for package and vscode
gadenbuie Sep 5, 2024
587ba41
chore: remove accidentally commited scratch file
gadenbuie Sep 5, 2024
b48a55d
feat(color): Resolve named colors as with `with_` field
gadenbuie Sep 5, 2024
350641e
refactor(BrandColor): get color fields from model_fields
gadenbuie Sep 6, 2024
a12dd98
feat(BrandTypography): Add `brand.typography`
gadenbuie Sep 6, 2024
fdb0b81
chore: Suppress unused fields in `repr()` methods
gadenbuie Sep 6, 2024
e962daf
tests(BrandTypographyFrontFile): `family` is required
gadenbuie Sep 6, 2024
7c24436
chore(pyright): pyright is now happy
gadenbuie Sep 9, 2024
18950e9
feat(typography.monospace): Update monospace properties
gadenbuie Sep 10, 2024
bf3cd2e
chore(BrandTypography): Already inherits from BrandBase
gadenbuie Sep 10, 2024
b3c6776
tests(BrandTypography): Ensure typography fields have the correct fields
gadenbuie Sep 10, 2024
f5eceb5
feat(typography): Add Font Bunny foundry
gadenbuie Sep 10, 2024
dbbc91d
feat(typography): Add import URL for Google Fonts
gadenbuie Sep 10, 2024
f2905e3
feat: create abstract class for google fonts API
gadenbuie Sep 10, 2024
1c8a744
feat(typography): Monospace fields inherit from same parent class
gadenbuie Sep 11, 2024
c806b84
tests(typography): Add snapshot tests
gadenbuie Sep 11, 2024
c43b99d
chore: move pyproject.toml to the root of the repository
gadenbuie Sep 11, 2024
0ae7a03
chore: use standard hatch versioning for now
gadenbuie Sep 11, 2024
41fd121
chore: add ipykernel to optional quarto deps
gadenbuie Sep 11, 2024
1a94b55
feat(typography): Default to `seq(100, 900, by=100)` for font weights…
gadenbuie Sep 13, 2024
426a1cf
feat(typography): Restructure `source: file` fonts
gadenbuie Sep 13, 2024
4219295
feat(brand.color.palette): Rename from color.with
gadenbuie Sep 17, 2024
2077721
feat(brand.logo.images): Rename from `logo.with`
gadenbuie Sep 17, 2024
481d8b6
tests(brand.color): Add snapshot tests
gadenbuie Sep 17, 2024
719b676
feat(typography): Update typographic options
gadenbuie Sep 17, 2024
654f583
chore: Add comment headers and remove dead code
gadenbuie Sep 17, 2024
d93c488
chore: Add makefile
gadenbuie Sep 18, 2024
dcaecfb
chore(color): Move attribute descriptions to attribute docstrings
gadenbuie Sep 18, 2024
19ae8e4
chore: uv sync --all-extras --upgrade
gadenbuie Sep 18, 2024
535330b
chore: Move dev deps to `tool.uv` section
gadenbuie Sep 18, 2024
578ff1b
chore: Add ruff to project makefile
gadenbuie Sep 18, 2024
c2182ac
chore: ruff check --fix
gadenbuie Sep 18, 2024
e61734b
chore: Add package checking with tox
gadenbuie Sep 18, 2024
102b2fa
ci: Add package testing
gadenbuie Sep 18, 2024
dcf7428
ci(py-test): Fix workflow and make targets
gadenbuie Sep 18, 2024
2bf3533
chore: add todo notes, other small edits
gadenbuie Sep 18, 2024
7d19c00
feat: Automatically find `_brand.yml` from `__file__`
gadenbuie Sep 18, 2024
6cfb8a4
feat(Brand): Include hidden `source` field to track path to `brand.ym…
gadenbuie Sep 18, 2024
dd90630
feat(BrandMeta.name): Always promote `brand.meta.name = str` to `Bran…
gadenbuie Sep 18, 2024
26c8dcf
feat(BrandMeta.link): Promote single string to `brand.meta.link = {ho…
gadenbuie Sep 18, 2024
cb3cc77
tests(meta): Add snapshot tests for `brand.meta`
gadenbuie Sep 18, 2024
d3a614d
feat(brand.typography): Resolve `color`/`background-color` from `bran…
gadenbuie Sep 18, 2024
788f8c9
chore(brand.logo): update TODO comment
gadenbuie Sep 18, 2024
1a74512
ci: sync specific python version
gadenbuie Sep 18, 2024
d79eea0
chore(read_brand_yaml): error if brand yaml does not parse into a dic…
gadenbuie Sep 19, 2024
0412a39
chore(brand.path): Rename from `brand.source`
gadenbuie Sep 19, 2024
3bfa402
chore(brand.typography): Make supported formats a field of BrandUnsup…
gadenbuie Sep 19, 2024
349da8a
chore(typography): rename constants
gadenbuie Sep 19, 2024
65f0384
chore(defs_replace_recursively): Swap order of defs/items
gadenbuie Sep 19, 2024
812b415
feat(typography): Easy font setting, default is google font
gadenbuie Sep 20, 2024
1fa63e4
chore(brand.typography): Factor out common FontSource type
gadenbuie Sep 20, 2024
ac0feab
feat(brand.typography): Prepare CSS font declarations
gadenbuie Sep 20, 2024
4112312
fix(brand.typography): Assert not None in tests
gadenbuie Sep 20, 2024
dcbe646
fix(brand.typography): Before validators are applied to widest type
gadenbuie Sep 20, 2024
a0458de
fix(BrandMetaLink): Allow extra links
gadenbuie Sep 20, 2024
5843c5d
fix(brand.typography): validate default URL fields for correct typing
gadenbuie Sep 20, 2024
4bd6271
feat(Brand): Add `.from_yaml()` method
gadenbuie Sep 20, 2024
0f08677
chore: move BrandBase to `.base`
gadenbuie Sep 24, 2024
3dd0115
feat(typography): Validate paths relative to `_brand.yml`, allow `wei…
gadenbuie Sep 24, 2024
4b5a2f5
feat(typography): Support variable font weights
gadenbuie Sep 25, 2024
ce4db4b
chore(typography): Update `validate_path()` method name
gadenbuie Sep 25, 2024
d7164c0
fix(FileLocation): Path might already be absolute
gadenbuie Sep 25, 2024
2f93b12
feat: Also find `_brand.yml` in parent `brand/` or `_brand` directories
gadenbuie Sep 26, 2024
8e857d3
feat(FileLocation): set and validate in one (public-ish) method
gadenbuie Sep 26, 2024
a4d0b7c
feat(BrandLogo): Add file validation to logo files
gadenbuie Sep 26, 2024
8ad9524
chore(read_brand_yaml): standardize path early
gadenbuie Oct 1, 2024
4d80414
feat: Throw an error if a color field refers to `color.{name}` which …
gadenbuie Oct 1, 2024
08cb6c9
feat(path): Simplify file location logic
gadenbuie Oct 2, 2024
82100a9
chore: Move `FileLocation` to `.file`
gadenbuie Oct 2, 2024
c9c1e5f
chore: Rename test_file.py as well
gadenbuie Oct 3, 2024
ab6ddde
feat(FileLocationLocal): Now has absolute, relative, exists methods
gadenbuie Oct 3, 2024
f553a74
chore: Remove `BrandWith`
gadenbuie Oct 3, 2024
ada04de
chore(check_circular_references): Stronger typing
gadenbuie Oct 3, 2024
7484197
chore(defs_replace_recursively): Improve typing
gadenbuie Oct 3, 2024
fbca376
chore: add and improve coverage
gadenbuie Oct 3, 2024
18a77c9
chore: docs remove refs to `with_`
gadenbuie Oct 3, 2024
7a1d967
chore: fix format issue
gadenbuie Oct 3, 2024
0ae4fb0
chore(defs_replace_recursively): Make `defs` a required argument
gadenbuie Oct 4, 2024
87e8be2
chore(defs): Replace `is_leaf_node()` with typeguard for `dict | Base…
gadenbuie Oct 4, 2024
5be99f7
chore: coverage settings
gadenbuie Oct 4, 2024
6e8a593
tests(typography): Increase coverage
gadenbuie Oct 4, 2024
2690eae
chore(file): Remove unused init method
gadenbuie Oct 4, 2024
c5dda80
chore: Move jsonschema to dev deps
gadenbuie Oct 4, 2024
d3673d6
chore(typography): Relocate custom error
gadenbuie Oct 4, 2024
a18d5c5
chore: fix typos
gadenbuie Oct 4, 2024
a69c92e
feat(Brand.from_yaml_str): Add method for creating Brand instances fr…
gadenbuie Oct 4, 2024
c4e0c54
fix(BrandTypographyFontPath): Fix font-weight range
gadenbuie Oct 4, 2024
1415e9c
fix(BrandTypographyGoogleFontsWeightRange): Improve validation and te…
gadenbuie Oct 4, 2024
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
52 changes: 52 additions & 0 deletions .github/workflows/py-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test - Python

on:
push:
branches: [main]
paths:
- 'pkg-py/*'
- 'pyproject.toml'
- 'uv.lock'
- '.github/workflows/py-test.yml'
pull_request:
paths:
- 'pkg-py/*'
- 'pyproject.toml'
- 'uv.lock'
- '.github/workflows/py-test.yml'

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"

steps:
- uses: actions/checkout@v4

- name: 🚀 Install uv
uses: astral-sh/setup-uv@v2

- name: 🐍 Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: 📦 Install the project
run: uv sync --python ${{ matrix.python-version }} --no-dev --extra test

- name: 🧪 Check tests
run: make py-check-tests

- name: 📝 Check types
run: make py-check-types

- name: 📐 Check formatting
run: make py-check-format
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
.coverage
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"charliermarsh.ruff"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff"
}
}
78 changes: 78 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
.PHONY: docs
docs: ## [docs] Build the documentation
quarto render docs

.PHONY: docs-preview
docs-preview: ## [docs] Preview the documentation
quarto preview docs

.PHONY: py-setup
py-setup: ## [py] Setup python environment
uv sync --all-extras

.PHONY: py-check
py-check: py-check-tests py-check-format py-check-types ## [py] Run python checks

.PHONY: py-check-tox
py-check-tox: ## [py] Run python 3.9 - 3.12 checks with tox
@echo ""
@echo "🔄 Running tests and type checking with tox for Python 3.9--3.12"
uv run tox run-parallel

.PHONY: py-check-tests
py-check-tests: ## [py] Run python tests
@echo ""
@echo "🧪 Running tests with pytest"
uv run pytest

.PHONY: py-check-types
py-check-types: ## [py] Run python type checks
@echo ""
@echo "📝 Checking types with pyright"
uv run pyright

.PHONY: py-check-format
py-check-format:
@echo ""
@echo "📐 Checking format with ruff"
uv run ruff check pkg-py --config pyproject.toml

.PHONY: py-format
py-format: ## [py] Format python code
uv run ruff check --fix pkg-py --config pyproject.toml
uv run ruff format pkg-py --config pyproject.toml

.PHONY: py-coverage
py-coverage: ## [py] Generate coverage report
@echo "📔 Generating coverage report"
uv run coverage run -m pytest pkg-py/tests
uv run coverage report

.PHONY: py-coverage-report
py-coverage-report: py-coverage ## [py] Generate coverage report and open it in browser
uv run coverage html
@echo ""
@echo "📡 Serving coverage report at http://localhost:8081/"
@npx http-server htmlcov --silent -p 8081

.PHONY: py-update-snaps
py-update-snaps: ## [py] Update python test snapshots
@echo "📸 Updating pytest snapshots"
uv run pytest --snapshot-update

.PHONY: help
help: ## Show help messages for make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; { \
printf "\033[32m%-18s\033[0m", $$1; \
if ($$2 ~ /^\[docs\]/) { \
printf "\033[34m[docs]\033[0m%s\n", substr($$2, 7); \
} else if ($$2 ~ /^\[py\]/) { \
printf " \033[33m[py]\033[0m%s\n", substr($$2, 5); \
} else if ($$2 ~ /^\[r\]/) { \
printf " \033[31m[r]\033[0m%s\n", substr($$2, 4); \
} else { \
printf " %s\n", $$2; \
} \
}'

.DEFAULT_GOAL := help
12 changes: 12 additions & 0 deletions examples/brand-color-direct-posit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
color:
foreground: "#151515"
background: "#FFFFFF"
primary: "#447099"
secondary: "#707073"
tertiary: "#C2C2C4"
success: "#72994E"
info: "#419599"
warning: "#EE6331"
danger: "#9A4665"
light: "#FFFFFF"
dark: "#404041"
21 changes: 21 additions & 0 deletions examples/brand-color-palette-internal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
color:
palette:
white: "#FFFFFF"
black: "#151515"
blue: "#447099"
orange: "#EE6331"
green: "#72994E"
teal: "#419599"
burgundy: "#9A4665"

foreground: black
background: white
primary: blue
secondary: "#707073"
tertiary: "#C2C2C4"
success: green
info: primary
warning: orange
danger: burgundy
light: background
dark: "#404041"
21 changes: 21 additions & 0 deletions examples/brand-color-palette-posit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
color:
palette:
white: "#FFFFFF"
black: "#151515"
blue: "#447099"
orange: "#EE6331"
green: "#72994E"
teal: "#419599"
burgundy: "#9A4665"

foreground: black
background: white
primary: blue
secondary: "#707073"
tertiary: "#C2C2C4"
success: green
info: teal
warning: orange
danger: burgundy
light: white
dark: "#404041"
13 changes: 13 additions & 0 deletions examples/brand-logo-full.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
logo:
images:
mark: logos/pandas/pandas_mark.svg
mark-white: logos/pandas/pandas_mark_white.svg
secondary: logos/pandas/pandas_secondary.svg
secondary-white: logos/pandas/pandas_secondary_white.svg
pandas: logos/pandas/pandas.svg
pandas-white: logos/pandas/pandas_white.svg
small: mark
medium:
light: logos/pandas/pandas_secondary.svg
dark: secondary-white
large: pandas
6 changes: 6 additions & 0 deletions examples/brand-logo-light-dark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
logo:
small: logos/pandas/pandas_mark.svg
medium:
light: logos/pandas/pandas_secondary.svg
dark: logos/pandas/pandas_secondary_white.svg
large: logos/pandas/pandas.svg
4 changes: 4 additions & 0 deletions examples/brand-logo-simple.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
logo:
small: logos/pandas/pandas_mark.svg
medium: logos/pandas/pandas_secondary.svg
large: logos/pandas/pandas.svg
1 change: 1 addition & 0 deletions examples/brand-logo-single.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logo: posit.png
11 changes: 11 additions & 0 deletions examples/brand-meta-full.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
meta:
name:
full: Very Big Corporation of America
short: VBC
link:
home: https://very-big-corp.com
mastodon: https://mastodon.social/@VeryBigCorpOfficial
github: https://github.com/Very-Big-Corp
linkedin: https://linkedin.com/company/very-big-corp
twitter: https://twitter.com/VeryBigCorp
facebook: https://facebook.com/Very-Big-Corp
3 changes: 3 additions & 0 deletions examples/brand-meta-small.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
meta:
name: Very Big Corp. of America
link: https://very-big-corp.com
60 changes: 60 additions & 0 deletions examples/brand-posit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
meta:
name:
full: Posit Software, PBC
short: Posit
link:
home: https://posit.co
guide: https://positpbc.atlassian.net/wiki/x/AQAgBQ
mastodon: https://fosstodon.org/@Posit
linkedin: https://www.linkedin.com/company/posit-software/
twitter: https://twitter.com/posit_pbc

logo:
small: posit-icon.png
medium: posit.png
large: posit.svg

color:
palette:
blue: "#447099"
orange: "#EE6331"
gray: "#404041"
white: "#FFFFFF"
teal: "#419599"
green: "#72994E"
burgundy: "#9A4665"
foreground: "#151515"
background: "#FFFFFF"
primary: "#447099"
secondary: "#707073"
tertiary: "#C2C2C4"
success: "#72994E"
info: "#419599"
warning: "#EE6331"
danger: "#9A4665"
light: "#FFFFFF"
dark: "#404041"

typography:
fonts:
- source: google
family: Open Sans
- source: google
family: Fira Code
- source: google
family: Roboto Slab
weight: 600
style: normal
display: block

base:
family: "Open Sans"
line-height: 1.25
size: 1rem
headings:
family: "Roboto Slab"
color: primary
weight: 600
monospace:
family: "Fira Code"
size: 0.9em
25 changes: 25 additions & 0 deletions examples/brand-typography-color.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
meta:
name: examples/brand-typography-color.yml

color:
palette:
red: "#FF6F61"
primary: "#87CEEB"
secondary: "#50C878"
danger: red
foreground: "#1b1818"
background: "#f7f4f4"

typography:
base:
color: foreground
headings:
color: primary
monospace-inline:
color: background
background-color: red
monospace-block:
color: foreground
background-color: background
link:
color: danger
48 changes: 48 additions & 0 deletions examples/brand-typography-fonts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
meta:
name: examples/brand-typography-fonts.yml
color:
primary: "#f24242"
typography:
fonts:
# Local files
- family: Open Sans
source: file
files:
- path: fonts/open-sans/OpenSans-Variable.ttf
- path: fonts/open-sans/OpenSans-Variable-Italic.ttf
style: italic

# Online files
- family: Closed Sans
source: file
files:
- path: https://example.com/Closed-Sans-Bold.woff2
weight: bold
- path: https://example.com/Closed-Sans-Italic.woff2
style: italic

# Online Font Foundries
- family: Roboto Slab
source: google
weight: 600..900
style: normal
display: block

- family: Fira Code
source: bunny
# weight: [100, 200, 300, 400, 500, 600, 700, 800, 900]
# style: [normal, italic]

base:
family: Open Sans
line-height: 1.25
size: 1rem

headings:
family: Roboto Slab
color: primary
weight: 600

monospace:
family: Fira Code
size: 0.9em
Loading