Skip to content

Commit

Permalink
Add get_grafeas_client method. (#8381)
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 authored Jun 19, 2019
1 parent 387b8e5 commit 26752c6
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
from google.iam.v1 import policy_pb2


from grafeas import grafeas_v1
from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport

_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution(
"google-cloud-containeranalysis"
).version
Expand Down Expand Up @@ -194,6 +197,18 @@ def __init__(
# timeout, and the like.
self._inner_api_calls = {}

def get_grafeas_client(self):
"""Returns an equivalent grafeas client.
Returns:
A :class:`~grafeas.grafeas_v1.GrafeasClient` instance.
"""
grafeas_transport = grafeas_grpc_transport.GrafeasGrpcTransport(
self.SERVICE_ADDRESS, self.transport._OAUTH_SCOPES
)

return grafeas_v1.GrafeasClient(grafeas_transport)

# Service calls
def set_iam_policy(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option go_package = "google.golang.org/genproto/googleapis/devtools/containerana
option java_multiple_files = true;
option java_package = "com.google.containeranalysis.v1";
option objc_class_prefix = "GCA";
option ruby_package = "Google::Cloud::ContainerAnalysis::V1";

// Retrieves analysis results of Cloud components such as Docker container
// images. The Container Analysis API is an implementation of the
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 24 additions & 26 deletions containeranalysis/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))

BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]

if os.path.exists("samples"):
BLACK_PATHS.append("samples")


@nox.session(python="3.7")
def lint(session):
"""Run linters.
Expand All @@ -31,13 +37,7 @@ def lint(session):
serious code quality issues.
"""
session.install("flake8", "black", *LOCAL_DEPS)
session.run(
"black",
"--check",
"google",
"tests",
"docs",
)
session.run("black", "--check", *BLACK_PATHS)
session.run("flake8", "google", "tests")


Expand All @@ -46,18 +46,13 @@ def blacken(session):
"""Run black.
Format code to uniform standard.
This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
That run uses an image that doesn't have 3.6 installed. Before updating this
check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
"""
session.install("black")
session.run(
"black",
"google",
"tests",
"docs",
)
session.run("black", *BLACK_PATHS)


@nox.session(python="3.7")
Expand All @@ -83,7 +78,7 @@ def default(session):
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=51",
"--cov-fail-under=0",
os.path.join("tests", "unit"),
*session.posargs,
)
Expand Down Expand Up @@ -140,21 +135,24 @@ def cover(session):

session.run("coverage", "erase")


@nox.session(python="3.7")
def docs(session):
"""Build the docs for this library."""

session.install('-e', '.')
session.install('sphinx', 'alabaster', 'recommonmark')
session.install("-e", ".")
session.install("sphinx", "alabaster", "recommonmark")

shutil.rmtree(os.path.join('docs', '_build'), ignore_errors=True)
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
'sphinx-build',
'-W', # warnings as errors
'-T', # show full traceback on exception
'-N', # no colors
'-b', 'html',
'-d', os.path.join('docs', '_build', 'doctrees', ''),
os.path.join('docs', ''),
os.path.join('docs', '_build', 'html', ''),
"sphinx-build",
"-W", # warnings as errors
"-T", # show full traceback on exception
"-N", # no colors
"-b",
"html",
"-d",
os.path.join("docs", "_build", "doctrees", ""),
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
)
65 changes: 32 additions & 33 deletions containeranalysis/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,60 @@
import setuptools



name = 'google-cloud-containeranalysis'
description = 'Container Analysis API API client library'
version = '0.1.0'
release_status = '3 - Alpha'
name = "google-cloud-containeranalysis"
description = "Container Analysis API API client library"
version = "0.1.0"
release_status = "3 - Alpha"
dependencies = [
'google-api-core[grpc] >= 1.4.1, < 2.0.0dev',
'grpc-google-iam-v1 >= 0.11.1, < 0.12dev',
'enum34; python_version < "3.4"',
"google-api-core[grpc] >= 1.4.1, < 2.0.0dev",
"grpc-google-iam-v1 >= 0.11.1, < 0.12dev",
'enum34; python_version < "3.4"',
"grafeas",
]



package_root = os.path.abspath(os.path.dirname(__file__))

readme_filename = os.path.join(package_root, 'README.rst')
with io.open(readme_filename, encoding='utf-8') as readme_file:
readme_filename = os.path.join(package_root, "README.rst")
with io.open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()

packages = [
package for package in setuptools.find_packages()
if package.startswith('google')]
package for package in setuptools.find_packages() if package.startswith("google")
]

namespaces = ['google']
if 'google.cloud' in packages:
namespaces.append('google.cloud')
namespaces = ["google"]
if "google.cloud" in packages:
namespaces.append("google.cloud")


setuptools.setup(
name=name,
version=version,
description=description,
long_description=readme,
author='Google LLC',
author_email='googleapis-packages@google.com',
license='Apache 2.0',
url='https://github.com/googleapis/google-cloud-python',
author="Google LLC",
author_email="googleapis-packages@google.com",
license="Apache 2.0",
url="https://github.com/googleapis/google-cloud-python",
classifiers=[
release_status,
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Operating System :: OS Independent',
'Topic :: Internet',
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Operating System :: OS Independent",
"Topic :: Internet",
],
platforms='Posix; MacOS X; Windows',
platforms="Posix; MacOS X; Windows",
packages=packages,
namespace_packages=namespaces,
install_requires=dependencies,
include_package_data=True,
zip_safe=False,
)
)
10 changes: 5 additions & 5 deletions containeranalysis/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"updateTime": "2019-06-05T22:45:41.734439Z",
"updateTime": "2019-06-18T00:23:56.692141Z",
"sources": [
{
"generator": {
"name": "artman",
"version": "0.23.1",
"dockerImage": "googleapis/artman@sha256:9d5cae1454da64ac3a87028f8ef486b04889e351c83bb95e83b8fab3959faed0"
"version": "0.26.0",
"dockerImage": "googleapis/artman@sha256:6db0735b0d3beec5b887153a2a7c7411fc7bb53f73f6f389a822096bd14a3a15"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "5487c78983f6bd5bbafa69166593826a90778a2f",
"internalRef": "251716150"
"sha": "384aa843867c4d17756d14a01f047b6368494d32",
"internalRef": "253675319"
}
},
{
Expand Down
33 changes: 32 additions & 1 deletion containeranalysis/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,43 @@
include_protos=True,
)

excludes = ["nox.py", "setup.py", "google/cloud/containeranalysis_v1/proto"]
excludes = ["nox.py", "setup.py", "google/cloud/containeranalysis_v1/proto", "README.rst", "docs/index.rst"]

s.move(library, excludes=excludes)
# .proto files end up in the wrong place by default
s.move(library / "google/cloud/containeranalysis_v1/proto", "google/cloud/devtools/containeranalysis_v1/proto")


# Insert helper method to get grafeas client
s.replace("google/**/container_analysis_client.py",
r"""_GAPIC_LIBRARY_VERSION = pkg_resources\.get_distribution\(
'google-cloud-containeranalysis',
\)\.version""",
r"""from grafeas import grafeas_v1
from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport
_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution(
"google-cloud-containeranalysis"
).version
""")

s.replace("google/**/container_analysis_client.py",
r''' \# Service calls
def set_iam_policy\(''',
r''' def get_grafeas_client(self):
"""Returns an equivalent grafeas client.
Returns:
A :class:`~grafeas.grafeas_v1.GrafeasClient` instance.
"""
grafeas_transport = grafeas_grpc_transport.GrafeasGrpcTransport(
self.SERVICE_ADDRESS,
self.transport._OAUTH_SCOPES)
return grafeas_v1.GrafeasClient(grafeas_transport)
# Service calls
def set_iam_policy(''')
# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
Expand Down

0 comments on commit 26752c6

Please sign in to comment.