Added default Python version `3` to pip command.

development
Shawn Davis 4 years ago
parent 81eef60e64
commit 428b860dc7
  1. 11
      scripttease/library/overlays/common.py
  2. 2
      tests/test_library_overlays_common.py

@ -14,19 +14,24 @@ __all__ = (
# Functions # 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. """Use pip to install or uninstall a Python package.
- name (str): The name of the package. - name (str): The name of the package.
- op (str): The operation to perform; install, uninstall - op (str): The operation to perform; install, uninstall
- upgrade (bool): Upgrade an installed package. - upgrade (bool): Upgrade an installed package.
- venv (str): The name of the virtual environment to load. - 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: if upgrade:
statement = "pip install --upgrade %s" % name statement = "%s install --upgrade %s" % (manager, name)
else: else:
statement = "pip %s %s" % (op, name) statement = "%s %s %s" % (manager, op, name)
if venv is not None: if venv is not None:
kwargs['prefix'] = "source %s/bin/activate" % venv kwargs['prefix'] = "source %s/bin/activate" % venv

@ -3,7 +3,7 @@ from scripttease.library.overlays.common import *
def test_python_pip(): def test_python_pip():
c = python_pip("Pillow") 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) c = python_pip("Pillow", upgrade=True)
assert "--upgrade" in c.get_statement() assert "--upgrade" in c.get_statement()

Loading…
Cancel
Save