kopia lustrzana https://github.com/simonw/datasette
datasette install -r requirements.txt, closes #2033
rodzic
a53b893c46
commit
1ad92a1d87
|
@ -340,15 +340,25 @@ def package(
|
|||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("packages", nargs=-1, required=True)
|
||||
@click.argument("packages", nargs=-1)
|
||||
@click.option(
|
||||
"-U", "--upgrade", is_flag=True, help="Upgrade packages to latest version"
|
||||
)
|
||||
def install(packages, upgrade):
|
||||
@click.option(
|
||||
"-r",
|
||||
"--requirement",
|
||||
type=click.Path(exists=True),
|
||||
help="Install from requirements file",
|
||||
)
|
||||
def install(packages, upgrade, requirement):
|
||||
"""Install plugins and packages from PyPI into the same environment as Datasette"""
|
||||
if not packages and not requirement:
|
||||
raise click.UsageError("Please specify at least one package to install")
|
||||
args = ["pip", "install"]
|
||||
if upgrade:
|
||||
args += ["--upgrade"]
|
||||
if requirement:
|
||||
args += ["-r", requirement]
|
||||
args += list(packages)
|
||||
sys.argv = args
|
||||
run_module("pip", run_name="__main__")
|
||||
|
|
|
@ -345,12 +345,13 @@ Would install the `datasette-cluster-map <https://datasette.io/plugins/datasette
|
|||
|
||||
::
|
||||
|
||||
Usage: datasette install [OPTIONS] PACKAGES...
|
||||
Usage: datasette install [OPTIONS] [PACKAGES]...
|
||||
|
||||
Install plugins and packages from PyPI into the same environment as Datasette
|
||||
|
||||
Options:
|
||||
-U, --upgrade Upgrade packages to latest version
|
||||
-r, --requirement PATH Install from requirements file
|
||||
--help Show this message and exit.
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,16 @@ This command can also be used to upgrade Datasette itself to the latest released
|
|||
|
||||
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.
|
||||
You can install multiple plugins at once by listing them as lines in a ``requirements.txt`` file like this::
|
||||
|
||||
datasette-vega
|
||||
datasette-cluster-map
|
||||
|
||||
Then pass that file to ``datasette install -r``::
|
||||
|
||||
datasette install -r requirements.txt
|
||||
|
||||
The ``install`` and ``uninstall`` commands are thin wrappers around ``pip install`` and ``pip uninstall``, which ensure that they run ``pip`` in the same virtual environment as Datasette itself.
|
||||
|
||||
One-off plugins using --plugins-dir
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -178,6 +178,24 @@ def test_install_upgrade(run_module, flag):
|
|||
assert sys.argv == ["pip", "install", "--upgrade", "datasette"]
|
||||
|
||||
|
||||
@mock.patch("datasette.cli.run_module")
|
||||
def test_install_requirements(run_module):
|
||||
runner = CliRunner()
|
||||
with runner.isolated_filesystem():
|
||||
with open("requirements.txt", "w") as fp:
|
||||
fp.write("datasette-mock-plugin\ndatasette-plugin-2")
|
||||
runner.invoke(cli, ["install", "-r", "requirements.txt"])
|
||||
run_module.assert_called_once_with("pip", run_name="__main__")
|
||||
assert sys.argv == ["pip", "install", "-r", "requirements.txt"]
|
||||
|
||||
|
||||
def test_install_error_if_no_packages():
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["install"])
|
||||
assert result.exit_code == 2
|
||||
assert "Error: Please specify at least one package to install" in result.output
|
||||
|
||||
|
||||
@mock.patch("datasette.cli.run_module")
|
||||
def test_uninstall(run_module):
|
||||
runner = CliRunner()
|
||||
|
|
Ładowanie…
Reference in New Issue