From 0eb15d0e58963ee2ad3aa1538d150ce1bb09e7c6 Mon Sep 17 00:00:00 2001 From: doronz88 Date: Tue, 13 Dec 2022 23:16:43 +0200 Subject: [PATCH] feat: accept path-like (`pathlib.Path`) objects (#627) * .gitignore: add .idea * local: accept path-like (`pathlib.Path`) objects * chore: flake8 & ci fix Signed-off-by: Henry Schreiner Signed-off-by: Henry Schreiner Co-authored-by: Henry Schreiner --- .github/workflows/ci.yml | 5 +++++ .gitignore | 3 +++ plumbum/machines/local.py | 2 ++ setup.cfg | 4 ++-- tests/test_local.py | 5 +++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d71d88b13..238ba7204 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/.gitignore b/.gitignore index 2226fef86..5b7c904ff 100644 --- a/.gitignore +++ b/.gitignore @@ -164,3 +164,6 @@ cython_debug/ /tests/nohup.out /plumbum/version.py + +# jetbrains +.idea diff --git a/plumbum/machines/local.py b/plumbum/machines/local.py index 5f1630c90..f421bb6b3 100644 --- a/plumbum/machines/local.py +++ b/plumbum/machines/local.py @@ -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)) diff --git a/setup.cfg b/setup.cfg index 53f0dde89..e1bc49d47 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/tests/test_local.py b/tests/test_local.py index 932ab85b7..290fb4b86 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -3,6 +3,7 @@ import signal import sys import time +from pathlib import Path import pytest @@ -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"))