kopia lustrzana https://github.com/simonw/datasette
--metadata accepts YAML as well as JSON, refs #713
rodzic
2aaad72789
commit
616536e9dc
|
@ -11,6 +11,7 @@ import sys
|
|||
from .app import Datasette, DEFAULT_CONFIG, CONFIG_OPTIONS, pm
|
||||
from .utils import (
|
||||
check_connection,
|
||||
parse_metadata,
|
||||
ConnectionProblem,
|
||||
SpatialiteConnectionProblem,
|
||||
temporary_docker_directory,
|
||||
|
@ -147,7 +148,7 @@ def plugins(all, plugins_dir):
|
|||
"-m",
|
||||
"--metadata",
|
||||
type=click.File(mode="r"),
|
||||
help="Path to JSON file containing metadata to publish",
|
||||
help="Path to JSON/YAML 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")
|
||||
|
@ -281,7 +282,7 @@ def package(
|
|||
"-m",
|
||||
"--metadata",
|
||||
type=click.File(mode="r"),
|
||||
help="Path to JSON file containing license/source metadata",
|
||||
help="Path to JSON/YAML file containing license/source metadata",
|
||||
)
|
||||
@click.option(
|
||||
"--template-dir",
|
||||
|
@ -354,7 +355,7 @@ def serve(
|
|||
|
||||
metadata_data = None
|
||||
if metadata:
|
||||
metadata_data = json.loads(metadata.read())
|
||||
metadata_data = parse_metadata(metadata.read())
|
||||
|
||||
click.echo(
|
||||
"Serve! files={} (immutables={}) on port {}".format(files, immutable, port)
|
||||
|
|
|
@ -12,7 +12,7 @@ def add_common_publish_arguments_and_options(subcommand):
|
|||
"-m",
|
||||
"--metadata",
|
||||
type=click.File(mode="r"),
|
||||
help="Path to JSON file containing metadata to publish",
|
||||
help="Path to JSON/YAML file containing metadata to publish",
|
||||
),
|
||||
click.option(
|
||||
"--extra-options", help="Extra options to pass to datasette serve"
|
||||
|
|
|
@ -11,7 +11,7 @@ from .common import (
|
|||
add_common_publish_arguments_and_options,
|
||||
fail_if_publish_binary_not_installed,
|
||||
)
|
||||
from datasette.utils import link_or_copy, link_or_copy_directory
|
||||
from datasette.utils import link_or_copy, link_or_copy_directory, parse_metadata
|
||||
|
||||
|
||||
@hookimpl
|
||||
|
@ -154,7 +154,7 @@ def temporary_heroku_directory(
|
|||
file_names = [os.path.split(f)[-1] for f in files]
|
||||
|
||||
if metadata:
|
||||
metadata_content = json.load(metadata)
|
||||
metadata_content = parse_metadata(metadata.read())
|
||||
else:
|
||||
metadata_content = {}
|
||||
for key, value in extra_metadata.items():
|
||||
|
|
|
@ -13,6 +13,7 @@ import types
|
|||
import shutil
|
||||
import urllib
|
||||
import numbers
|
||||
import yaml
|
||||
|
||||
try:
|
||||
import pysqlite3 as sqlite3
|
||||
|
@ -359,7 +360,7 @@ def temporary_docker_directory(
|
|||
file_paths = [os.path.join(saved_cwd, file_path) for file_path in files]
|
||||
file_names = [os.path.split(f)[-1] for f in files]
|
||||
if metadata:
|
||||
metadata_content = json.load(metadata)
|
||||
metadata_content = parse_metadata(metadata.read())
|
||||
else:
|
||||
metadata_content = {}
|
||||
for key, value in extra_metadata.items():
|
||||
|
@ -785,3 +786,18 @@ def check_connection(conn):
|
|||
raise SpatialiteConnectionProblem(e)
|
||||
else:
|
||||
raise ConnectionProblem(e)
|
||||
|
||||
|
||||
class BadMetadataError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def parse_metadata(content):
|
||||
# content can be JSON or YAML
|
||||
try:
|
||||
return json.loads(content)
|
||||
except json.JSONDecodeError:
|
||||
try:
|
||||
return yaml.safe_load(content)
|
||||
except yaml.YAMLError:
|
||||
raise BadMetadataError("Metadata is not valid JSON or YAML")
|
||||
|
|
1
setup.py
1
setup.py
|
@ -45,6 +45,7 @@ setup(
|
|||
"uvicorn~=0.11",
|
||||
"aiofiles~=0.4.0",
|
||||
"janus~=0.4.0",
|
||||
"PyYAML~=5.3",
|
||||
],
|
||||
entry_points="""
|
||||
[console_scripts]
|
||||
|
|
Ładowanie…
Reference in New Issue