pytest-dev / py

Python development support library (note: maintenance only)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LocalPath.mkdir: No recursive directory creation when using mkdir

pytestbot opened this issue · comments

https://bitbucket.org/pytest-dev/py/src/4617fe465cfc3289cefb8e7b8ce28ed5168f139f/py/_path/local.py?at=default&fileviewer=file-view-default#local.py-453

When trying to create a recursive directory I have to call to LocalPath.mkdir N times the level of directories I want to create creating intermediate LocalPath instances.

Also I'm lost at what is the use that LocalPath.mkdir will join all the args passed if it can't create recursive directories. (bug?)

Could be good that LocalPath.mkdir internally uses os.makedirs instead or for LocalPath to provide LocalPath.makedirs method.

Thanks

Original comment by @eka

@b-enlnt thanks didn't know about that and it wasn't at all intuitive, but will try it.

Original comment by @sashkab

Why can't you use path.ensure(dir=True) to make whole directory three? At least it works for me.

Example:

path = py.path.local('/tmp/xxx/xxx/zzz/one/doesnt/exist'.ensure(dir=True)

It will create directories required. dir=True will ensure that exists is a directory, not a file.

closing as works as intended - ensure is for recursive, mkdir is for no-surprise fail early on mistakes