From 49a36f3cb0344497bb0c3b5b8e993a9112d20e22 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Mon, 22 Jul 2019 13:38:56 +0300 Subject: [PATCH] Use subprocess32 only on Python2.7. Since Python3.4 is EOL and Python3.5 has `run` in the `subprocess` module, there's no need for it outside of Python2.7. --- setup.py | 2 +- template/filters.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index d8808e6..69f8e93 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( "PyYAML", "jmespath", "toml", - "subprocess32>=3.5.0", + "subprocess32>=3.5.0;python_version<'3.5'", ], extras_require={"dev": ["pipenv"]}, entry_points={"console_scripts": ["template=template:main"]}, diff --git a/template/filters.py b/template/filters.py index 6d1a9f5..c521885 100644 --- a/template/filters.py +++ b/template/filters.py @@ -157,11 +157,16 @@ def run(*argv, **kwargs): >>> run(['ls', 'foo'])['returncode'] > 0 True """ - import subprocess32 # nosec + import sys - defaults = {"stdout": subprocess32.PIPE, "stderr": subprocess32.PIPE} + if sys.version_info[0] < 3: # nosec + import subprocess32 as subprocess + else: + import subprocess + + defaults = {"stdout": subprocess.PIPE, "stderr": subprocess.PIPE} defaults.update(kwargs) - proc = subprocess32.run(*argv, **defaults).__dict__ + proc = subprocess.run(*argv, **defaults).__dict__ # nosec if "text" not in kwargs or kwargs["text"]: proc["stdout"] = proc["stdout"].decode() proc["stderr"] = proc["stderr"].decode() -- GitLab