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()