Skip to content

Commit

Permalink
add license to j2 files and clean up templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed May 1, 2024
1 parent 3e64854 commit f7a273a
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from enum import Enum

from deprecated import deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from enum import Enum

from deprecated import deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from enum import Enum

from deprecated import deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from enum import Enum

from deprecated import deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from enum import Enum

from deprecated import deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from enum import Enum

from deprecated import deprecated
Expand Down
9 changes: 8 additions & 1 deletion scripts/semconv/templates/common.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
{%- endmacro -%}

{% endmacro -%}

{%- macro to_docstring(str) -%}
{{ str | to_doc_brief | replace("\\", "\\\\") }}
{%- endmacro -%}

{%- macro import_deprecated(semconv) -%}
{%- if (semconv | select("is_deprecated") | list | count > 0) or (filter == "any" and semconv | select("is_stable") | list | count > 0) %}
from deprecated import deprecated
{%- endif %}
{%- endmacro-%}
29 changes: 17 additions & 12 deletions scripts/semconv/templates/semantic_attributes.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
{% import 'common.j2' as common %}
{#
# Copyright The OpenTelemetry Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#}

{%- import 'common.j2' as common -%}

{%- macro stable_class_ref(const_name, separator) -%}
{{stable_package}}.{{root_namespace}}_attributes{{separator}}{{const_name}}
Expand Down Expand Up @@ -27,16 +42,6 @@ Note: {{ common.to_docstring(attribute.note | indent)}}.
"""
{%- endmacro -%}

{%- macro import_deprecated(attrs) -%}
{%- if attrs | select("is_deprecated") | list | count > 0 %}
from deprecated import deprecated
{%- endif %}

{%- if filter == "any" and attrs | select("is_stable") | list | count > 0 %}
from deprecated import deprecated
{%- endif %}
{%- endmacro-%}

{%- if root_namespace not in excluded_namespaces -%}
{%- if filter != 'any' -%}
{%- set filtered_attributes = attributes_and_templates | select(filter) | list -%}
Expand All @@ -53,7 +58,7 @@ from deprecated import deprecated
{%- set filtered_enum_attributes = enum_attributes | list %}
{%- endif -%}

{{import_deprecated(filtered_enum_attributes)}}
{{common.import_deprecated(filtered_enum_attributes)}}

{% if filtered_enum_attributes | count > 0 %}

Expand Down
25 changes: 16 additions & 9 deletions scripts/semconv/templates/semantic_metrics.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
{% import 'common.j2' as common %}
{#
# Copyright The OpenTelemetry Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#}

{%- import 'common.j2' as common -%}

{%- macro to_python_instrument_factory(instrument) -%}
{%- if instrument == "counter" -%}
Expand Down Expand Up @@ -47,14 +62,6 @@ Note: {{ common.to_docstring(metric.note | indent) }}.
"""
{%- endmacro -%}

{%- macro import_deprecated(metrics) -%}
{%- if metrics | select("is_deprecated") | list | count > 0 %}
from deprecated import deprecated
{%- elif filter == "any" and metrics | select("is_stable") | list | count > 0 %}
from deprecated import deprecated
{%- endif %}
{%- endmacro-%}

{%- macro import_instrument_classes(metrics) -%}
{% if filter == "any" %}
from opentelemetry.metrics import Meter
Expand Down

0 comments on commit f7a273a

Please sign in to comment.