Skip to content

Commit

Permalink
Rename config= to settings=, refs #1432
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Aug 13, 2021
1 parent d2de179 commit 07b6c9d
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 33 deletions.
8 changes: 4 additions & 4 deletions datasette/app.py
Expand Up @@ -200,7 +200,7 @@ def __init__(
plugins_dir=None,
static_mounts=None,
memory=False,
config=None,
settings=None,
secret=None,
version_note=None,
config_dir=None,
Expand Down Expand Up @@ -279,7 +279,7 @@ def __init__(
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(
Expand Down Expand Up @@ -419,8 +419,8 @@ def remove_database(self, name):
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):
Expand Down
8 changes: 4 additions & 4 deletions datasette/cli.py
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion datasette/templates/table.html
Expand Up @@ -201,7 +201,7 @@ <h3>Advanced export</h3>
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 }}">
Expand Down
2 changes: 1 addition & 1 deletion datasette/views/base.py
Expand Up @@ -614,7 +614,7 @@ async def view_get(self, request, database, hash, correct_hash_provided, **kwarg
]
+ [("_size", "max")],
"datasette_version": __version__,
"config": self.ds.config_dict(),
"settings": self.ds.settings_dict(),
},
}
if "metadata" not in context:
Expand Down
2 changes: 1 addition & 1 deletion datasette/views/database.py
Expand Up @@ -465,7 +465,7 @@ async def extra_template():
"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,
Expand Down
20 changes: 10 additions & 10 deletions tests/fixtures.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -138,16 +138,16 @@ 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,
memory=memory,
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,
Expand All @@ -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


Expand Down Expand Up @@ -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


Expand All @@ -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


Expand Down
8 changes: 4 additions & 4 deletions tests/test_api.py
Expand Up @@ -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"]

Expand Down Expand Up @@ -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][
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_custom_pages.py
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_facets.py
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions tests/test_html.py
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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$")}))
Expand Down Expand Up @@ -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>{")
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 07b6c9d

Please sign in to comment.