diff --git a/datasette/cli.py b/datasette/cli.py index f3455f72..8dbc97c4 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -235,9 +235,16 @@ def package( @cli.command() @click.argument("packages", nargs=-1, required=True) -def install(packages): +@click.option( + "-U", "--upgrade", is_flag=True, help="Upgrade packages to latest version" +) +def install(packages, upgrade): "Install Python packages - e.g. Datasette plugins - into the same environment as Datasette" - sys.argv = ["pip", "install"] + list(packages) + args = ["pip", "install"] + if upgrade: + args += ["--upgrade"] + args += list(packages) + sys.argv = args run_module("pip", run_name="__main__") diff --git a/docs/plugins.rst b/docs/plugins.rst index e67c77b3..1c0dd588 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -43,7 +43,15 @@ You can uninstall plugins with ``datasette uninstall``:: datasette uninstall datasette-vega -These ommands are thin wrappers around ``pip install`` and ``pip uninstall``, which ensure they run ``pip`` in the same virtual environment as Datasette itself. +You can upgrade plugins with ``datasette install --upgrade`` or ``datasette install -U``:: + + datasette install -U datasette-vega + +This command can also be used to upgrade Datasette itself to the latest released version:: + + datasette install -U datasette + +These commands are thin wrappers around ``pip install`` and ``pip uninstall``, which ensure they run ``pip`` in the same virtual environment as Datasette itself. One-off plugins using --plugins-dir ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/test_cli.py b/tests/test_cli.py index 38bb8834..dc5229cd 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -125,6 +125,15 @@ def test_install(run_module): ] +@pytest.mark.parametrize("flag", ["-U", "--upgrade"]) +@mock.patch("datasette.cli.run_module") +def test_install_upgrade(run_module, flag): + runner = CliRunner() + runner.invoke(cli, ["install", flag, "datasette"]) + run_module.assert_called_once_with("pip", run_name="__main__") + assert sys.argv == ["pip", "install", "--upgrade", "datasette"] + + @mock.patch("datasette.cli.run_module") def test_uninstall(run_module): runner = CliRunner()