Skip to content

Commit 902362d

Browse files
committed
Add some examples showing how to build a TempFS
1 parent 5bc93ef commit 902362d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

fs/tempfs.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,31 @@
2727

2828
@six.python_2_unicode_compatible
2929
class TempFS(OSFS):
30-
"""A temporary filesystem on the OS."""
30+
"""A temporary filesystem on the OS.
31+
32+
Temporary filesystems are created using the `tempfile.mkdtemp`
33+
function to obtain a temporary folder in an OS-specific location.
34+
You can provide an alternative location with the ``temp_dir``
35+
argument of the constructor.
36+
37+
Examples:
38+
Create with the constructor::
39+
40+
>>> from fs.tempfs import TempFS
41+
>>> tmp_fs = TempFS()
42+
43+
Or via an FS URL::
44+
45+
>>> import fs
46+
>>> tmp_fs = fs.open_fs("temp://")
47+
48+
Use a specific identifier for the temporary folder to better
49+
illustrate its purpose::
50+
51+
>>> named_tmp_fs = fs.open_fs("temp://local_copy")
52+
>>> named_tmp_fs = TempFS(identifier="local_copy")
53+
54+
"""
3155

3256
def __init__(
3357
self,
@@ -43,7 +67,7 @@ def __init__(
4367
identifier (str): A string to distinguish the directory within
4468
the OS temp location, used as part of the directory name.
4569
temp_dir (str, optional): An OS path to your temp directory
46-
(leave as `None` to auto-detect)
70+
(leave as `None` to auto-detect).
4771
auto_clean (bool): If `True` (the default), the directory
4872
contents will be wiped on close.
4973
ignore_clean_errors (bool): If `True` (the default), any errors

tests/test_doctest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import importlib
66
import os
77
import pkgutil
8-
import sys
98
import types
109
import warnings
1110
import tempfile
@@ -50,7 +49,7 @@ def _open_fs(path):
5049
if parse_result.path is not None:
5150
home_fs = home_fs.opendir(parse_result.path, factory=ClosingSubFS)
5251
return home_fs
53-
elif parse_result.protocol in {"ftp", "ftps", "mem"}:
52+
elif parse_result.protocol in {"ftp", "ftps", "mem", "temp"}:
5453
return MemoryFS()
5554
else:
5655
raise RuntimeError("not allowed in doctests: {}".format(path))

0 commit comments

Comments
 (0)