Skip to content

Commit

Permalink
feat: accept path-like (pathlib.Path) objects (#627)
Browse files Browse the repository at this point in the history
* .gitignore: add .idea

* local: accept path-like (`pathlib.Path`) objects

* chore: flake8 & ci fix

Signed-off-by: Henry Schreiner <[email protected]>

Signed-off-by: Henry Schreiner <[email protected]>
Co-authored-by: Henry Schreiner <[email protected]>
  • Loading branch information
doronz88 and henryiii authored Dec 13, 2022
1 parent a89f381 commit 0eb15d0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
os: ubuntu-latest
- python-version: 'pypy-3.9'
os: ubuntu-latest
- python-version: '3.6'
os: ubuntu-20.04
exclude:
- python-version: '3.6'
os: ubuntu-latest
runs-on: ${{ matrix.os }}

steps:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ cython_debug/

/tests/nohup.out
/plumbum/version.py

# jetbrains
.idea
2 changes: 2 additions & 0 deletions plumbum/machines/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def __getitem__(self, cmd):
return LocalCommand(cmd)

if not isinstance(cmd, RemotePath):
# handle "path-like" (pathlib.Path) objects
cmd = os.fspath(cmd)
if "/" in cmd or "\\" in cmd:
# assume path
return LocalCommand(local.path(cmd))
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ exclude_lines =

[flake8]
max-complexity = 50
extend-ignore = E203, E501, B950, T202
extend-select = B9
extend-ignore = E203, E501, T202
extend-select = B902, B903, B904
per-file-ignores =
tests/*: T
examples/*: T
Expand Down
5 changes: 5 additions & 0 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import signal
import sys
import time
from pathlib import Path

import pytest

Expand Down Expand Up @@ -329,6 +330,10 @@ def test_imports(self):

assert non_exist1N9

def test_pathlib(self):
ls_path = Path(local.which("ls"))
assert "test_local.py" in local[ls_path]().splitlines()

def test_get(self):
assert str(local["ls"]) == str(local.get("ls"))
assert str(local["ls"]) == str(local.get("non_exist1N9", "ls"))
Expand Down

0 comments on commit 0eb15d0

Please sign in to comment.