Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Jul 29, 2024
1 parent 51ac1b7 commit 8668528
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions scripts/semconv/templates/registry/common.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
{%- endmacro %}

{%- macro str_or_empty(str) -%}
{% if str is defined and str is not none %}{{str}}{% else %}{{""}}{% endif %}
{% if str is none %}{{""}}{% else %}{{str}}{% endif %}
{%- endmacro %}

{%- macro remove_trailing_dots(str) -%}
{%- if str[-1:] == '.' -%}{{ remove_trailing_dots(str[:-1]) }}{%- else -%}{{ str }}{%- endif -%}
{%- endmacro -%}

{%- macro to_docstring(str, prefix) -%}
{%- macro comment_with_prefix(str, prefix) -%}
{{remove_trailing_dots(str | trim(' \n')) | comment_with_prefix(prefix)}}
{%- endmacro %}

Expand Down
8 changes: 4 additions & 4 deletions scripts/semconv/templates/registry/semantic_attributes.j2
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ from typing import Final

{%- macro write_docstring(name, brief, note, deprecated, stability, prefix) -%}
{%- if c.str_or_empty(deprecated)|length -%}
{{prefix}}Deprecated: {{c.to_docstring(deprecated, prefix)}}.
{{prefix}}Deprecated: {{c.comment_with_prefix(deprecated, prefix)}}.
{%- elif ctx.filter == "any" and stability == "stable" -%}
{{prefix}}Deprecated in favor of stable :py:const:`{{stable_class_ref(name, '.')}}`.
{%- elif c.str_or_empty(brief)|length -%}
{{prefix}}{{c.to_docstring(brief, prefix)}}.
{{prefix}}{{c.comment_with_prefix(brief, prefix)}}.
{%- if c.str_or_empty(note)|length %}
{{prefix}}Note: {{c.to_docstring(note, prefix)}}.
{{prefix}}Note: {{c.comment_with_prefix(note, prefix)}}.
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
Expand All @@ -58,7 +58,7 @@ from typing import Final

{% for attribute in enum_attributes %}{%- set class_name = attribute.name | pascal_case ~ "Values" -%}
{%- if attribute is deprecated %}
@deprecated(reason="The attribute {{attribute.name}} is deprecated - {{ c.to_docstring(attribute.deprecated, "") }}") # type: ignore
@deprecated(reason="The attribute {{attribute.name}} is deprecated - {{ c.comment_with_prefix(attribute.deprecated, "") }}") # type: ignore
{%- elif attribute.stability == "stable" and ctx.filter == "any" %}
@deprecated(reason="Deprecated in favor of stable :py:const:`{{stable_class_ref(class_name, '.')}}`.") # type: ignore
{%- endif %}
Expand Down
8 changes: 4 additions & 4 deletions scripts/semconv/templates/registry/semantic_metrics.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@

{%- macro write_docstring(metric, const_name, prefix) -%}
{%- if metric is deprecated %}
{{prefix}}Deprecated: {{c.to_docstring(metric.deprecated, prefix)}}.
{{prefix}}Deprecated: {{c.comment_with_prefix(metric.deprecated, prefix)}}.
{%- elif ctx.filter == "any" and metric.stability == "stable" %}
{{prefix}}Deprecated in favor of stable :py:const:`{{stable_class_ref(const_name, '.')}}`.
{%- else -%}
{%- if c.str_or_empty(metric.brief)|length %}
{{prefix}}{{c.to_docstring(metric.brief, prefix)}}
{{prefix}}{{c.comment_with_prefix(metric.brief, prefix)}}
{%- endif %}
{{prefix}}Instrument: {{ metric.instrument }}
{{prefix}}Unit: {{ metric.unit }}
{%- if c.str_or_empty(metric.note)|length %}
{{prefix}}Note: {{c.to_docstring(metric.note, prefix)}}.
{{prefix}}Note: {{c.comment_with_prefix(metric.note, prefix)}}.
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
Expand Down Expand Up @@ -81,7 +81,7 @@ def create_{{ metric_name }}(meter: Meter, callbacks: Optional[Sequence[Callback
def create_{{ metric_name }}(meter: Meter) -> {{metric.instrument | map_text("py_instrument_to_type")}}:
{%- endif %}
{%- if c.str_or_empty(metric.brief) |length %}
"""{{ c.to_docstring(metric.brief, "") | replace("\\", "\\\\")}}"""
"""{{ c.comment_with_prefix(metric.brief, "") }}"""
{% endif -%}
return meter.create_{{ metric.instrument | map_text("py_instrument_to_factory")}}(
name={{ const_name }},
Expand Down

0 comments on commit 8668528

Please sign in to comment.