From 1c69bd8d67846a906717bbe1d71528db3465a77d Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Sun, 28 Apr 2024 15:04:35 +0200 Subject: [PATCH] Also return True if the default source is the only one containing features. This allows us to use variable features more easily by putting them in the default UFO only. --- Lib/ufo2ft/featureCompiler.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Lib/ufo2ft/featureCompiler.py b/Lib/ufo2ft/featureCompiler.py index e1c6bc98..3e0d992e 100644 --- a/Lib/ufo2ft/featureCompiler.py +++ b/Lib/ufo2ft/featureCompiler.py @@ -446,7 +446,8 @@ def setupFeatures(self): def _featuresCompatible(designSpaceDoc: DesignSpaceDocument) -> bool: - """Returns whether the features of the individual source UFOs are the same. + """Returns True when the features of the individual source UFOs are the same, + or when only the default source has features. NOTE: Only compares the feature file text inside the source UFO and does not follow imports. This will suffice as long as no external feature file is @@ -463,5 +464,13 @@ def transform(f: SourceDescriptor) -> str: text = re.sub(r"\s+", " ", text) return text - first = transform(designSpaceDoc.sources[0]) - return all(transform(s) == first for s in designSpaceDoc.sources[1:]) + sources = sorted( + designSpaceDoc.sources, key=lambda source: source != designSpaceDoc.default + ) + assert sources[0] == designSpaceDoc.default + + transformed = [transform(s) for s in designSpaceDoc.sources] + first = transformed[0] + return all(s == first for s in transformed[1:]) or all( + not s for s in transformed[1:] + )