Skip to content

Commit

Permalink
fix: better print onut (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino authored Nov 15, 2024
1 parent 7636b42 commit eb738e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
19 changes: 10 additions & 9 deletions cognite/pygen/_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,17 @@ def _generate_sdk(
if client_name is None:
client_name = _default_client_name(external_id)

sdk_generator = SDKGenerator(
top_level_package,
client_name,
data_model,
default_instance_space,
"inheritance",
logger,
config or PygenConfig(),
)
with warnings.catch_warnings(record=True) as warning_logger:
sdk_generator = SDKGenerator(
top_level_package,
client_name,
data_model,
default_instance_space,
"inheritance",
logger,
config or PygenConfig(),
)

sdk = sdk_generator.generate_sdk()
if warning_logger:
print_warnings(warning_logger, logger, context)
Expand Down
17 changes: 12 additions & 5 deletions cognite/pygen/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,18 @@ def _print_group(console: Callable[[str], None], group: type[PygenWarning], warn
for view, properties in itertools.groupby(
sorted(property_warnings, key=lambda w: w.view_id.external_id), key=lambda w: w.view_id.external_id
):
properties_str = ", ".join(warning.property_name for warning in properties)
console(
f"{indent}The following properties in view {view} will have an underscore "
f"added to avoid name collision: {properties_str}"
)
properties_list = list(properties)
if len(properties_list) == 1:
console(
f"{indent} The property {properties_list[0].property_name!r} in view {view} "
"will have an underscore to avoid name collision."
)
else:
properties_str = ", ".join(warning.property_name for warning in properties)
console(
f"{indent}The following properties in view {view} will have an underscore "
f"added to avoid name collision: {properties_str}"
)
elif group is MissingReverseDirectRelationTargetWarning:
relation_warnings = cast(list[MissingReverseDirectRelationTargetWarning], warning_list)
for relation_warn in relation_warnings:
Expand Down

0 comments on commit eb738e6

Please sign in to comment.