Skip to content

Commit

Permalink
Smarter merging of metadata and extra_metadata, closes #724
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 10, 2020
1 parent d55fe8c commit d349d57
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 6 additions & 3 deletions datasette/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import click
import hashlib
import json
import mergedeep
import os
import re
import shlex
Expand Down Expand Up @@ -363,9 +364,11 @@ def temporary_docker_directory(
metadata_content = parse_metadata(metadata.read())
else:
metadata_content = {}
for key, value in extra_metadata.items():
if value:
metadata_content[key] = value
# Merge in the non-null values in extra_metadata
mergedeep.merge(
metadata_content,
{key: value for key, value in extra_metadata.items() if value is not None},
)
try:
dockerfile = make_dockerfile(
file_names,
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get_version():
"aiofiles~=0.4.0",
"janus~=0.4.0",
"PyYAML~=5.3",
"mergedeep~=1.1.1",
],
entry_points="""
[console_scripts]
Expand Down
17 changes: 14 additions & 3 deletions tests/test_publish_cloudrun.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from click.testing import CliRunner
from datasette import cli
from unittest import mock
import pytest
import json
import pytest
import textwrap


@mock.patch("shutil.which")
Expand Down Expand Up @@ -146,7 +147,16 @@ def test_publish_cloudrun_plugin_secrets(mock_call, mock_output, mock_which):
runner = CliRunner()
with runner.isolated_filesystem():
open("test.db", "w").write("data")
open("metadata.yml", "w").write("title: Hello from metadata YAML")
open("metadata.yml", "w").write(
textwrap.dedent(
"""
title: Hello from metadata YAML
plugins:
datasette-auth-github:
foo: bar
"""
).strip()
)
result = runner.invoke(
cli.cli,
[
Expand Down Expand Up @@ -189,7 +199,8 @@ def test_publish_cloudrun_plugin_secrets(mock_call, mock_output, mock_which):
"title": "Hello from metadata YAML",
"plugins": {
"datasette-auth-github": {
"client_id": {"$env": "DATASETTE_AUTH_GITHUB_CLIENT_ID"}
"foo": "bar",
"client_id": {"$env": "DATASETTE_AUTH_GITHUB_CLIENT_ID"},
}
},
} == json.loads(metadata)

0 comments on commit d349d57

Please sign in to comment.