Skip to content

Commit

Permalink
Makes tempfile and tempdir accept Path as dir
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Nov 6, 2014
1 parent 9b9d9d6 commit ecb2fed
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ def tempfile(cls, suffix='', prefix=None, dir=None, text=False):
"""
if prefix is None:
prefix = tempfile.template
if dir is not None:
# Note that this is not safe on Python 2
# There is no work around, apart from not using the tempfile module
dir = str(Path(dir))
fd, filename = tempfile.mkstemp(suffix, prefix, dir, text)
return fd, cls(filename).absolute()

Expand All @@ -505,6 +509,10 @@ def tempdir(cls, suffix='', prefix=None, dir=None):
"""
if prefix is None:
prefix = tempfile.template
if dir is not None:
# Note that this is not safe on Python 2
# There is no work around, apart from not using the tempfile module
dir = str(Path(dir))
dirname = tempfile.mkdtemp(suffix, prefix, dir)
return cls(dirname).absolute()

Expand Down

0 comments on commit ecb2fed

Please sign in to comment.