Skip to content
This repository has been archived by the owner on Jan 28, 2019. It is now read-only.

Non-existing parent directories are implicitly created #60

Open
justvanrossum opened this issue Feb 17, 2017 · 7 comments
Open

Non-existing parent directories are implicitly created #60

justvanrossum opened this issue Feb 17, 2017 · 7 comments

Comments

@justvanrossum
Copy link
Contributor

justvanrossum commented Feb 17, 2017

Non-existing parent directories are implicitly created:

from ufoLib import UFOWriter
import os

p = os.path.expanduser(u"~/Desktop/deeper/and/Deeper/test.ufo")
w = UFOWriter(p)

The deeper/and/Deeper directories are created if they didn't already exist.
This may have been intentional, but I don't think it's good design: a simple typo in a script could silently behave a lot different than intended. A "No such directory" exception would be better.

Btw., this behavior trickles down all the way to the RoboFont scripting level, via defcon :)
Cc @typemytype

@anthrotype
Copy link
Member

anthrotype commented Feb 18, 2017

We should use os.mkdir instead of os.makedirs, at least to create the UFO root directory.
https://docs.python.org/3/library/os.html#os.makedirs

@typesupply
Copy link
Contributor

This was not intentional. It should be changed.

@anthrotype
Copy link
Member

this is fixed in master

dirName = os.path.dirname(path)
if dirName and not os.path.isdir(dirName):
raise UFOLibError(
"Cannot write to '%s': directory does not exist" % path
)

@anthrotype
Copy link
Member

lots of defcon-based tools relied on this behaviour that the output directories where automatically created when missing (MutatorMath for one)
https://travis-ci.org/adobe-type-tools/afdko/jobs/440211784#L2121

I know that raising an error is the correct thing to do for ufoLib when asked to write a UFO to a directory which does not exist yet (as it might have been a mistake), but still..

@anthrotype
Copy link
Member

so what should a tool like MutatorMath do when a designspace contains instances' filenames whose directories don't exist?
Should it let ufoLib raise its error "no such directory" and force the user do a preemptive mkdir -p somewhere/over/the/rainbow?

anthrotype added a commit to googlefonts/fontmake that referenced this issue Oct 11, 2018
@miguelsousa
Copy link
Member

force the user do a preemptive mkdir -p somewhere/over/the/rainbow

Does that mean that the user would have to preemptively create each parent directory of each instance? That's a lot extra setup for projects that do not generate all the instances to the same parent directory. I understand releasing ufoLib from that responsibility, but the tools should take over the burden, not the user.

@anthrotype anthrotype reopened this Oct 11, 2018
@anthrotype
Copy link
Member

a simple typo in a script could silently behave a lot different than intended.

similarly, a typo in a designspace file could silently behave a lot different than intended

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

No branches or pull requests

4 participants