You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We could probably get rid of pkg_resources by using __file__ variable inside ev3dev.fonts.__init__ to get the path to the fonts directory. Then we could just use glob.glob() as a replacement for package_listdir, and os.path.join() for package_filename.
#!/usr/bin/env python3
from pkg_resources import package_listdir, package_filename
and after 48s (39s adjusted for download etc time) I got ImportError: cannot import name 'package_listdir'
I also tried
#!/usr/bin/env python3
from pkg_resources import resource_listdir, resource_filename
and that completed in about 50s, so no time saved.
I believe the font files we are talking about are at usr\lib\python3\dist-packages\ev3dev\fonts. That folder contains 402 items (1.34MB), of which 200 .pbm files and 200 .pil files. It also contains a file _int_.py which begins:
import pkg_resources
import os.path
from PIL import ImageFont
def available():
"""
Returns list of available font names.
"""
names = []
for f in pkg_resources.resource_listdir('ev3dev.fonts', ''):
name, ext = os.path.splitext(os.path.basename(f))
if ext == '.pil':
names.append(name)
return sorted(names)
Is that available() function relevant or useful?
If there is no other way of speeding up the loading of file names then maybe one solution would be to split the fonts into multiple folders so that only one small folder then has to have its file names loaded? Or maybe we don't need 200 different fonts? Or maybe we don't need both the .pil and the .pbm files?
pkg_resources is used to get file names for the font files packaged with ev3dev.
If I'm running import ev3dev.fonts as fonts it is because I intend to use a specific font. If I know the file name and location then why should I have to wait 40s for import pkg_resources to get file names? I could supply this information in a line of code if necessary, saving 40s of waiting. I believe the files are located in this directory usr\lib\python3\dist-packages\ev3dev\fonts and I believe the extensions for the filenames are .pbm and .pil (I don't know which format is needed – perhaps both?)
Activity
ddemidov commentedon Apr 16, 2018
We could probably get rid of
pkg_resourcesby using__file__variable insideev3dev.fonts.__init__to get the path to the fonts directory. Then we could just useglob.glob()as a replacement forpackage_listdir, andos.path.join()forpackage_filename.ndward commentedon Apr 16, 2018
40s just to load some file names. Wow. I tried
and after 48s (39s adjusted for download etc time) I got
ImportError: cannot import name 'package_listdir'I also tried
and that completed in about 50s, so no time saved.
I believe the font files we are talking about are at usr\lib\python3\dist-packages\ev3dev\fonts. That folder contains 402 items (1.34MB), of which 200 .pbm files and 200 .pil files. It also contains a file
_int_.pywhich begins:Is that available() function relevant or useful?
If there is no other way of speeding up the loading of file names then maybe one solution would be to split the fonts into multiple folders so that only one small folder then has to have its file names loaded? Or maybe we don't need 200 different fonts? Or maybe we don't need both the .pil and the .pbm files?
ndward commentedon Apr 20, 2018
Using Stretch, it seems to take about 45s for this command to run
import ev3dev.fonts as fonts@ddemidov says that this command does not import any fonts but does this instead:
I have added comments above to indicate how long each import seems to take. The only import that takes a long time is
import pkg_resources #40s@ddemidov says
If I'm running import
ev3dev.fonts as fontsit is because I intend to use a specific font. If I know the file name and location then why should I have to wait 40s for import pkg_resources to get file names? I could supply this information in a line of code if necessary, saving 40s of waiting. I believe the files are located in this directory usr\lib\python3\dist-packages\ev3dev\fonts and I believe the extensions for the filenames are .pbm and .pil (I don't know which format is needed – perhaps both?)ddemidov commentedon Apr 22, 2018
#458 should help, but needs testing.
ensonic commentedon Apr 26, 2018
@ndward how did you measure the import times? tool or stopwatch?
ndward commentedon Apr 26, 2018
ddemidov commentedon Apr 30, 2018
Fixed by #458