Skip to content

Commit

Permalink
Restore env var even if exception occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed Mar 16, 2022
1 parent d0de0e2 commit 1c887c9
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions Lib/ufo2ft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,22 +539,25 @@ def compileVariableTTF(designSpaceDoc, **kwargs):
excludeVariationTables = kwargs.pop("excludeVariationTables")
optimizeGvar = kwargs.pop("optimizeGvar")

# Disable GPOS compaction while building masters because the compaction
# will be undone anyway by varLib merge and then done again on the VF
# FIXME: Hack until we get a fontTools config module. Disable GPOS
# compaction while building masters because the compaction will be undone
# anyway by varLib merge and then done again on the VF
gpos_compact_value = os.environ.pop(GPOS_COMPACT_MODE_ENV_KEY, None)
ttfDesignSpace = compileInterpolatableTTFsFromDS(
designSpaceDoc,
**{
**kwargs,
**dict(
useProductionNames=False, # will rename glyphs after varfont is built
# No need to post-process intermediate fonts.
postProcessorClass=None,
),
},
)
if gpos_compact_value is not None:
os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value
try:
ttfDesignSpace = compileInterpolatableTTFsFromDS(
designSpaceDoc,
**{
**kwargs,
**dict(
useProductionNames=False, # will rename glyphs after varfont is built
# No need to post-process intermediate fonts.
postProcessorClass=None,
),
},
)
finally:
if gpos_compact_value is not None:
os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value

logger.info("Building variable TTF font")

Expand Down Expand Up @@ -603,22 +606,25 @@ def compileVariableCFF2(designSpaceDoc, **kwargs):

excludeVariationTables = kwargs.pop("excludeVariationTables")

# Disable GPOS compaction while building masters because the compaction
# will be undone anyway by varLib merge and then done again on the VF
# FIXME: Hack until we get a fontTools config module. Disable GPOS
# compaction while building masters because the compaction will be undone
# anyway by varLib merge and then done again on the VF
gpos_compact_value = os.environ.pop(GPOS_COMPACT_MODE_ENV_KEY, None)
otfDesignSpace = compileInterpolatableOTFsFromDS(
designSpaceDoc,
**{
**kwargs,
**dict(
useProductionNames=False, # will rename glyphs after varfont is built
# No need to post-process intermediate fonts.
postProcessorClass=None,
),
},
)
if gpos_compact_value is not None:
os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value
try:
otfDesignSpace = compileInterpolatableOTFsFromDS(
designSpaceDoc,
**{
**kwargs,
**dict(
useProductionNames=False, # will rename glyphs after varfont is built
# No need to post-process intermediate fonts.
postProcessorClass=None,
),
},
)
finally:
if gpos_compact_value is not None:
os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value

logger.info("Building variable CFF2 font")

Expand Down

0 comments on commit 1c887c9

Please sign in to comment.