Skip to content

Commit

Permalink
Introduce FLEXMEASURES_JSON_COMPACT setting, in a move to deprecate J…
Browse files Browse the repository at this point in the history
…SONIFY_PRETTYPRINT_REGULAR

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
nhoening committed Jun 10, 2024
1 parent 60fbace commit fb1afb2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
13 changes: 13 additions & 0 deletions flexmeasures/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ def get_reporters():

register_auth_at(app)

# This needs to happen here because for unknown reasons, Security(app)
# and FlaskJSON() will set this to False on their own
if app.config.get("FLEXMEASURES_JSON_COMPACT", False) in (
True,
"True",
"true",
"1",
"yes",
):
app.json.compact = True
else:
app.json.compact = False

# Register the CLI

from flexmeasures.cli import register_at as register_cli_at
Expand Down
5 changes: 2 additions & 3 deletions flexmeasures/utils/config_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class Config(object):

MAPBOX_ACCESS_TOKEN: str | None = None

JSONIFY_PRETTYPRINT_REGULAR: bool = False

RQ_DASHBOARD_POLL_INTERVAL: int = (
3000 # Web interface poll period for updates in ms
)
Expand Down Expand Up @@ -130,6 +128,7 @@ class Config(object):
currencysymbolmap="5.1.0",
# todo: expand with other js versions used in FlexMeasures
)
FLEXMEASURES_JSON_COMPACT = False

FLEXMEASURES_FALLBACK_REDIRECT: bool = False

Expand Down Expand Up @@ -182,9 +181,9 @@ class DevelopmentConfig(Config):
SQLALCHEMY_ECHO: bool = False
PROPAGATE_EXCEPTIONS: bool = True
# PRESERVE_CONTEXT_ON_EXCEPTION: bool = False # might need this to make our transaction handling work in debug mode
JSONIFY_PRETTYPRINT_REGULAR: bool = True
FLEXMEASURES_MODE: str = "development"
FLEXMEASURES_PROFILE_REQUESTS: bool = True
FLEXMEASURES_JSON_COMPACT = False


class TestingConfig(Config):
Expand Down
9 changes: 8 additions & 1 deletion flexmeasures/utils/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,18 @@ def read_env_vars(app: Flask):
- Logging settings
- access tokens
- plugins (handled in plugin utils)
- json compactness
"""
for var in (
required
+ list(warnable.keys())
+ ["LOGGING_LEVEL", "MAPBOX_ACCESS_TOKEN", "SENTRY_SDN", "FLEXMEASURES_PLUGINS"]
+ [
"LOGGING_LEVEL",
"MAPBOX_ACCESS_TOKEN",
"SENTRY_SDN",
"FLEXMEASURES_PLUGINS",
"FLEXMEASURES_JSON_COMPACT",
]
):
app.config[var] = os.getenv(var, app.config.get(var, None))
# DEBUG in env can come in as a string ("True") so make sure we don't trip here
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/utils/flexmeasures_inflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def human_sorted(alist: list, attr: Any | None = None, reverse: bool = False):
# List of objects, to be sorted by attribute
sorted_list = sorted(
alist,
key=lambda k: natural_keys(str(getattr(k, attr))),
key=lambda k: natural_keys(str(getattr(k, str(attr)))),
reverse=reverse,
)
return sorted_list

0 comments on commit fb1afb2

Please sign in to comment.