Skip to content

Commit 6bb366b

Browse files
committed
version bump
2 parents 7c2a259 + 53e093a commit 6bb366b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

fs/osfs.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class OSFS(FS):
9191
create_mode (int): The permissions that will be used to create
9292
the directory if ``create`` is `True` and the path doesn't
9393
exist, defaults to ``0o777``.
94+
expand_vars(bool): If `True` (the default) environment variables of
95+
the form $name or ${name} will be expanded.
9496
9597
Raises:
9698
`fs.errors.CreateFailed`: If ``root_path`` does not
@@ -108,6 +110,7 @@ def __init__(
108110
root_path, # type: Text
109111
create=False, # type: bool
110112
create_mode=0o777, # type: SupportsInt
113+
expand_vars=True, # type: bool
111114
):
112115
# type: (...) -> None
113116
"""Create an OSFS instance.
@@ -118,7 +121,9 @@ def __init__(
118121
self.root_path = root_path
119122
_drive, _root_path = os.path.splitdrive(fsdecode(fspath(root_path)))
120123
_root_path = _drive + (_root_path or "/") if _drive else _root_path
121-
_root_path = os.path.expanduser(os.path.expandvars(_root_path))
124+
_root_path = os.path.expanduser(
125+
os.path.expandvars(_root_path) if expand_vars else _root_path
126+
)
122127
_root_path = os.path.normpath(os.path.abspath(_root_path))
123128
self._root_path = _root_path
124129

tests/test_osfs.py

+10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ def test_not_exists(self):
6969
with self.assertRaises(errors.CreateFailed):
7070
fs = osfs.OSFS("/does/not/exists/")
7171

72+
def test_expand_vars(self):
73+
self.fs.makedir("TYRIONLANISTER")
74+
self.fs.makedir("$FOO")
75+
path = self.fs.getsyspath("$FOO")
76+
os.environ["FOO"] = "TYRIONLANISTER"
77+
fs1 = osfs.OSFS(path)
78+
fs2 = osfs.OSFS(path, expand_vars=False)
79+
self.assertIn("TYRIONLANISTER", fs1.getsyspath("/"))
80+
self.assertNotIn("TYRIONLANISTER", fs2.getsyspath("/"))
81+
7282
@unittest.skipIf(osfs.sendfile is None, "sendfile not supported")
7383
def test_copy_sendfile(self):
7484
# try copying using sendfile

0 commit comments

Comments
 (0)