Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-font -- failing with OSError: [Errno 20] No such directory: u'encodings/' #89

Closed
eliheuer opened this issue Oct 18, 2018 · 6 comments · Fixed by #103
Closed

add-font -- failing with OSError: [Errno 20] No such directory: u'encodings/' #89

eliheuer opened this issue Oct 18, 2018 · 6 comments · Fixed by #103
Assignees
Labels

Comments

@eliheuer
Copy link
Contributor

This might just be a documentation issue or i'm missing something obvious, but I'm getting this error when trying to use add-font.py:

(Python2) 🐍
eli ~/Google/fonts -> ef708bbf|staatliches✓
gftools add-font ofl/staatliches                                                                        [12h29m]

Traceback (most recent call last):
  File "/Users/Air/Py/Source/gftools/bin/gftools-add-font.py", line 267, in <module>
    app.run()
  File "/Users/Air/Py/Venvs/Python2/lib/python2.7/site-packages/google/apputils/app.py", line 238, in run
    return _actual_start()
  File "/Users/Air/Py/Venvs/Python2/lib/python2.7/site-packages/google/apputils/app.py", line 267, in _actual_start
    really_start()
  File "/Users/Air/Py/Venvs/Python2/lib/python2.7/site-packages/google/apputils/app.py", line 220, in really_start
    sys.exit(main(argv))
  File "/Users/Air/Py/Source/gftools/bin/gftools-add-font.py", line 253, in main
    metadata = _MakeMetadata(fontdir, is_new)
  File "/Users/Air/Py/Source/gftools/bin/gftools-add-font.py", line 119, in _MakeMetadata
    FLAGS.min_pct_ext)]
  File "/Users/Air/Py/Source/gftools/Lib/gftools/util/google_fonts.py", line 397, in SubsetsInFont
    subset_cps = CodepointsInSubset(subset, unique_glyphs=True)
  File "/Users/Air/Py/Source/gftools/Lib/gftools/util/google_fonts.py", line 286, in CodepointsInSubset
    filenames = [CodepointFileForSubset(subset)]
  File "/Users/Air/Py/Source/gftools/Lib/gftools/util/google_fonts.py", line 341, in CodepointFileForSubset
    raise OSError(errno.ENOTDIR, 'No such directory', enc_path)
OSError: [Errno 20] No such directory: u'encodings/'
@felipesanches
Copy link
Member

it relies on having access to the nam files from the encodings directory on the project repo. I think this is a python packaging bug. Those files should be installed as resources and then the code should be updated to get them from the pip-installed resources instead of looking for it on the current working directory.

@felipesanches
Copy link
Member

These are the files it is looking or:
https://github.com/googlefonts/gftools/tree/master/encodings

@felipesanches
Copy link
Member

This is where the default path for the files is declared:
https://github.com/googlefonts/gftools/blob/master/Lib/gftools/util/google_fonts.py#L55-L56

The flag to let the user change it might be useful in some cases, but the most common usage is certainly having a default value here. And this default is definitely wrong since it is a relative path that would only work when running the script from the git repo root dir.

@felipesanches
Copy link
Member

And here is where you get the crash because of that:

https://github.com/googlefonts/gftools/blob/master/Lib/gftools/util/google_fonts.py#L324-L349

@thundernixon
Copy link
Contributor

If anyone else comes across this while the problem still exists, here's how I was able to (partially) use this script:

  1. Change line 55 of google_fonts.py, based on @felipesanches's comment above. I put in the exact path of that folder on my system, so for me, line 55 becomes: flags.DEFINE_string('nam_dir', '/Users/stephennixon/Environments/gfonts3/lib/python3.6/site-packages/gftools/encodings/', 'nam file dir')
  2. The script also tries to determine the license based on the parent directory of the font directory pointed to. So, that means I was able to:
    A. Run the script from google/fonts on ofl/librecaslontext, or
    B. Change my repo font directory name to ofl, and run the tool from the base of the Libre Caslon repo

It doesn't work perfectly (at least not yet), because it doesn't fill in info for all fields, even though other files are in place in the repo. For example, I get the result designer: "UNKNOWN", even though the repo has CONTRIBUTORS.txt and AUTHORS.txt. Still, it does save some typing and guesswork in trying to write my own from scratch.

@m4rc1e
Copy link
Collaborator

m4rc1e commented Dec 13, 2018

If you run add-font.py from the repo's parent dir, it will work. This is simply a path issue.

Can't we move the encodings dir into the Lib dir so we can form an absolute path more easily?

I can happily make a quick pr for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants