Skip to content

Commit ed37745

Browse files
authored
feat: reimplement functions esphome needs (#2)
1 parent f7b61c4 commit ed37745

File tree

9 files changed

+55
-13
lines changed

9 files changed

+55
-13
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ jobs:
4646
runs-on: ${{ matrix.os }}
4747
steps:
4848
- uses: actions/checkout@v4
49+
with:
50+
submodules: true
4951
- uses: actions/setup-python@v5
5052
id: setup-python
5153
with:
@@ -78,6 +80,7 @@ jobs:
7880
with:
7981
fetch-depth: 0
8082
ref: ${{ github.sha }}
83+
submodules: true
8184

8285
- name: Checkout commit for release
8386
run: |

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/esphome_glyphsets/glyphsets"]
2+
path = src/esphome_glyphsets/glyphsets
3+
url = https://github.com/googlefonts/glyphsets/

.pre-commit-config.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ repos:
4646
- id: ruff
4747
args: [--fix, --exit-non-zero-on-fix]
4848
- id: ruff-format
49-
- repo: https://github.com/codespell-project/codespell
50-
rev: v2.4.1
51-
hooks:
52-
- id: codespell
5349
- repo: https://github.com/pre-commit/mirrors-mypy
5450
rev: v1.15.0
5551
hooks:

pyproject.toml

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ lint.per-file-ignores."tests/**/*" = [
7272
]
7373
lint.isort.known-first-party = [ "esphome_glyphsets", "tests" ]
7474

75+
[tool.setuptools.packages.find]
76+
where = ["src"]
77+
78+
[tool.setuptools.package-data]
79+
"*" = ["*.yaml", "*.nam"]
80+
7581
[tool.pytest.ini_options]
7682
addopts = """\
7783
-v
@@ -81,6 +87,7 @@ addopts = """\
8187
--cov-report=xml
8288
"""
8389
pythonpath = [ "src" ]
90+
testpaths = "tests/"
8491

8592
[tool.coverage.run]
8693
branch = true

src/esphome_glyphsets/__init__.py

+29
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
11
__version__ = "0.0.1"
2+
3+
import pathlib
4+
5+
FILE_PATH = pathlib.Path(__file__).resolve()
6+
GLYPHSETS_BASE_PATH = FILE_PATH.parent / "glyphsets" / "Lib" / "glyphsets"
7+
GLYPHSETS_DEFINITIONS_PATH = GLYPHSETS_BASE_PATH / "definitions"
8+
GLYPHSETS_NAM_PATH = GLYPHSETS_BASE_PATH / "results" / "nam"
9+
10+
11+
def defined_glyphsets() -> list[str]:
12+
"""Return a list of defined glyphsets."""
13+
return sorted(
14+
f.stem
15+
for f in GLYPHSETS_DEFINITIONS_PATH.iterdir()
16+
if f.is_file() and f.suffix == ".yaml"
17+
)
18+
19+
20+
def unicodes_per_glyphset(glyphset_name: str) -> list[int]:
21+
"""Return a list of unicodes for a given glyphset."""
22+
nam_path = GLYPHSETS_NAM_PATH / f"{glyphset_name}.nam"
23+
if not nam_path.exists():
24+
return []
25+
character_set: set[int] = set()
26+
for line in nam_path.read_text().splitlines():
27+
unicode = line.partition(" ")[0]
28+
if unicode.startswith("0x"):
29+
character_set.add(int(unicode[2:], 16))
30+
return sorted(character_set)

src/esphome_glyphsets/glyphsets

Submodule glyphsets added at 5d04700

src/esphome_glyphsets/main.py

-3
This file was deleted.

tests/test_init.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from esphome_glyphsets import defined_glyphsets, unicodes_per_glyphset
2+
3+
4+
def test_defined_glyphsets() -> None:
5+
"""Test defined_glyphsets."""
6+
assert "GF_Latin_Core" in defined_glyphsets()
7+
8+
9+
def test_unicodes_per_glyphset() -> None:
10+
"""Test unicodes_per_glyphset."""
11+
assert unicodes_per_glyphset("GF_Latin_Core")
12+
assert not unicodes_per_glyphset("GF_Latin_Core_Invalid")

tests/test_main.py

-6
This file was deleted.

0 commit comments

Comments
 (0)