|
4 | 4 | from datetime import datetime |
5 | 5 | import hashlib |
6 | 6 | import pathlib |
| 7 | +from runpy import run_module |
7 | 8 | import sqlite_utils |
8 | 9 | from sqlite_utils.db import AlterError, BadMultiValues, DescIndex, NoTable |
9 | 10 | from sqlite_utils.utils import maximize_csv_field_size_limit |
@@ -2657,6 +2658,30 @@ def _analyze(db, tables, columns, save): |
2657 | 2658 | click.echo(details) |
2658 | 2659 |
|
2659 | 2660 |
|
| 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 | + |
2660 | 2685 | def _generate_convert_help(): |
2661 | 2686 | help = textwrap.dedent( |
2662 | 2687 | """ |
|
0 commit comments