Skip to content

Commit

Permalink
[fontc] Code review and fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr committed Oct 25, 2024
1 parent 890dec9 commit a1ec830
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 9 additions & 7 deletions Lib/gftools/builder/fontc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""functionality for running fontc via gftools
This mostly exists so that we can keep as much of the fontc logic in one place,
and not need to dirty up anything else.
gftools has a few special flags that allow it to use fontc, an alternative
font compiler (https://github.com/googlefonts/fontc).
This module exists to keep the logic related to fontc in one place, and not
dirty up everything else.
"""

from argparse import Namespace
Expand All @@ -12,14 +15,13 @@


class FontcArgs:
simple_output_path: Union[Path, None]
fontc_bin_path: Union[Path, None]
single_source: Union[str, None]

# init with 'None' returns a default obj where everything is None
def __init__(self, args: Union[Namespace, None]) -> None:
if not args:
return None
self.simple_output_path = None
self.fontc_bin_path = None
self.single_source = None
return
self.simple_output_path = abspath(args.experimental_simple_output)
self.fontc_bin_path = abspath(args.experimental_fontc)
self.single_source = args.experimental_single_source
Expand Down
9 changes: 5 additions & 4 deletions Lib/gftools/builder/operations/fontc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
from typing import List
from gftools.builder.operations import OperationBase

FONTC_PATH = "FONTC_PATH_NOT_SET"
_FONTC_PATH = None


# should only be called once, from main, before doing anything else. This is a
# relatively non-invasive way to smuggle this value into FontcOperationBase
def set_global_fontc_path(path: Path):
global FONTC_PATH
FONTC_PATH = path
global _FONTC_PATH
assert _FONTC_PATH is None, "set_global_fontc_path should only be called once"
_FONTC_PATH = path


class FontcOperationBase(OperationBase):
@property
def variables(self):
vars = super().variables
vars["fontc_path"] = FONTC_PATH
vars["fontc_path"] = _FONTC_PATH
args = vars.get("args")
if args:
vars["args"] = rewrite_fontmake_args_for_fontc(args)
Expand Down

0 comments on commit a1ec830

Please sign in to comment.