Skip to content

Commit c968ab1

Browse files
authored
Replace pkg_resources with __file__/glob combination (#458)
1 parent b8026b5 commit c968ab1

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

ev3dev2/fonts/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import pkg_resources
21
import os.path
2+
from glob import glob
33
from PIL import ImageFont
44

55
def available():
66
"""
77
Returns list of available font names.
88
"""
9-
names = []
10-
for f in pkg_resources.resource_listdir('ev3dev.fonts', ''):
11-
name, ext = os.path.splitext(os.path.basename(f))
12-
if ext == '.pil':
13-
names.append(name)
9+
font_dir = os.path.dirname(__file__)
10+
names = [os.path.basename(os.path.splitext(f)[0])
11+
for f in glob(os.path.join(font_dir, '*.pil'))]
1412
return sorted(names)
1513

1614
def load(name):
@@ -20,8 +18,9 @@ def load(name):
2018
class.
2119
"""
2220
try:
23-
pil_file = pkg_resources.resource_filename('ev3dev.fonts', '{}.pil'.format(name))
24-
pbm_file = pkg_resources.resource_filename('ev3dev.fonts', '{}.pbm'.format(name))
21+
font_dir = os.path.dirname(__file__)
22+
pil_file = os.path.join(font_dir, '{}.pil'.format(name))
23+
pbm_file = os.path.join(font_dir, '{}.pbm'.format(name))
2524
return ImageFont.load(pil_file)
2625
except FileNotFoundError:
2726
raise Exception('Failed to load font "{}". '.format(name) +

0 commit comments

Comments
 (0)