Skip to content

Commit 8524703

Browse files
committed
install and uninstall commands, closes #483
1 parent 0b315d3 commit 8524703

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

docs/cli-reference.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ This page lists the ``--help`` for every ``sqlite-utils`` CLI sub-command.
5959
"convert": "cli_convert",
6060
"add-geometry-column": "cli_spatialite",
6161
"create-spatial-index": "cli_spatialite_indexes",
62+
"install": "cli_install",
63+
"uninstall": "cli_uninstall",
6264
}
6365
commands.sort(key = lambda command: go_first.index(command) if command in go_first else 999)
6466
cog.out("\n")
@@ -1349,6 +1351,42 @@ See :ref:`cli_drop_view`.
13491351
-h, --help Show this message and exit.
13501352

13511353

1354+
.. _cli_ref_install:
1355+
1356+
install
1357+
=======
1358+
1359+
See :ref:`cli_install`.
1360+
1361+
::
1362+
1363+
Usage: sqlite-utils install [OPTIONS] PACKAGES...
1364+
1365+
Install packages from PyPI into the same environment as sqlite-utils
1366+
1367+
Options:
1368+
-U, --upgrade Upgrade packages to latest version
1369+
-h, --help Show this message and exit.
1370+
1371+
1372+
.. _cli_ref_uninstall:
1373+
1374+
uninstall
1375+
=========
1376+
1377+
See :ref:`cli_uninstall`.
1378+
1379+
::
1380+
1381+
Usage: sqlite-utils uninstall [OPTIONS] PACKAGES...
1382+
1383+
Uninstall Python packages from the sqlite-utils environment
1384+
1385+
Options:
1386+
-y, --yes Don't ask for confirmation
1387+
-h, --help Show this message and exit.
1388+
1389+
13521390
.. _cli_ref_add_geometry_column:
13531391

13541392
add-geometry-column

docs/cli.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,3 +2116,29 @@ Once you have a geometry column, you can speed up bounding box queries by adding
21162116
$ sqlite-utils create-spatial-index spatial.db locations geometry
21172117

21182118
See this `SpatiaLite Cookbook recipe <http://www.gaia-gis.it/gaia-sins/spatialite-cookbook-5/cookbook_topics.03.html#topic_Wonderful_RTree_Spatial_Index>`__ for examples of how to use a spatial index.
2119+
2120+
.. _cli_install:
2121+
2122+
Installing packages
2123+
-------------------
2124+
2125+
The :ref:`insert -\\-convert <cli_insert_convert>` and :ref:`query -\\-functions <cli_query_functions>` options can be provided with a Python script that imports additional modules from the ``sqlite-utils`` environment.
2126+
2127+
You can install packages from PyPI directly into the correct environment using ``sqlite-utils install <package>``. This is a wrapper around ``pip install``.
2128+
2129+
::
2130+
2131+
$ sqlite-utils install beautifulsoup4
2132+
2133+
Use ``-U`` to upgrade an existing package.
2134+
2135+
.. _cli_uninstall:
2136+
2137+
Uninstalling packages
2138+
---------------------
2139+
2140+
You can uninstall packages that were installed using ``sqlite-utils install`` with ``sqlite-utils uninstall <package>``::
2141+
2142+
$ sqlite-utils uninstall beautifulsoup4
2143+
2144+
Use ``-y`` to skip the request for confirmation.

sqlite_utils/cli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime
55
import hashlib
66
import pathlib
7+
from runpy import run_module
78
import sqlite_utils
89
from sqlite_utils.db import AlterError, BadMultiValues, DescIndex, NoTable
910
from sqlite_utils.utils import maximize_csv_field_size_limit
@@ -2657,6 +2658,30 @@ def _analyze(db, tables, columns, save):
26572658
click.echo(details)
26582659

26592660

2661+
@cli.command()
2662+
@click.argument("packages", nargs=-1, required=True)
2663+
@click.option(
2664+
"-U", "--upgrade", is_flag=True, help="Upgrade packages to latest version"
2665+
)
2666+
def install(packages, upgrade):
2667+
"""Install packages from PyPI into the same environment as sqlite-utils"""
2668+
args = ["pip", "install"]
2669+
if upgrade:
2670+
args += ["--upgrade"]
2671+
args += list(packages)
2672+
sys.argv = args
2673+
run_module("pip", run_name="__main__")
2674+
2675+
2676+
@cli.command()
2677+
@click.argument("packages", nargs=-1, required=True)
2678+
@click.option("-y", "--yes", is_flag=True, help="Don't ask for confirmation")
2679+
def uninstall(packages, yes):
2680+
"""Uninstall Python packages from the sqlite-utils environment"""
2681+
sys.argv = ["pip", "uninstall"] + list(packages) + (["-y"] if yes else [])
2682+
run_module("pip", run_name="__main__")
2683+
2684+
26602685
def _generate_convert_help():
26612686
help = textwrap.dedent(
26622687
"""

0 commit comments

Comments
 (0)