This commit is contained in:
AnkitaAdvitot 2026-10-17 18:30:50 +03:00 • committed by GitHub
commit 01d180ccc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 69 additions and 1 deletions

View file

@ -326,13 +326,34 @@ def package(
"--editable",
help="Install a project in editable mode from this path",
)
def install(packages, upgrade, requirement, editable):
@click.option(
"--pre", is_flag=True, help="Include pre-release and development versions"
)
@click.option(
"--force-reinstall",
is_flag=True,
help="Reinstall all packages even if they are already up-to-date",
)
@click.option(
"--no-cache-dir",
is_flag=True,
help="Disable the cache",
)
def install(
packages, upgrade, requirement, editable, pre, force_reinstall, no_cache_dir
):
"""Install plugins and packages from PyPI into the same environment as Datasette"""
if not packages and not requirement and not editable:
raise click.UsageError("Please specify at least one package to install")
args = ["pip", "install"]
if upgrade:
args += ["--upgrade"]
if pre:
args += ["--pre"]
if force_reinstall:
args += ["--force-reinstall"]
if no_cache_dir:
args += ["--no-cache-dir"]
if editable:
args += ["--editable", editable]
if requirement:

View file

@ -25,6 +25,7 @@ To collect telemetry, configure an OpenTelemetry SDK and exporter, then run Data
Other features
~~~~~~~~~~~~~~
- New ``--pre``, ``--force-reinstall``, and ``--no-cache-dir`` options for ``datasette install``. (:issue:`2483`)
- New :ref:`DatasetteModal JavaScript API <javascript_plugins_modals>` for plugins to create dialogs with Datasette's shared styles, keyboard behavior and focus handling. Datasette's built-in dialogs use the same API. (:issue:`2790`, :pr:`2948`)
Bug fixes

View file

@ -385,6 +385,10 @@ Would install the `datasette-cluster-map <https://datasette.io/plugins/datasette
-U, --upgrade Upgrade packages to latest version
-r, --requirement PATH Install from requirements file
-e, --editable TEXT Install a project in editable mode from this path
--pre Include pre-release and development versions
--force-reinstall Reinstall all packages even if they are already up-to-
date
--no-cache-dir Disable the cache
--help Show this message and exit.

View file

@ -213,6 +213,48 @@ def test_install_requirements(run_module, tmpdir):
assert sys.argv == ["pip", "install", "-r", str(path)]
@pytest.mark.parametrize(
"flag,expected_arg",
[
("--pre", "--pre"),
("--force-reinstall", "--force-reinstall"),
("--no-cache-dir", "--no-cache-dir"),
],
)
@mock.patch("datasette.cli.run_module")
def test_install_flags(run_module, flag, expected_arg):
runner = CliRunner()
runner.invoke(cli, ["install", flag, "datasette-mock-plugin"])
run_module.assert_called_once_with("pip", run_name="__main__")
assert sys.argv == ["pip", "install", expected_arg, "datasette-mock-plugin"]
@mock.patch("datasette.cli.run_module")
def test_install_multiple_options(run_module):
runner = CliRunner()
runner.invoke(
cli,
[
"install",
"--pre",
"--force-reinstall",
"--no-cache-dir",
"-U",
"datasette-mock-plugin",
],
)
run_module.assert_called_once_with("pip", run_name="__main__")
assert sys.argv == [
"pip",
"install",
"--upgrade",
"--pre",
"--force-reinstall",
"--no-cache-dir",
"datasette-mock-plugin",
]
def test_install_error_if_no_packages():
runner = CliRunner()
result = runner.invoke(cli, ["install"])