mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Rename config= to settings=, refs #1432
This commit is contained in:
parent
77f46297a8
commit
ca4f83dc7b
10 changed files with 35 additions and 33 deletions
|
|
@ -200,7 +200,7 @@ class Datasette:
|
|||
plugins_dir=None,
|
||||
static_mounts=None,
|
||||
memory=False,
|
||||
config=None,
|
||||
settings=None,
|
||||
secret=None,
|
||||
version_note=None,
|
||||
config_dir=None,
|
||||
|
|
@ -279,7 +279,7 @@ class Datasette:
|
|||
raise StartupError("config.json should be renamed to settings.json")
|
||||
if config_dir and (config_dir / "settings.json").exists() and not config:
|
||||
config = json.loads((config_dir / "settings.json").read_text())
|
||||
self._settings = dict(DEFAULT_SETTINGS, **(config or {}))
|
||||
self._settings = dict(DEFAULT_SETTINGS, **(settings or {}))
|
||||
self.renderers = {} # File extension -> (renderer, can_render) functions
|
||||
self.version_note = version_note
|
||||
self.executor = futures.ThreadPoolExecutor(
|
||||
|
|
@ -419,8 +419,8 @@ class Datasette:
|
|||
def setting(self, key):
|
||||
return self._settings.get(key, None)
|
||||
|
||||
def config_dict(self):
|
||||
# Returns a fully resolved config dictionary, useful for templates
|
||||
def settings_dict(self):
|
||||
# Returns a fully resolved settings dictionary, useful for templates
|
||||
return {option.name: self.setting(option.name) for option in SETTINGS}
|
||||
|
||||
def _metadata_recursive_update(self, orig, updated):
|
||||
|
|
|
|||
|
|
@ -495,14 +495,14 @@ def serve(
|
|||
if metadata:
|
||||
metadata_data = parse_metadata(metadata.read())
|
||||
|
||||
combined_config = {}
|
||||
combined_settings = {}
|
||||
if config:
|
||||
click.echo(
|
||||
"--config name:value will be deprecated in Datasette 1.0, use --setting name value instead",
|
||||
err=True,
|
||||
)
|
||||
combined_config.update(config)
|
||||
combined_config.update(settings)
|
||||
combined_settings.update(config)
|
||||
combined_settings.update(settings)
|
||||
|
||||
kwargs = dict(
|
||||
immutables=immutable,
|
||||
|
|
@ -514,7 +514,7 @@ def serve(
|
|||
template_dir=template_dir,
|
||||
plugins_dir=plugins_dir,
|
||||
static_mounts=static,
|
||||
config=combined_config,
|
||||
settings=combined_settings,
|
||||
memory=memory,
|
||||
secret=secret,
|
||||
version_note=version_note,
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@
|
|||
CSV options:
|
||||
<label><input type="checkbox" name="_dl"> download file</label>
|
||||
{% if expandable_columns %}<label><input type="checkbox" name="_labels" checked> expand labels</label>{% endif %}
|
||||
{% if next_url and config.allow_csv_stream %}<label><input type="checkbox" name="_stream"> stream all rows</label>{% endif %}
|
||||
{% if next_url and settings.allow_csv_stream %}<label><input type="checkbox" name="_stream"> stream all rows</label>{% endif %}
|
||||
<input type="submit" value="Export CSV">
|
||||
{% for key, value in url_csv_hidden_args %}
|
||||
<input type="hidden" name="{{ key }}" value="{{ value }}">
|
||||
|
|
|
|||
|
|
@ -614,7 +614,7 @@ class DataView(BaseView):
|
|||
]
|
||||
+ [("_size", "max")],
|
||||
"datasette_version": __version__,
|
||||
"config": self.ds.config_dict(),
|
||||
"settings": self.ds.settings_dict(),
|
||||
},
|
||||
}
|
||||
if "metadata" not in context:
|
||||
|
|
|
|||
|
|
@ -456,7 +456,7 @@ class QueryView(DataView):
|
|||
"canned_query": canned_query,
|
||||
"edit_sql_url": edit_sql_url,
|
||||
"metadata": metadata,
|
||||
"config": self.ds.config_dict(),
|
||||
"settings": self.ds.settings_dict(),
|
||||
"request": request,
|
||||
"show_hide_link": show_hide_link,
|
||||
"show_hide_text": show_hide_text,
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ def make_app_client(
|
|||
max_returned_rows=None,
|
||||
cors=False,
|
||||
memory=False,
|
||||
config=None,
|
||||
settings=None,
|
||||
filename="fixtures.db",
|
||||
is_immutable=False,
|
||||
extra_databases=None,
|
||||
|
|
@ -129,7 +129,7 @@ def make_app_client(
|
|||
# Insert at start to help test /-/databases ordering:
|
||||
files.insert(0, extra_filepath)
|
||||
os.chdir(os.path.dirname(filepath))
|
||||
config = config or {}
|
||||
settings = settings or {}
|
||||
for key, value in {
|
||||
"default_page_size": 50,
|
||||
"max_returned_rows": max_returned_rows or 100,
|
||||
|
|
@ -138,8 +138,8 @@ def make_app_client(
|
|||
# errors when running the full test suite:
|
||||
"num_sql_threads": 1,
|
||||
}.items():
|
||||
if key not in config:
|
||||
config[key] = value
|
||||
if key not in settings:
|
||||
settings[key] = value
|
||||
ds = Datasette(
|
||||
files,
|
||||
immutables=immutables,
|
||||
|
|
@ -147,7 +147,7 @@ def make_app_client(
|
|||
cors=cors,
|
||||
metadata=metadata or METADATA,
|
||||
plugins_dir=PLUGINS_DIR,
|
||||
config=config,
|
||||
settings=settings,
|
||||
inspect_data=inspect_data,
|
||||
static_mounts=static_mounts,
|
||||
template_dir=template_dir,
|
||||
|
|
@ -171,7 +171,7 @@ def app_client_no_files():
|
|||
|
||||
@pytest.fixture(scope="session")
|
||||
def app_client_base_url_prefix():
|
||||
with make_app_client(config={"base_url": "/prefix/"}) as client:
|
||||
with make_app_client(settings={"base_url": "/prefix/"}) as client:
|
||||
yield client
|
||||
|
||||
|
||||
|
|
@ -210,13 +210,13 @@ def app_client_two_attached_databases_one_immutable():
|
|||
|
||||
@pytest.fixture(scope="session")
|
||||
def app_client_with_hash():
|
||||
with make_app_client(config={"hash_urls": True}, is_immutable=True) as client:
|
||||
with make_app_client(settings={"hash_urls": True}, is_immutable=True) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def app_client_with_trace():
|
||||
with make_app_client(config={"trace_debug": True}, is_immutable=True) as client:
|
||||
with make_app_client(settings={"trace_debug": True}, is_immutable=True) as client:
|
||||
yield client
|
||||
|
||||
|
||||
|
|
@ -234,13 +234,13 @@ def app_client_returned_rows_matches_page_size():
|
|||
|
||||
@pytest.fixture(scope="session")
|
||||
def app_client_larger_cache_size():
|
||||
with make_app_client(config={"cache_size_kb": 2500}) as client:
|
||||
with make_app_client(settings={"cache_size_kb": 2500}) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def app_client_csv_max_mb_one():
|
||||
with make_app_client(config={"max_csv_mb": 1}) as client:
|
||||
with make_app_client(settings={"max_csv_mb": 1}) as client:
|
||||
yield client
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1711,14 +1711,14 @@ def test_suggested_facets(app_client):
|
|||
|
||||
|
||||
def test_allow_facet_off():
|
||||
with make_app_client(config={"allow_facet": False}) as client:
|
||||
with make_app_client(settings={"allow_facet": False}) as client:
|
||||
assert 400 == client.get("/fixtures/facetable.json?_facet=planet_int").status
|
||||
# Should not suggest any facets either:
|
||||
assert [] == client.get("/fixtures/facetable.json").json["suggested_facets"]
|
||||
|
||||
|
||||
def test_suggest_facets_off():
|
||||
with make_app_client(config={"suggest_facets": False}) as client:
|
||||
with make_app_client(settings={"suggest_facets": False}) as client:
|
||||
# Now suggested_facets should be []
|
||||
assert [] == client.get("/fixtures/facetable.json").json["suggested_facets"]
|
||||
|
||||
|
|
@ -1883,7 +1883,7 @@ def test_config_cache_size(app_client_larger_cache_size):
|
|||
|
||||
|
||||
def test_config_force_https_urls():
|
||||
with make_app_client(config={"force_https_urls": True}) as client:
|
||||
with make_app_client(settings={"force_https_urls": True}) as client:
|
||||
response = client.get("/fixtures/facetable.json?_size=3&_facet=state")
|
||||
assert response.json["next_url"].startswith("https://")
|
||||
assert response.json["facet_results"]["state"]["results"][0][
|
||||
|
|
@ -1921,7 +1921,7 @@ def test_custom_query_with_unicode_characters(app_client):
|
|||
|
||||
@pytest.mark.parametrize("trace_debug", (True, False))
|
||||
def test_trace(trace_debug):
|
||||
with make_app_client(config={"trace_debug": trace_debug}) as client:
|
||||
with make_app_client(settings={"trace_debug": trace_debug}) as client:
|
||||
response = client.get("/fixtures/simple_primary_key.json?_trace=1")
|
||||
assert response.status == 200
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ def custom_pages_client():
|
|||
@pytest.fixture(scope="session")
|
||||
def custom_pages_client_with_base_url():
|
||||
with make_app_client(
|
||||
template_dir=TEST_TEMPLATE_DIRS, config={"base_url": "/prefix/"}
|
||||
template_dir=TEST_TEMPLATE_DIRS, settings={"base_url": "/prefix/"}
|
||||
) as client:
|
||||
yield client
|
||||
|
||||
|
|
|
|||
|
|
@ -351,7 +351,7 @@ async def test_json_array_with_blanks_and_nulls():
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_facet_size():
|
||||
ds = Datasette([], memory=True, config={"max_returned_rows": 50})
|
||||
ds = Datasette([], memory=True, settings={"max_returned_rows": 50})
|
||||
db = ds.add_database(Database(ds, memory_name="test_facet_size"))
|
||||
await db.execute_write(
|
||||
"create table neighbourhoods(city text, neighbourhood text)", block=True
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ def test_definition_sql(path, expected_definition_sql, app_client):
|
|||
|
||||
|
||||
def test_table_cell_truncation():
|
||||
with make_app_client(config={"truncate_cells_html": 5}) as client:
|
||||
with make_app_client(settings={"truncate_cells_html": 5}) as client:
|
||||
response = client.get("/fixtures/facetable")
|
||||
assert response.status == 200
|
||||
table = Soup(response.body, "html.parser").find("table")
|
||||
|
|
@ -239,7 +239,7 @@ def test_table_cell_truncation():
|
|||
|
||||
|
||||
def test_row_page_does_not_truncate():
|
||||
with make_app_client(config={"truncate_cells_html": 5}) as client:
|
||||
with make_app_client(settings={"truncate_cells_html": 5}) as client:
|
||||
response = client.get("/fixtures/facetable/1")
|
||||
assert response.status == 200
|
||||
table = Soup(response.body, "html.parser").find("table")
|
||||
|
|
@ -1072,7 +1072,9 @@ def test_database_download_disallowed_for_memory():
|
|||
|
||||
|
||||
def test_allow_download_off():
|
||||
with make_app_client(is_immutable=True, config={"allow_download": False}) as client:
|
||||
with make_app_client(
|
||||
is_immutable=True, settings={"allow_download": False}
|
||||
) as client:
|
||||
response = client.get("/fixtures")
|
||||
soup = Soup(response.body, "html.parser")
|
||||
assert not len(soup.findAll("a", {"href": re.compile(r"\.db$")}))
|
||||
|
|
@ -1486,7 +1488,7 @@ def test_query_error(app_client):
|
|||
|
||||
|
||||
def test_config_template_debug_on():
|
||||
with make_app_client(config={"template_debug": True}) as client:
|
||||
with make_app_client(settings={"template_debug": True}) as client:
|
||||
response = client.get("/fixtures/facetable?_context=1")
|
||||
assert response.status == 200
|
||||
assert response.text.startswith("<pre>{")
|
||||
|
|
@ -1500,7 +1502,7 @@ def test_config_template_debug_off(app_client):
|
|||
|
||||
def test_debug_context_includes_extra_template_vars():
|
||||
# https://github.com/simonw/datasette/issues/693
|
||||
with make_app_client(config={"template_debug": True}) as client:
|
||||
with make_app_client(settings={"template_debug": True}) as client:
|
||||
response = client.get("/fixtures/facetable?_context=1")
|
||||
# scope_path is added by PLUGIN1
|
||||
assert "scope_path" in response.text
|
||||
|
|
@ -1744,7 +1746,7 @@ def test_facet_more_links(
|
|||
expected_ellipses_url,
|
||||
):
|
||||
with make_app_client(
|
||||
config={"max_returned_rows": max_returned_rows, "default_facet_size": 2}
|
||||
settings={"max_returned_rows": max_returned_rows, "default_facet_size": 2}
|
||||
) as client:
|
||||
response = client.get(path)
|
||||
soup = Soup(response.body, "html.parser")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue