font-patcher: Allow to run without Fontname* modules

[why]
People might want to use the font-patcher with just the one script file.
The error message does not help them to understand the problem.

[how]
Require the modules only if the user wants to use it (i.e. --makegroups).
Give the expected path in the error message.

We could also download the missing files instead, similar to #741
But that PR did not get any feedback yet, so I do not know if this is
something we want.

Anyhow, the fetching of missing parts should then be unified for both
usecases (i.e. Fontname* and src/glyphs).

And then, there is font-patcher.zip (which needs to be adapted), maybe
that is the way to go.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2022-02-06 15:30:43 +01:00 committed by Fini
parent 20609652ea
commit c3363c8202

View file

@ -36,10 +36,14 @@ except ImportError:
) )
) )
# This is (for experimenting) far far away... # This is for experimenting
sys.path.insert(0, os.path.abspath(os.path.dirname(sys.argv[0])) + '/bin/scripts/name_parser/') sys.path.insert(0, os.path.abspath(os.path.dirname(sys.argv[0])) + '/bin/scripts/name_parser/')
from FontnameParser import FontnameParser try:
from FontnameTools import FontnameTools from FontnameParser import FontnameParser
from FontnameTools import FontnameTools
FontnameParserOK = True
except ImportError:
FontnameParserOK = False
class TableHEADWriter: class TableHEADWriter:
""" Access to the HEAD table without external dependencies """ """ Access to the HEAD table without external dependencies """
@ -334,6 +338,9 @@ class font_patcher:
self.args = parser.parse_args() self.args = parser.parse_args()
if self.args.makegroups and not FontnameParserOK:
sys.exit(projectName + ": FontnameParser module missing (bin/scripts/name_parser/Fontname*), can not --makegroups".format(projectName))
# if you add a new font, set it to True here inside the if condition # if you add a new font, set it to True here inside the if condition
if self.args.complete: if self.args.complete:
self.args.fontawesome = True self.args.fontawesome = True
@ -430,7 +437,7 @@ class font_patcher:
additionalFontNameSuffix += " M" additionalFontNameSuffix += " M"
verboseAdditionalFontNameSuffix += " Mono" verboseAdditionalFontNameSuffix += " Mono"
if self.args.makegroups: if FontnameParserOK and self.args.makegroups:
use_fullname = type(self.sourceFont.fullname) == str # Usually the fullname is better to parse use_fullname = type(self.sourceFont.fullname) == str # Usually the fullname is better to parse
# Use fullname if it is 'equal' to the fontname # Use fullname if it is 'equal' to the fontname
if self.sourceFont.fullname: if self.sourceFont.fullname:
@ -584,7 +591,7 @@ class font_patcher:
fullname = replace_font_name(fullname, additionalFontNameReplacements2) fullname = replace_font_name(fullname, additionalFontNameReplacements2)
fontname = replace_font_name(fontname, additionalFontNameReplacements2) fontname = replace_font_name(fontname, additionalFontNameReplacements2)
if not self.args.makegroups: if not (FontnameParserOK and self.args.makegroups):
# replace any extra whitespace characters: # replace any extra whitespace characters:
self.sourceFont.familyname = " ".join(familyname.split()) self.sourceFont.familyname = " ".join(familyname.split())
self.sourceFont.fullname = " ".join(fullname.split()) self.sourceFont.fullname = " ".join(fullname.split())