Skip to content

Commit

Permalink
Update imports to be explicitly relative (#296)
Browse files Browse the repository at this point in the history
In python 3, imports are absolute by default. By adding from __future__ import absolute_import, we ensure that python 2 adopts this behavior too.
  • Loading branch information
jameslynnwu authored Jul 9, 2020
1 parent 7975c0c commit ca20945
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apitools/gen/extended_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ def PrintPreamble(self, package, version, file_descriptor):
self.__printer('# NOTE: This file is autogenerated and should not be '
'edited by hand.')
self.__printer()
self.__printer('from __future__ import absolute_import')
self.__printer()
self.__PrintAdditionalImports(file_descriptor.additional_imports)
self.__printer()
self.__printer("package = '%s'", file_descriptor.package)
Expand Down
4 changes: 3 additions & 1 deletion apitools/gen/gen_client_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,14 @@ def WriteInit(self, out):
else:
printer('"""Package marker file."""')
printer()
printer('from __future__ import absolute_import')
printer()
printer('import pkgutil')
printer()
if self.__init_wildcards_file:
printer('from %s import *', self.__base_files_package)
if self.__root_package == '.':
import_prefix = ''
import_prefix = '.'
else:
import_prefix = '%s.' % self.__root_package
printer('from %s%s import *',
Expand Down
2 changes: 2 additions & 0 deletions apitools/gen/gen_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def testGenClient_SimpleDocEmptyInit(self):
init_file = _GetContent(os.path.join(tmp_dir_path, '__init__.py'))
self.assertEqual("""\"""Package marker file.\"""
from __future__ import absolute_import
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
Expand Down
3 changes: 3 additions & 0 deletions apitools/gen/service_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ def WriteFile(self, printer):
client_info.package, client_info.version)
printer('# NOTE: This file is autogenerated and should not be edited '
'by hand.')
printer()
printer('from __future__ import absolute_import')
printer()
printer('from %s import base_api', self.__base_files_package)
if self.__root_package:
import_prefix = 'from {0} '.format(self.__root_package)
Expand Down
2 changes: 2 additions & 0 deletions samples/bigquery_sample/bigquery_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Package marker file."""

from __future__ import absolute_import

import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
3 changes: 3 additions & 0 deletions samples/bigquery_sample/bigquery_v2/bigquery_v2_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Generated client library for bigquery version v2."""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.py import base_api
from samples.bigquery_sample.bigquery_v2 import bigquery_v2_messages as messages

Expand Down
2 changes: 2 additions & 0 deletions samples/bigquery_sample/bigquery_v2/bigquery_v2_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.protorpclite import messages as _messages
from apitools.base.py import encoding
from apitools.base.py import extra_types
Expand Down
2 changes: 2 additions & 0 deletions samples/dns_sample/dns_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Package marker file."""

from __future__ import absolute_import

import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
3 changes: 3 additions & 0 deletions samples/dns_sample/dns_v1/dns_v1_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Generated client library for dns version v1."""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.py import base_api
from samples.dns_sample.dns_v1 import dns_v1_messages as messages

Expand Down
2 changes: 2 additions & 0 deletions samples/dns_sample/dns_v1/dns_v1_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.protorpclite import messages as _messages


Expand Down
2 changes: 2 additions & 0 deletions samples/fusiontables_sample/fusiontables_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Package marker file."""

from __future__ import absolute_import

import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Generated client library for fusiontables version v1."""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.py import base_api
from samples.fusiontables_sample.fusiontables_v1 import fusiontables_v1_messages as messages

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.protorpclite import messages as _messages
from apitools.base.py import extra_types

Expand Down
2 changes: 2 additions & 0 deletions samples/iam_sample/iam_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Package marker file."""

from __future__ import absolute_import

import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
3 changes: 3 additions & 0 deletions samples/iam_sample/iam_v1/iam_v1_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Generated client library for iam version v1."""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.py import base_api
from samples.iam_sample.iam_v1 import iam_v1_messages as messages

Expand Down
2 changes: 2 additions & 0 deletions samples/iam_sample/iam_v1/iam_v1_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.protorpclite import messages as _messages
from apitools.base.py import encoding

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Package marker file."""

from __future__ import absolute_import

import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Generated client library for servicemanagement version v1."""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.py import base_api
from samples.servicemanagement_sample.servicemanagement_v1 import servicemanagement_v1_messages as messages

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.protorpclite import messages as _messages
from apitools.base.py import encoding
from apitools.base.py import extra_types
Expand Down
2 changes: 2 additions & 0 deletions samples/storage_sample/storage_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Package marker file."""

from __future__ import absolute_import

import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
3 changes: 3 additions & 0 deletions samples/storage_sample/storage_v1/storage_v1_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Generated client library for storage version v1."""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.py import base_api
from samples.storage_sample.storage_v1 import storage_v1_messages as messages

Expand Down
2 changes: 2 additions & 0 deletions samples/storage_sample/storage_v1/storage_v1_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
# NOTE: This file is autogenerated and should not be edited by hand.

from __future__ import absolute_import

from apitools.base.protorpclite import message_types as _message_types
from apitools.base.protorpclite import messages as _messages
from apitools.base.py import encoding
Expand Down

0 comments on commit ca20945

Please sign in to comment.