Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
feat!: migrate to microgenerator. (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 committed Jul 30, 2020
1 parent dd0c3db commit 605f757
Show file tree
Hide file tree
Showing 86 changed files with 18,138 additions and 11,308 deletions.
15 changes: 7 additions & 8 deletions .coveragerc
Expand Up @@ -14,22 +14,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Generated by synthtool. DO NOT EDIT!
[run]
branch = True

[report]
fail_under = 100
show_missing = True
omit =
google/cloud/kms/__init__.py
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
# Ignore debug-only repr
def __repr__
# Ignore abstract methods
raise NotImplementedError
omit =
*/gapic/*.py
*/proto/*.py
*/core/*.py
*/site-packages/*.py
# Ignore pkg_resources exceptions.
# This is added at the module level as a safeguard for if someone
# generates the code and tries to run it without pip installing. This
# makes it virtually impossible to test properly.
except pkg_resources.DistributionNotFound
6 changes: 4 additions & 2 deletions README.rst
Expand Up @@ -51,11 +51,13 @@ dependencies.

Supported Python Versions
^^^^^^^^^^^^^^^^^^^^^^^^^
Python >= 3.5
Python >= 3.6

Deprecated Python Versions
^^^^^^^^^^^^^^^^^^^^^^^^^^
Python == 2.7. Python 2.7 support will be removed on January 1, 2020.
Python == 2.7.

The last version of this library compatible with Python 2.7 is google-cloud-kms==1.4.0.


Mac/Linux
Expand Down
167 changes: 167 additions & 0 deletions UPGRADING.md
@@ -0,0 +1,167 @@
# 2.0.0 Migration Guide

The 2.0 release of the `google-cloud-kms` client is a significant upgrade based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-python), and includes substantial interface changes. Existing code written for earlier versions of this library will likely require updates to use this version. This document describes the changes that have been made, and what you need to do to update your usage.

If you experience issues or have questions, please file an [issue](https://github.com/googleapis/python-kms/issues).

## Supported Python Versions

> **WARNING**: Breaking change
The 2.0.0 release requires Python 3.6+.


## Method Calls

> **WARNING**: Breaking change
Methods expect request objects. We provide a script that will convert most common use cases.

* Install the library

```py
python3 -m pip install google-cloud-kms
```

* The script `fixup_kms_v1_keywords.py` is shipped with the library. It expects
an input directory (with the code to convert) and an empty destination directory.

```sh
$ fixup_kms_v1_keywords.py --input-directory .samples/ --output-directory samples/
```

**Before:**
```py
from google.cloud import kms

client = kms.KeyManagementServiceClient()
location_name = client.location_path(project_id, location_id)
key_ring = {}

created_key_ring = client.create_key_ring(location_name, id, key_ring)
```


**After:**
```py
from google.cloud import kms

client = kms.KeyManagementServiceClient()
location_name = f'projects/{project_id}/locations/{location_id}'
key_ring = {}

created_key_ring = client.create_key_ring(request={'parent': location_name, 'key_ring_id': id, 'key_ring': key_ring})
```

### More Details

In `google-cloud-kms<2.0.0`, parameters required by the API were positional parameters and optional parameters were keyword parameters.

**Before:**
```py
def create_key_ring(
self,
parent,
key_ring_id,
key_ring,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
```

In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a parameter is required or optional.

Some methods have additional keyword only parameters. The available parameters depend on the `google.api.method_signature` annotation specified by the API producer.


**After:**
```py
def create_key_ring(
self,
request: service.CreateKeyRingRequest = None,
*,
parent: str = None,
key_ring_id: str = None,
key_ring: resources.KeyRing = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> resources.KeyRing:
```

> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive.
> Passing both will result in an error.

Both of these calls are valid:

```py
response = client.create_key_ring(
request={
"parent": parent,
"key_ring_id": key_ring_id,
"key_ring": key_ring
}
)
```

```py
response = client.create_key_ring(
parent=parent,
key_ring_id=key_ring_id,
key_ring=key_ring
)
```

This call is invalid because it mixes `request` with a keyword argument `key_ring`. Executing this code
will result in an error.

```py
response = client.create_key_ring(
request={
"parent": parent,
"key_ring_id": key_ring_id,
},
key_ring=key_ring
)
```



## Enums and Types


> **WARNING**: Breaking change
The submodules `enums` and `types` have been removed.

**Before:**
```py

from google.cloud import kms

purpose = kms.enums.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_SIGN
key_ring = kms.types.KeyRing()
```


**After:**
```py
from google.cloud import kms

purpose = kms.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_SIGN
key_ring = kms.KeyRing()
```

## Resource Path Helper Methods

The resource path helper method `location_path` has been removed. Please construct
this path manually.

```py
project = 'my-project'
location = 'us-east1'

location_path = f'projects/{project}/locations/{location}'
```
1 change: 1 addition & 0 deletions docs/UPGRADING.md
4 changes: 2 additions & 2 deletions docs/_templates/layout.html
Expand Up @@ -21,8 +21,8 @@

<div class="body" role="main">
<div class="admonition" id="python2-eol">
On January 1, 2020 this library will no longer support Python 2 on the latest released version.
Previously released library versions will continue to be available. For more information please
As of January 1, 2020 this library no longer supports Python 2 on the latest released version.
Library versions released prior to that date will continue to be available. For more information please
visit <a href="https://cloud.google.com/python/docs/python2-sunset/">Python 2 support on Google Cloud</a>.
</div>
{% block body %} {% endblock %}
Expand Down
11 changes: 4 additions & 7 deletions docs/conf.py
Expand Up @@ -38,21 +38,18 @@
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"recommonmark",
]

# autodoc/autosummary flags
autoclass_content = "both"
autodoc_default_flags = ["members"]
autodoc_default_options = {"members": True}
autosummary_generate = True


# 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']
Expand Down Expand Up @@ -293,7 +290,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, "google-cloud-kms", u"google-cloud-kms Documentation", [author], 1)
(master_doc, "google-cloud-kms", u"google-cloud-kms Documentation", [author], 1,)
]

# If true, show URL addresses after external links.
Expand Down Expand Up @@ -334,7 +331,7 @@
intersphinx_mapping = {
"python": ("http://python.readthedocs.org/en/latest/", None),
"google-auth": ("https://google-auth.readthedocs.io/en/stable", None),
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None),
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
"grpc": ("https://grpc.io/grpc/python/", None),
}

Expand Down
6 changes: 0 additions & 6 deletions docs/gapic/v1/api.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/gapic/v1/types.rst

This file was deleted.

15 changes: 13 additions & 2 deletions docs/index.rst
Expand Up @@ -7,8 +7,19 @@ API Reference
.. toctree::
:maxdepth: 2

gapic/v1/api
gapic/v1/types
kms_v1/services
kms_v1/types


Migration Guide
---------------

See the guide below for instructions on migrating to the 2.x release of this library.

.. toctree::
:maxdepth: 2

UPGRADING


Changelog
Expand Down
6 changes: 6 additions & 0 deletions docs/kms_v1/services.rst
@@ -0,0 +1,6 @@
Services for Google Cloud Kms v1 API
====================================

.. automodule:: google.cloud.kms_v1.services.key_management_service
:members:
:inherited-members:
5 changes: 5 additions & 0 deletions docs/kms_v1/types.rst
@@ -0,0 +1,5 @@
Types for Google Cloud Kms v1 API
=================================

.. automodule:: google.cloud.kms_v1.types
:members:
25 changes: 0 additions & 25 deletions google/cloud/kms.py

This file was deleted.

0 comments on commit 605f757

Please sign in to comment.