Skip to content

Commit

Permalink
fix exit_with_install_instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesanches committed Mar 13, 2024
1 parent 2511d53 commit 3aee94d
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Lib/fontbakery/checks/fontval.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def com_google_fonts_check_fontvalidator(font, config):
try:
import lxml.etree
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("fontval")

check_config = config.get("com.google.fonts/check/fontvalidator", {})
enabled_checks = check_config.get("enabled_checks")
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontbakery/checks/googlefonts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def com_google_fonts_check_canonical_filename(ttFont):
try:
import axisregistry
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

current_filename = os.path.basename(ttFont.reader.file.name)
expected_filename = axisregistry.build_filename(ttFont)
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontbakery/checks/googlefonts/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def family_metadata(font):
try:
from google.protobuf import text_format
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

from fontbakery.utils import get_FamilyProto_Message

Expand Down
4 changes: 2 additions & 2 deletions Lib/fontbakery/checks/googlefonts/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def description_html(font):
try:
from lxml import etree
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

if not font.description:
return
Expand Down Expand Up @@ -295,7 +295,7 @@ def com_google_fonts_check_description_valid_html(descfile, description):
try:
from lxml import html
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

passed = True
if "<html>" in description or "</html>" in description:
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontbakery/checks/googlefonts/glyphset.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def can_shape(ttFont, text, parameters=None):
try:
from vharfbuzz import Vharfbuzz
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

filename = ttFont.reader.file.name
vharfbuzz = Vharfbuzz(filename)
Expand Down
4 changes: 2 additions & 2 deletions Lib/fontbakery/checks/googlefonts/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def com_google_fonts_check_metadata_parses(family_directory):
from google.protobuf import text_format
from fontbakery.utils import get_FamilyProto_Message
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

try:
pb_file = os.path.join(family_directory, "METADATA.pb")
Expand Down Expand Up @@ -1683,7 +1683,7 @@ def com_google_fonts_check_metadata_can_render_samples(ttFont, family_metadata):
try:
from gflanguages import LoadLanguages
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

passed = True
languages = LoadLanguages()
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontbakery/checks/googlefonts/os2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def registered_vendor_ids():
try:
from bs4 import BeautifulSoup, NavigableString
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

registered_vendor_ids = {}
CACHED = resource_filename(
Expand Down
4 changes: 2 additions & 2 deletions Lib/fontbakery/checks/googlefonts/subsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def com_google_fonts_check_metadata_unsupported_subsets(
try:
from gfsubsets import CodepointsInSubset, ListSubsets
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

passed = True
for subset in family_metadata.subsets:
Expand Down Expand Up @@ -78,7 +78,7 @@ def com_google_fonts_check_metadata_unreachable_subsetting(font, config):
import unicodedata2
from gfsubsets import CodepointsInSubset, ListSubsets, SubsetsInFont
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

from fontbakery.utils import pretty_print_list

Expand Down
4 changes: 2 additions & 2 deletions Lib/fontbakery/checks/googlefonts/varfont.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def uharfbuzz_blob(font):
try:
import uharfbuzz as hb
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

return hb.Blob.from_file_path(font.file)

Expand All @@ -635,7 +635,7 @@ def com_google_fonts_check_slant_direction(ttFont, uharfbuzz_blob):
try:
import uharfbuzz as hb
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

from fontbakery.utils import PointsPen, axis

Expand Down
2 changes: 1 addition & 1 deletion Lib/fontbakery/checks/iso15008.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def pair_kerning(font, left, right):
try:
import uharfbuzz as hb
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("iso15008")

with open(font.file, "rb") as fontfile:
fontdata = fontfile.read()
Expand Down
10 changes: 5 additions & 5 deletions Lib/fontbakery/checks/shaping.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def run_a_set_of_shaping_tests(
filename = Path(ttFont.reader.file.name)
vharfbuzz = Vharfbuzz(filename)
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("shaping")

shaping_file_found = False
ran_a_test = False
Expand Down Expand Up @@ -368,7 +368,7 @@ def setup_glyph_collides(ttFont, configuration):
try:
from collidoscope import Collidoscope
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("shaping")

filename = Path(ttFont.reader.file.name)
collidoscope_configuration = configuration.get("collidoscope")
Expand All @@ -393,7 +393,7 @@ def run_collides_glyph_test(
try:
from stringbrewer import StringBrewer
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("shaping")

col = extra_data["collidoscope"]
is_stringbrewer = (
Expand Down Expand Up @@ -448,7 +448,7 @@ def is_complex_shaper_font(ttFont):
try:
from ufo2ft.constants import INDIC_SCRIPTS, USE_SCRIPTS
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("shaping")

for table in ["GSUB", "GPOS"]:
if table not in ttFont:
Expand Down Expand Up @@ -576,7 +576,7 @@ def com_google_fonts_check_soft_dotted(ttFont):
try:
from vharfbuzz import Vharfbuzz
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("shaping")

import itertools
from beziers.path import BezierPath
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontbakery/checks/typenetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def com_typenetwork_glyph_coverage(ttFont, font_codepoints, config):
try:
import unicodedata2
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("typenetwork")

TN_latin_set = {
0x0020: (" ", "SPACE"),
Expand Down
6 changes: 3 additions & 3 deletions Lib/fontbakery/checks/ufo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def ufo_font(ufo):
from fontTools.ufoLib.errors import UFOLibError
import defcon
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("ufo-sources")

try:
return defcon.Font(ufo.file)
Expand All @@ -40,7 +40,7 @@ def designSpace(designspace):
from fontTools.designspaceLib import DesignSpaceDocument
import defcon
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("ufo-sources")

if designspace:
DS = DesignSpaceDocument.fromfile(designspace.file)
Expand All @@ -57,7 +57,7 @@ def designspace_sources(designspace):
try:
import defcon
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("ufo-sources")

if designspace.designSpace:
return designspace.designSpace.loadSourceFonts(defcon.Font)
Expand Down
15 changes: 4 additions & 11 deletions Lib/fontbakery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,8 @@

from fontbakery.constants import NO_COLORS_THEME, DARK_THEME, LIGHT_THEME

profile_name = None


def set_profile_name(name):
global profile_name # pylint:disable=W0603 (global-statement)
profile_name = name


def exit_with_install_instructions():
def exit_with_install_instructions(profile_name):
sys.exit(
f"\nTo run the {profile_name} profile, one needs to install\n"
f"fontbakery with the '{profile_name}' extra, like this:\n\n"
Expand Down Expand Up @@ -311,7 +304,7 @@ def get_Protobuf_Message(klass, path):
try:
from google.protobuf import text_format
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

message = klass()
text_data = open(path, "rb").read()
Expand All @@ -323,7 +316,7 @@ def get_FamilyProto_Message(path):
try:
from fontbakery.fonts_public_pb2 import FamilyProto
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

return get_Protobuf_Message(FamilyProto, path)

Expand All @@ -333,7 +326,7 @@ def get_DesignerInfoProto_Message(text_data):
from fontbakery.designers_pb2 import DesignerInfoProto
from google.protobuf import text_format
except ImportError:
exit_with_install_instructions()
exit_with_install_instructions("googlefonts")

message = DesignerInfoProto()
text_format.Merge(text_data, message)
Expand Down
5 changes: 1 addition & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@


def test_exit_with_install_instructions():
from fontbakery.utils import set_profile_name

profile_name = "test-profile"
set_profile_name(profile_name)
with patch("sys.exit") as mock_exit:
exit_with_install_instructions()
exit_with_install_instructions(profile_name)
mock_exit.assert_called_with(
f"\nTo run the {profile_name} profile, one needs to install\n"
f"fontbakery with the '{profile_name}' extra, like this:\n\n"
Expand Down

0 comments on commit 3aee94d

Please sign in to comment.