Skip to content

Commit

Permalink
Vision: Add nox session docs, reorder methods, modify samples in do…
Browse files Browse the repository at this point in the history
…cstrings (via synth). (#7787)
  • Loading branch information
yoshi-automation authored and busunkim96 committed Apr 30, 2019
1 parent d713950 commit bcfa1fa
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 46 deletions.
1 change: 1 addition & 0 deletions vision/docs/README.rst
44 changes: 39 additions & 5 deletions vision/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'
needs_sphinx = "1.6.3"

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand All @@ -36,6 +36,7 @@
"sphinx.ext.intersphinx",
"sphinx.ext.coverage",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
]

Expand All @@ -47,10 +48,14 @@
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# Allow markdown includes (so releases.md can include CHANGLEOG.md)
# http://www.sphinx-doc.org/en/master/markdown.html
source_parsers = {".md": "recommonmark.parser.CommonMarkParser"}

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
# source_suffix = ['.rst', '.md']
source_suffix = ".rst"
source_suffix = [".rst", ".md"]

# The encoding of source files.
# source_encoding = 'utf-8-sig'
Expand Down Expand Up @@ -120,12 +125,20 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = "sphinx_rtd_theme"
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
# html_theme_options = {}
html_theme_options = {
"description": "Google Cloud Client Libraries for Python",
"github_user": "googleapis",
"github_repo": "google-cloud-python",
"github_banner": True,
"font_family": "'Roboto', Georgia, sans",
"head_font_family": "'Roboto', Georgia, serif",
"code_font_family": "'Roboto Mono', 'Consolas', monospace",
}

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
Expand Down Expand Up @@ -214,6 +227,17 @@
# Output file base name for HTML help builder.
htmlhelp_basename = "google-cloud-vision-doc"

# -- Options for warnings ------------------------------------------------------

suppress_warnings = [
# Temporarily suppress this to avoid "more than one target found for
# cross-reference" warning, which are intractable for us to avoid while in
# a mono-repo.
# See https://github.com/sphinx-doc/sphinx/blob
# /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843
"ref.python"
]

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
Expand Down Expand Up @@ -289,7 +313,7 @@
u"google-cloud-vision Documentation",
author,
"google-cloud-vision",
"GAPIC library for the {metadata.shortName} v1 service",
"GAPIC library for the {metadata.shortName} v1p3beta1 service",
"APIs",
)
]
Expand All @@ -310,6 +334,16 @@
intersphinx_mapping = {
"python": ("http://python.readthedocs.org/en/latest/", None),
"gax": ("https://gax-python.readthedocs.org/en/latest/", None),
"google-auth": ("https://google-auth.readthedocs.io/en/stable", None),
"google-gax": ("https://gax-python.readthedocs.io/en/latest/", None),
"google.api_core": (
"https://googleapis.github.io/google-cloud-python/latest",
None,
),
"grpc": ("https://grpc.io/grpc/python/", None),
"requests": ("http://docs.python-requests.org/en/master/", None),
"fastavro": ("https://fastavro.readthedocs.io/en/stable/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
}

# Napoleon settings
Expand Down
2 changes: 1 addition & 1 deletion vision/docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. include:: /../vision/README.rst
.. include:: README.rst

Using the Library
-----------------
Expand Down
24 changes: 10 additions & 14 deletions vision/google/cloud/vision_v1/gapic/product_search_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ def location_path(cls, project, location):
)

@classmethod
def product_set_path(cls, project, location, product_set):
"""Return a fully-qualified product_set string."""
def product_path(cls, project, location, product):
"""Return a fully-qualified product string."""
return google.api_core.path_template.expand(
"projects/{project}/locations/{location}/productSets/{product_set}",
"projects/{project}/locations/{location}/products/{product}",
project=project,
location=location,
product_set=product_set,
product=product,
)

@classmethod
def product_path(cls, project, location, product):
"""Return a fully-qualified product string."""
def product_set_path(cls, project, location, product_set):
"""Return a fully-qualified product_set string."""
return google.api_core.path_template.expand(
"projects/{project}/locations/{location}/products/{product}",
"projects/{project}/locations/{location}/productSets/{product_set}",
project=project,
location=location,
product=product,
product_set=product_set,
)

@classmethod
Expand Down Expand Up @@ -1522,9 +1522,7 @@ def add_product_to_product_set(
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.product_set_path('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]')
>>>
>>> # TODO: Initialize `product`:
>>> product = ''
>>> product = client.product_path('[PROJECT]', '[LOCATION]', '[PRODUCT]')
>>>
>>> client.add_product_to_product_set(name, product)
Expand Down Expand Up @@ -1604,9 +1602,7 @@ def remove_product_from_product_set(
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.product_set_path('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]')
>>>
>>> # TODO: Initialize `product`:
>>> product = ''
>>> product = client.product_path('[PROJECT]', '[LOCATION]', '[PRODUCT]')
>>>
>>> client.remove_product_from_product_set(name, product)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ def location_path(cls, project, location):
)

@classmethod
def product_set_path(cls, project, location, product_set):
"""Return a fully-qualified product_set string."""
def product_path(cls, project, location, product):
"""Return a fully-qualified product string."""
return google.api_core.path_template.expand(
"projects/{project}/locations/{location}/productSets/{product_set}",
"projects/{project}/locations/{location}/products/{product}",
project=project,
location=location,
product_set=product_set,
product=product,
)

@classmethod
def product_path(cls, project, location, product):
"""Return a fully-qualified product string."""
def product_set_path(cls, project, location, product_set):
"""Return a fully-qualified product_set string."""
return google.api_core.path_template.expand(
"projects/{project}/locations/{location}/products/{product}",
"projects/{project}/locations/{location}/productSets/{product_set}",
project=project,
location=location,
product=product,
product_set=product_set,
)

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ def location_path(cls, project, location):
)

@classmethod
def product_set_path(cls, project, location, product_set):
"""Return a fully-qualified product_set string."""
def product_path(cls, project, location, product):
"""Return a fully-qualified product string."""
return google.api_core.path_template.expand(
"projects/{project}/locations/{location}/productSets/{product_set}",
"projects/{project}/locations/{location}/products/{product}",
project=project,
location=location,
product_set=product_set,
product=product,
)

@classmethod
def product_path(cls, project, location, product):
"""Return a fully-qualified product string."""
def product_set_path(cls, project, location, product_set):
"""Return a fully-qualified product_set string."""
return google.api_core.path_template.expand(
"projects/{project}/locations/{location}/products/{product}",
"projects/{project}/locations/{location}/productSets/{product_set}",
project=project,
location=location,
product=product,
product_set=product_set,
)

@classmethod
Expand Down
20 changes: 20 additions & 0 deletions vision/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from __future__ import absolute_import
import os
import shutil

import nox

Expand Down Expand Up @@ -139,3 +140,22 @@ def cover(session):
session.run("coverage", "report", "--show-missing", "--fail-under=100")

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')

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', ''),
)
12 changes: 6 additions & 6 deletions vision/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"updateTime": "2019-03-28T12:31:01.635998Z",
"updateTime": "2019-04-23T12:38:11.773939Z",
"sources": [
{
"generator": {
"name": "artman",
"version": "0.16.20",
"dockerImage": "googleapis/artman@sha256:e3c054a2fb85a12481c722af616c7fb6f1d02d862248385eecbec3e4240ebd1e"
"version": "0.17.0",
"dockerImage": "googleapis/artman@sha256:c58f4ec3838eb4e0718eb1bccc6512bd6850feaa85a360a9e38f6f848ec73bc2"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "6a84b3267b0a95e922608b9891219075047eee29",
"internalRef": "240640999"
"sha": "547e19e7df398e9290e8e3674d7351efc500f9b0",
"internalRef": "244712781"
}
},
{
"template": {
"name": "python_library",
"origin": "synthtool.gcp",
"version": "2019.2.26"
"version": "2019.4.10"
}
}
],
Expand Down
3 changes: 3 additions & 0 deletions vision/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
f"class ImageAnnotatorClient(VisionHelpers, iac.ImageAnnotatorClient):",
)

# Move docs configuration
s.move(library / f"docs/conf.py")

# Fix import of operations
targets = ["google/cloud/vision_*/**/*.py", "tests/system/gapic/*/**/*.py"]
s.replace(
Expand Down
8 changes: 4 additions & 4 deletions vision/tests/unit/gapic/v1/test_product_search_client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def test_add_product_to_product_set(self):

# Setup Request
name = client.product_set_path("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]")
product = "product-309474065"
product = client.product_path("[PROJECT]", "[LOCATION]", "[PRODUCT]")

client.add_product_to_product_set(name, product)

Expand All @@ -698,7 +698,7 @@ def test_add_product_to_product_set_exception(self):

# Setup request
name = client.product_set_path("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]")
product = "product-309474065"
product = client.product_path("[PROJECT]", "[LOCATION]", "[PRODUCT]")

with pytest.raises(CustomException):
client.add_product_to_product_set(name, product)
Expand All @@ -712,7 +712,7 @@ def test_remove_product_from_product_set(self):

# Setup Request
name = client.product_set_path("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]")
product = "product-309474065"
product = client.product_path("[PROJECT]", "[LOCATION]", "[PRODUCT]")

client.remove_product_from_product_set(name, product)

Expand All @@ -733,7 +733,7 @@ def test_remove_product_from_product_set_exception(self):

# Setup request
name = client.product_set_path("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]")
product = "product-309474065"
product = client.product_path("[PROJECT]", "[LOCATION]", "[PRODUCT]")

with pytest.raises(CustomException):
client.remove_product_from_product_set(name, product)
Expand Down

0 comments on commit bcfa1fa

Please sign in to comment.