Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Updates from GitHub PR
Browse files Browse the repository at this point in the history
* Use {} rather than dict()
* Use pkg_resources to load service config file
* Simplify format string for tracking header and change separator to
  ';' instead of '/'.
* Fix incorrect comment where "DNS" was used although "domain name"
  was meant

See:
  googleapis/google-cloud-python#1629

Pre-push hook installed.

Change-Id: I02c832dfcd34eed8f79338711d6e2d0e34cf0182
  • Loading branch information
geigerj committed Mar 21, 2016
1 parent e981c25 commit 5eeb9aa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
2 changes: 2 additions & 0 deletions vgen/src/main/java/io/gapi/vgen/py/PythonImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public PythonImportHandler(Interface service) {
// Add non-service-specific imports.
addImport(null,
PythonImport.create("os", PythonImport.ImportType.STDLIB));
addImport(null,
PythonImport.create("pkg_resources", PythonImport.ImportType.STDLIB));
addImport(null,
PythonImport.create("platform", PythonImport.ImportType.STDLIB));
addImport(null,
Expand Down
23 changes: 11 additions & 12 deletions vgen/src/main/resources/io/gapi/vgen/py/main.snip
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
@end

@private constantSection(service)
_CODE_GEN_NAME_VERSION = 'gapic-0.1.0'
_CODE_GEN_NAME_VERSION = 'gapic/0.1.0'

SERVICE_ADDRESS = '{@context.getServiceConfig.getServiceAddress(service)}'
"""The default address of the service."""
Expand Down Expand Up @@ -110,7 +110,7 @@
"""Constructor.

Args:
:keyword service_path: The DNS of the API remote host.
:keyword service_path: The domain name of the API remote host.
:type service_path: string
:keyword port: The port on which to connect to the remote host.
:type port: int
Expand Down Expand Up @@ -145,20 +145,19 @@
app_name = 'gax'
if app_version is None:
app_version = google.gax.__version__
bundling_override = bundling_override or dict()
retrying_override = retrying_override or dict()
config_filename = os.path.join(
os.path.dirname(__file__), '{@yamlFilename}.yaml')
with open(config_filename, 'r') as api_yaml:
self._defaults = api_callable.construct_settings(
yaml.load(api_yaml.read()), bundling_override, retrying_override,
config.STATUS_CODE_NAMES, timeout)
google_apis_agent = '{}-{}/{}/gax-{}/{}'.format(
bundling_override = bundling_override or {}
retrying_override = retrying_override or {}
client_config = pkg_resources.resource_string(
__name__, '{@yamlFilename}.yaml')
self._defaults = api_callable.construct_settings(
yaml.load(client_config), bundling_override, retrying_override,
config.STATUS_CODE_NAMES, timeout)
google_apis_agent = '{}/{};{};gax/{};python/{}'.format(
app_name,
app_version,
self._CODE_GEN_NAME_VERSION,
google.gax.__version__,
'python-{}'.format(platform.python_version())
platform.python_version()
)
self._headers = [('x-google-apis-agent', google_apis_agent)]
self.stub = config.create_stub(
Expand Down
24 changes: 12 additions & 12 deletions vgen/src/test/java/io/gapi/vgen/testdata/python_library.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# merge preserves those additions if the generated source changes.

import os
import pkg_resources
import platform

from google.gax import api_callable
Expand Down Expand Up @@ -51,7 +52,7 @@ class LibraryServiceApi(object):
Check out `cloud docs! <https://cloud.google.com/library/example/link>`_
"""

_CODE_GEN_NAME_VERSION = 'gapic-0.1.0'
_CODE_GEN_NAME_VERSION = 'gapic/0.1.0'

SERVICE_ADDRESS = 'library-example.googleapis.com'
"""The default address of the service."""
Expand Down Expand Up @@ -101,7 +102,7 @@ class LibraryServiceApi(object):
"""Constructor.

Args:
:keyword service_path: The DNS of the API remote host.
:keyword service_path: The domain name of the API remote host.
:type service_path: string
:keyword port: The port on which to connect to the remote host.
:type port: int
Expand Down Expand Up @@ -136,20 +137,19 @@ class LibraryServiceApi(object):
app_name = 'gax'
if app_version is None:
app_version = google.gax.__version__
bundling_override = bundling_override or dict()
retrying_override = retrying_override or dict()
config_filename = os.path.join(
os.path.dirname(__file__), 'library_service_api.yaml')
with open(config_filename, 'r') as api_yaml:
self._defaults = api_callable.construct_settings(
yaml.load(api_yaml.read()), bundling_override, retrying_override,
config.STATUS_CODE_NAMES, timeout)
google_apis_agent = '{}-{}/{}/gax-{}/{}'.format(
bundling_override = bundling_override or {}
retrying_override = retrying_override or {}
client_config = pkg_resources.resource_string(
__name__, 'library_service_api.yaml')
self._defaults = api_callable.construct_settings(
yaml.load(client_config), bundling_override, retrying_override,
config.STATUS_CODE_NAMES, timeout)
google_apis_agent = '{}/{};{};gax/{};python/{}'.format(
app_name,
app_version,
self._CODE_GEN_NAME_VERSION,
google.gax.__version__,
'python-{}'.format(platform.python_version())
platform.python_version()
)
self._headers = [('x-google-apis-agent', google_apis_agent)]
self.stub = config.create_stub(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# merge preserves those additions if the generated source changes.

import os
import pkg_resources
import platform

from google.gax import api_callable
Expand All @@ -35,7 +36,7 @@ from google.example.v1 import no_path_templates_pb2


class NoTemplatesServiceApi(object):
_CODE_GEN_NAME_VERSION = 'gapic-0.1.0'
_CODE_GEN_NAME_VERSION = 'gapic/0.1.0'

SERVICE_ADDRESS = 'no-path-templates.googleapis.com'
"""The default address of the service."""
Expand Down Expand Up @@ -63,7 +64,7 @@ class NoTemplatesServiceApi(object):
"""Constructor.

Args:
:keyword service_path: The DNS of the API remote host.
:keyword service_path: The domain name of the API remote host.
:type service_path: string
:keyword port: The port on which to connect to the remote host.
:type port: int
Expand Down Expand Up @@ -98,20 +99,19 @@ class NoTemplatesServiceApi(object):
app_name = 'gax'
if app_version is None:
app_version = google.gax.__version__
bundling_override = bundling_override or dict()
retrying_override = retrying_override or dict()
config_filename = os.path.join(
os.path.dirname(__file__), 'no_templates_service_api.yaml')
with open(config_filename, 'r') as api_yaml:
self._defaults = api_callable.construct_settings(
yaml.load(api_yaml.read()), bundling_override, retrying_override,
config.STATUS_CODE_NAMES, timeout)
google_apis_agent = '{}-{}/{}/gax-{}/{}'.format(
bundling_override = bundling_override or {}
retrying_override = retrying_override or {}
client_config = pkg_resources.resource_string(
__name__, 'no_templates_service_api.yaml')
self._defaults = api_callable.construct_settings(
yaml.load(client_config), bundling_override, retrying_override,
config.STATUS_CODE_NAMES, timeout)
google_apis_agent = '{}/{};{};gax/{};python/{}'.format(
app_name,
app_version,
self._CODE_GEN_NAME_VERSION,
google.gax.__version__,
'python-{}'.format(platform.python_version())
platform.python_version()
)
self._headers = [('x-google-apis-agent', google_apis_agent)]
self.stub = config.create_stub(
Expand Down

0 comments on commit 5eeb9aa

Please sign in to comment.