-
-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
publish_subcommand hook + default plugins mechanism, used for publish…
… heroku/now (#349) This change introduces a new plugin hook, publish_subcommand, which can be used to implement new subcommands for the "datasette publish" command family. I've used this new hook to refactor out the "publish now" and "publish heroku" implementations into separate modules. I've also added unit tests for these two publishers, mocking the subprocess.call and subprocess.check_output functions. As part of this, I introduced a mechanism for loading default plugins. These are defined in the new "default_plugins" list inside datasette/app.py Closes #217 (Plugin support for datasette publish) Closes #348 (Unit tests for "datasette publish") Refs #14, #59, #102, #103, #146, #236, #347
- Loading branch information
Simon Willison
authored
Jul 26, 2018
1 parent
3ac21c7
commit dbbe707
Showing
14 changed files
with
343 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from ..utils import StaticMount | ||
import click | ||
import shutil | ||
import sys | ||
|
||
|
||
def add_common_publish_arguments_and_options(subcommand): | ||
for decorator in reversed(( | ||
click.argument("files", type=click.Path(exists=True), nargs=-1), | ||
click.option( | ||
"-m", | ||
"--metadata", | ||
type=click.File(mode="r"), | ||
help="Path to JSON file containing metadata to publish", | ||
), | ||
click.option("--extra-options", help="Extra options to pass to datasette serve"), | ||
click.option("--branch", help="Install datasette from a GitHub branch e.g. master"), | ||
click.option( | ||
"--template-dir", | ||
type=click.Path(exists=True, file_okay=False, dir_okay=True), | ||
help="Path to directory containing custom templates", | ||
), | ||
click.option( | ||
"--plugins-dir", | ||
type=click.Path(exists=True, file_okay=False, dir_okay=True), | ||
help="Path to directory containing custom plugins", | ||
), | ||
click.option( | ||
"--static", | ||
type=StaticMount(), | ||
help="mountpoint:path-to-directory for serving static files", | ||
multiple=True, | ||
), | ||
click.option( | ||
"--install", | ||
help="Additional packages (e.g. plugins) to install", | ||
multiple=True, | ||
), | ||
click.option("--version-note", help="Additional note to show on /-/versions"), | ||
click.option("--title", help="Title for metadata"), | ||
click.option("--license", help="License label for metadata"), | ||
click.option("--license_url", help="License URL for metadata"), | ||
click.option("--source", help="Source label for metadata"), | ||
click.option("--source_url", help="Source URL for metadata"), | ||
)): | ||
subcommand = decorator(subcommand) | ||
return subcommand | ||
|
||
|
||
def fail_if_publish_binary_not_installed(binary, publish_target, install_link): | ||
"""Exit (with error message) if ``binary` isn't installed""" | ||
if not shutil.which(binary): | ||
click.secho( | ||
"Publishing to {publish_target} requires {binary} to be installed and configured".format( | ||
publish_target=publish_target, binary=binary | ||
), | ||
bg="red", | ||
fg="white", | ||
bold=True, | ||
err=True, | ||
) | ||
click.echo( | ||
"Follow the instructions at {install_link}".format( | ||
install_link=install_link | ||
), | ||
err=True, | ||
) | ||
sys.exit(1) |
Oops, something went wrong.