Skip to content

Commit

Permalink
chore: __init__.py file output is now more deterministic
Browse files Browse the repository at this point in the history
Sort everything that is iteratively produced, e.g. message and enum
classes provided.
  • Loading branch information
software-dov committed Mar 5, 2021
1 parent 96f7864 commit 8218a60
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions gapic/ads-templates/%namespace/%name/%version/__init__.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ if sys.version_info < (3, 7):

_lazy_type_to_package_map = {
# Message types
{%- for message in api.top_level_messages.values() %}
{%- for _, message in api.top_level_messages|dictsort %}
'{{ message.name }}': '{{ message.ident.package|join('.') }}.types.{{ message.ident.module }}',
{%- endfor %}

# Enum types
{%- for enum in api.top_level_enums.values() %}
{%- for _, enum in api.top_level_enums|dictsort %}
'{{ enum.name }}': '{{ enum.ident.package|join('.') }}.types.{{enum.ident.module }}',
{%- endfor %}

{# TODO(yon-mg): add rest transport service once I know what this is #}
# Client classes and transports
{%- for service in api.services.values() %}
# Client classes and transports
{%- for _, service in api.services|dictsort %}
'{{ service.client_name }}': '{{ service.meta.address.package|join('.') }}.services.{{ service.meta.address.module }}',
'{{ service.transport_name }}': '{{ service.meta.address.package|join('.') }}.services.{{ service.meta.address.module }}.transports',
'{{ service.grpc_transport_name }}': '{{ service.meta.address.package|join('.') }}.services.{{ service.meta.address.module }}.transports',
Expand Down
14 changes: 7 additions & 7 deletions gapic/ads-templates/%namespace/%name/__init__.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ if sys.version_info < (3, 7):

_lazy_type_to_package_map = {
# Message types
{%- for message in api.top_level_messages.values() %}
{%- for _, message in api.top_level_messages|dictsort %}
'{{ message.name }}': '{{ message.ident.package|join('.') }}.types.{{ message.ident.module }}',
{%- endfor %}

# Enum types
{%- for enum in api.top_level_enums.values() %}
{%- for _, enum in api.top_level_enums|dictsort %}
'{{ enum.name }}': '{{ enum.ident.package|join('.') }}.types.{{enum.ident.module }}',
{%- endfor %}

{# TODO(yon-mg): add rest transport service once I know what this is #}
# Client classes and transports
{%- for service in api.services.values() %}
# Client classes and transports
{%- for _, service in api.services|dictsort %}
'{{ service.client_name }}': '{{ service.meta.address.package|join('.') }}.services.{{ service.meta.address.module }}',
'{{ service.transport_name }}': '{{ service.meta.address.package|join('.') }}.services.{{ service.meta.address.module }}.transports',
'{{ service.grpc_transport_name }}': '{{ service.meta.address.package|join('.') }}.services.{{ service.meta.address.module }}.transports',
Expand Down Expand Up @@ -90,7 +90,7 @@ from {% if api.naming.module_namespace %}{{ api.naming.module_namespace|join('.'
__all__ = (
{%- filter indent %}
{% filter sort_lines -%}
{% for subpackage in api.subpackages.keys() -%}
{% for subpackage, _ in api.subpackages|dictsort -%}
'{{ subpackage }}',
{% endfor -%}
{% for service in api.services.values()|sort(attribute='name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block content %}
{# Import subpackages. -#}
{% for subpackage in api.subpackages.keys() -%}
{% for subpackage, _ in api.subpackages|dictsort -%}
from . import {{ subpackage }}
{% endfor -%}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{% extends '_base.py.j2' %}

{% block content %}
{%- for proto in api.protos.values() if proto.file_to_generate and proto.messages %}
{%- for _, proto in api.protos|dictsort if proto.file_to_generate and proto.messages %}
from .{{proto.module_name }} import (
{%- for message in proto.messages.values() %}
{%- for _, message in proto.messages|dictsort %}
{{message.name }}, {% endfor %}
{%- for enum in proto.enums.values() %}
{%- for _, enum in proto.enums|dictsort %}
{{ enum.name }}, {% endfor %}
){% endfor %}

__all__ = (
{%- for proto in api.protos.values() if proto.file_to_generate %}
{%- for message in proto.messages.values() %}
{%- for _, proto in api.protos|dictsort if proto.file_to_generate %}
{%- for _, message in proto.messages|dictsort %}
'{{ message.name }}',
{%- endfor -%}
{%- for enum in proto.enums.values() %}
{%- for _, enum in proto.enums|dictsort %}
'{{ enum.name }}',
{%- endfor -%}
{%- endfor %}
Expand Down

0 comments on commit 8218a60

Please sign in to comment.