Skip to content

Commit 0058325

Browse files
committed
rm json_serializer option
1 parent 3a4491c commit 0058325

File tree

4 files changed

+12
-19
lines changed

4 files changed

+12
-19
lines changed

packages/settings-library/src/settings_library/utils_cli.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,15 @@ def print_as_envfile(
7070
typer.echo(f"{name}={value}")
7171

7272

73-
def print_as_json(
73+
def _print_as_json(
7474
settings_obj,
7575
*,
7676
compact: bool = False,
7777
show_secrets: bool,
78-
json_serializer,
7978
**pydantic_export_options,
8079
):
8180
typer.echo(
82-
json_serializer(
81+
json_dumps(
8382
model_dump_with_secrets(
8483
settings_obj, show_secrets=show_secrets, **pydantic_export_options
8584
),
@@ -91,7 +90,6 @@ def print_as_json(
9190
def create_settings_command(
9291
settings_cls: type[BaseCustomSettings],
9392
logger: logging.Logger | None = None,
94-
json_serializer=json_dumps,
9593
) -> Callable:
9694
"""Creates typer command function for settings"""
9795

@@ -117,7 +115,7 @@ def settings(
117115

118116
if as_json_schema:
119117
typer.echo(
120-
json.dumps(
118+
json_dumps(
121119
settings_cls.model_json_schema(),
122120
default=to_jsonable_python,
123121
indent=0 if compact else 2,
@@ -129,7 +127,7 @@ def settings(
129127
settings_obj = settings_cls.create_from_envs()
130128

131129
except ValidationError as err:
132-
settings_schema = json.dumps(
130+
settings_schema = json_dumps(
133131
settings_cls.model_json_schema(),
134132
default=to_jsonable_python,
135133
indent=2,
@@ -162,11 +160,10 @@ def settings(
162160
pydantic_export_options: dict[str, Any] = {"exclude_unset": exclude_unset}
163161

164162
if as_json:
165-
print_as_json(
163+
_print_as_json(
166164
settings_obj,
167165
compact=compact,
168166
show_secrets=show_secrets,
169-
json_serializer=json_serializer,
170167
**pydantic_export_options,
171168
)
172169
else:

packages/settings-library/tests/test_utils_cli.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
import pytest
1212
import typer
1313
from dotenv import dotenv_values
14-
from pydantic import Field, SecretStr
14+
from pydantic import AnyHttpUrl, Field, SecretStr
1515
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_envfile
1616
from pytest_simcore.helpers.typing_env import EnvVarsDict
1717
from settings_library.base import BaseCustomSettings
1818
from settings_library.utils_cli import (
19+
_print_as_json,
1920
create_settings_command,
2021
create_version_callback,
2122
model_dump_with_secrets,
2223
print_as_envfile,
23-
print_as_json,
2424
)
2525
from typer.testing import CliRunner
2626

@@ -416,8 +416,9 @@ def test_print_as(capsys: pytest.CaptureFixture):
416416
class FakeSettings(BaseCustomSettings):
417417
INTEGER: int = Field(..., description="Some info")
418418
SECRET: SecretStr
419+
URL: AnyHttpUrl
419420

420-
settings_obj = FakeSettings(INTEGER=1, SECRET="secret") # type: ignore
421+
settings_obj = FakeSettings(INTEGER=1, SECRET="secret", URL="http://google.com") # type: ignore
421422

422423
print_as_envfile(settings_obj, compact=True, verbose=True, show_secrets=True)
423424
captured = capsys.readouterr()
@@ -434,9 +435,7 @@ class FakeSettings(BaseCustomSettings):
434435
assert "secret" not in captured.out
435436
assert "Some info" not in captured.out
436437

437-
print_as_json(
438-
settings_obj, compact=True, show_secrets=False, json_serializer=json.dumps
439-
)
438+
_print_as_json(settings_obj, compact=True, show_secrets=False)
440439
captured = capsys.readouterr()
441440
assert "secret" not in captured.out
442441
assert "**" in captured.out

services/payments/src/simcore_service_payments/cli.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44

55
import typer
6-
from common_library.json_serialization import json_dumps
76
from servicelib.utils_secrets import generate_password, generate_token_secret_key
87
from settings_library.postgres import PostgresSettings
98
from settings_library.rabbit import RabbitSettings
@@ -21,9 +20,7 @@
2120
main = typer.Typer(name=PROJECT_NAME)
2221

2322
main.command()(
24-
create_settings_command(
25-
settings_cls=ApplicationSettings, logger=_logger, json_serializer=json_dumps
26-
)
23+
create_settings_command(settings_cls=ApplicationSettings, logger=_logger)
2724
)
2825
main.callback()(create_version_callback(__version__))
2926

services/storage/src/simcore_service_storage/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _validate_loglevel(cls, value: str) -> str:
105105
return log_level
106106

107107
@model_validator(mode="after")
108-
def ensure_settings_consistency(self) -> Self:
108+
def _ensure_settings_consistency(self) -> Self:
109109
if self.STORAGE_CLEANER_INTERVAL_S is not None and not self.STORAGE_REDIS:
110110
msg = (
111111
"STORAGE_CLEANER_INTERVAL_S cleaner cannot be set without STORAGE_REDIS! "

0 commit comments

Comments
 (0)