From 428b860dc7175966e9bed8aa482ca64003b8175c Mon Sep 17 00:00:00 2001 From: Shawn Davis Date: Sun, 6 Sep 2020 12:18:39 -0400 Subject: [PATCH] Added default Python version `3` to pip command. --- scripttease/library/overlays/common.py | 11 ++++++++--- tests/test_library_overlays_common.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scripttease/library/overlays/common.py b/scripttease/library/overlays/common.py index 677ab03..499f547 100644 --- a/scripttease/library/overlays/common.py +++ b/scripttease/library/overlays/common.py @@ -14,19 +14,24 @@ __all__ = ( # Functions -def python_pip(name, op="install", upgrade=False, venv=None, **kwargs): +def python_pip(name, op="install", upgrade=False, venv=None, version=3, **kwargs): """Use pip to install or uninstall a Python package. - name (str): The name of the package. - op (str): The operation to perform; install, uninstall - upgrade (bool): Upgrade an installed package. - venv (str): The name of the virtual environment to load. + - version (int): The Python version to use, e.g. ``2`` or ``3``. """ + manager = "pip" + if version == 3: + manager = "pip3" + if upgrade: - statement = "pip install --upgrade %s" % name + statement = "%s install --upgrade %s" % (manager, name) else: - statement = "pip %s %s" % (op, name) + statement = "%s %s %s" % (manager, op, name) if venv is not None: kwargs['prefix'] = "source %s/bin/activate" % venv diff --git a/tests/test_library_overlays_common.py b/tests/test_library_overlays_common.py index 3003efe..0d47eed 100644 --- a/tests/test_library_overlays_common.py +++ b/tests/test_library_overlays_common.py @@ -3,7 +3,7 @@ from scripttease.library.overlays.common import * def test_python_pip(): c = python_pip("Pillow") - assert "pip install Pillow" in c.get_statement() + assert "pip3 install Pillow" in c.get_statement() c = python_pip("Pillow", upgrade=True) assert "--upgrade" in c.get_statement()