Skip to content

Commit 0af3f66

Browse files
authored
Merge branch 'main' into update-name-length-check
2 parents 586756b + d289f33 commit 0af3f66

6 files changed

Lines changed: 35 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Below are the noteworthy changes from each release.
22
A more detailed list of changes is available in the corresponding milestones for each release in the Github issue tracker (https://github.com/googlefonts/fontbakery/milestones?state=closed).
33

4-
## Upcoming release: 1.1.0 (2025-Jul-??)
4+
## Upcoming release: 1.1.0 (2025-Sept-??)
5+
- Replace deprecated `pkg_resources` by `importlib.resources` (issue #5028)
6+
- ...
57

68
### Changes to existing checks
79
### On the Universal profile

Lib/fontbakery/checks/vendorspecific/googlefonts/conditions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ def rfn_exception(font):
307307
been published previously with an RFN, or fonts which benefit from
308308
an agreement with Google Fonts.
309309
"""
310-
from pkg_resources import resource_filename
310+
from fontbakery.utils import get_resource_file_path
311311

312312
rfn_exceptions_txt = "data/googlefonts/reserved_font_name_exceptions.txt"
313-
filename = resource_filename("fontbakery", rfn_exceptions_txt)
313+
filename = get_resource_file_path(rfn_exceptions_txt)
314314
for exception in open(filename, "r", encoding="utf-8").readlines():
315315
exception = exception.split("#")[0].strip()
316316
exception = exception.replace(" ", "")

Lib/fontbakery/checks/vendorspecific/googlefonts/family_name_compliance.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
def check_family_name_compliance(ttFont):
2626
"""Check family name for GF Guide compliance."""
2727
import re
28-
from pkg_resources import resource_filename
29-
from fontbakery.utils import get_name_entries
28+
29+
from fontbakery.utils import get_name_entries, get_resource_file_path
3030

3131
camelcase_exceptions_txt = "data/googlefonts/camelcased_familyname_exceptions.txt"
3232
abbreviations_exceptions_txt = (
@@ -45,7 +45,7 @@ def check_family_name_compliance(ttFont):
4545
known_exception = False
4646

4747
# Process exceptions
48-
filename = resource_filename("fontbakery", camelcase_exceptions_txt)
48+
filename = get_resource_file_path(camelcase_exceptions_txt)
4949
for exception in open(filename, "r", encoding="utf-8").readlines():
5050
exception = exception.split("#")[0].strip()
5151
if exception == "":
@@ -71,7 +71,7 @@ def check_family_name_compliance(ttFont):
7171
known_exception = False
7272

7373
# Process exceptions
74-
filename = resource_filename("fontbakery", abbreviations_exceptions_txt)
74+
filename = get_resource_file_path(abbreviations_exceptions_txt)
7575
for exception in open(filename, "r", encoding="utf-8").readlines():
7676
exception = exception.split("#")[0].strip()
7777
if exception == "":

Lib/fontbakery/checks/vendorspecific/googlefonts/utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import re
22
from functools import lru_cache
3-
from pkg_resources import resource_filename
43

5-
from fontbakery.utils import exit_with_install_instructions
4+
from fontbakery.utils import exit_with_install_instructions, get_resource_file_path
65

76

87
@lru_cache(maxsize=1)
@@ -22,9 +21,7 @@ def registered_vendor_ids():
2221
exit_with_install_instructions("googlefonts")
2322

2423
registered_vendor_ids = {}
25-
CACHED = resource_filename(
26-
"fontbakery", "data/fontbakery-microsoft-vendorlist.cache"
27-
)
24+
CACHED = get_resource_file_path("data/fontbakery-microsoft-vendorlist.cache")
2825
content = open(CACHED, encoding="utf-8").read()
2926
# Strip all <A> HTML tags from the raw HTML. The current page contains a
3027
# closing </A> for which no opening <A> is present, which causes

Lib/fontbakery/utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
from __future__ import annotations
17+
1618
import os
1719
import subprocess
1820
import sys
1921
import traceback
20-
from typing import Optional
2122
from copy import deepcopy
23+
from typing import TYPE_CHECKING, Optional
2224

2325
from fontTools.pens.basePen import BasePen
2426
from fontTools.ttLib import TTFont
@@ -31,6 +33,27 @@
3133
PANOSE_Family_Type,
3234
)
3335

36+
if TYPE_CHECKING:
37+
from pathlib import Path
38+
39+
40+
def get_resource_file_path(sub_file_path: str) -> Path:
41+
"""Return the full file path of a resource file inside the fontbakery
42+
directory.
43+
44+
Args:
45+
sub_file_path (str): The file path relative to the `fontbakery`
46+
directory.
47+
48+
Returns:
49+
Path: The full file path
50+
"""
51+
from importlib.resources import as_file, files
52+
53+
with as_file(files("fontbakery").joinpath(sub_file_path)) as path:
54+
file_path = path
55+
return file_path
56+
3457

3558
def exit_with_install_instructions(profile_name):
3659
sys.exit(

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ exclude = [
209209
minversion = "6.0"
210210
testpaths = ["tests"]
211211
addopts = "--color=yes --verbose"
212-
filterwarnings = [
213-
"ignore:pkg_resources is deprecated as an API:DeprecationWarning",
214-
"ignore:Deprecated call to `pkg_resources.declare_namespace:DeprecationWarning",
215-
]
216212

217213
# ============================================================================
218214
[tool.pylint.master]

0 commit comments

Comments
 (0)