Skip to content

Commit

Permalink
Merge branch 'master' into pipe-to-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
koreno committed Aug 1, 2019
2 parents ed93823 + 6d29382 commit eba972d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Unreleased
-----
* Commands: support for per-line timeout with iter_lines (`#454 <https://github.com/tomerfiliba/plumbum/pull/454>`_)
* Commands: support for piping stdout/stderr to a logger (`#454 <https://github.com/tomerfiliba/plumbum/pull/454>`_)
* Paths: support composing paths using subscription operations (`#455 <https://github.com/tomerfiliba/plumbum/pull/455>`_)
* CLI: Improved 'Set' validator to allow non-string types, and CSV params (`#452 <https://github.com/tomerfiliba/plumbum/pull/452>`_)
* TypedEnv: Facility for modeling environment-variables into python data types (`#451 <https://github.com/tomerfiliba/plumbum/pull/450>`_)
* Commands: execute local/remote commands via a magic `.cmd` attribute (`#450 <https://github.com/tomerfiliba/plumbum/pull/450>`_)
Expand Down
8 changes: 6 additions & 2 deletions docs/paths.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ with a few improvements and extra features.
Paths now support more pathlib like syntax, several old names have been depreciated, like ``.basename``

The primary ways to create paths are from ``.cwd``, ``.env.home``, or ``.path(...)`` on a local
or remote machine, with ``/`` or ``//`` for composition.
or remote machine, with ``/``, ``//`` or ``[]`` for composition.

.. note::

Expand All @@ -43,14 +43,18 @@ Note that a name like ``file.name.10.15.tar.gz`` will have "5" suffixes.
Also available is ``.with_name(name)``, which will will replace the entire name.
``preferred_suffix(suffix)`` will add a suffix if one does not exist (for default suffix situations).

Paths can be composed using ``/``::
Paths can be composed using ``/`` or ``[]``::

>>> p / "notepad.exe"
<LocalPath c:\windows\notepad.exe>
>>> (p / "notepad.exe").is_file()
True
>>> (p / "notepad.exe").with_suffix(".dll")
<LocalPath c:\windows\notepad.dll>
>>> p["notepad.exe"].is_file()
True
>>> p["../some/path"]["notepad.exe"].with_suffix(".dll")
<LocalPath c:\windows\notepad.dll>


You can also iterate over directories to get the contents::
Expand Down
1 change: 1 addition & 0 deletions plumbum/path/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __div__(self, other):
return self.join(other)

__truediv__ = __div__
__getitem__ = __div__

def __floordiv__(self, expr):
"""Returns a (possibly empty) list of paths that matched the glob-pattern under this path"""
Expand Down
1 change: 1 addition & 0 deletions plumbum/path/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __new__(cls, remote, *parts):
windows = (remote.uname.lower() == "windows")
normed = []

parts = tuple(map(str, parts)) # force the paths into string, so subscription works properly
# Simple skip if path is absolute
if parts[0] and parts[0][0] not in ("/", "\\"):
cwd = (remote._cwd if hasattr(remote, '_cwd') else
Expand Down
22 changes: 12 additions & 10 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def test_iterdir(self):
files = list(cwd.iterdir())
assert cwd / 'test_local.py' in files
assert cwd / 'test_remote.py' in files
assert cwd['test_local.py'] in files
assert cwd['test_remote.py'] in files

def test_stem(self):
assert self.longpath.stem == "file"
Expand Down Expand Up @@ -228,18 +230,18 @@ def test_path_dir(self):
def test_mkdir(self):
# (identical to test_remote.TestRemotePath.test_mkdir)
with local.tempdir() as tmp:
(tmp / "a").mkdir(exist_ok=False, parents=False)
assert (tmp / "a").exists()
assert (tmp / "a").is_dir()
(tmp / "a").mkdir(exist_ok=True, parents=False)
(tmp / "a").mkdir(exist_ok=True, parents=True)
tmp["a"].mkdir(exist_ok=False, parents=False)
assert tmp["a"].exists()
assert tmp["a"].is_dir()
tmp["a"].mkdir(exist_ok=True, parents=False)
tmp["a"].mkdir(exist_ok=True, parents=True)
with pytest.raises(OSError):
(tmp / "a").mkdir(exist_ok=False, parents=False)
tmp["a"].mkdir(exist_ok=False, parents=False)
with pytest.raises(OSError):
(tmp / "a").mkdir(exist_ok=False, parents=True)
(tmp / "b" / "bb").mkdir(exist_ok=False, parents=True)
assert (tmp / "b" / "bb").exists()
assert (tmp / "b" / "bb").is_dir()
tmp["a"].mkdir(exist_ok=False, parents=True)
tmp["b"]["bb"].mkdir(exist_ok=False, parents=True)
assert tmp["b"]["bb"].exists()
assert tmp["b"]["bb"].is_dir()
assert not tmp.exists()

def test_mkdir_mode(self):
Expand Down

0 comments on commit eba972d

Please sign in to comment.