-
Notifications
You must be signed in to change notification settings - Fork 70
feat: add support for reading google.api.api_version #1999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d002b39
to
950e89b
Compare
🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use -- conventional-commit-lint bot |
bf409e6
to
816a2cf
Compare
5a57275
to
c61464c
Compare
c61464c
to
4e3138c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a review; I know this is a draft at the moment. Just a fly-by comment.
@@ -388,6 +391,12 @@ class {{ service.async_client_name }}: | |||
) | |||
{% endif %} | |||
|
|||
{% if service.version %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if we could call this code in the _client_macros.j2
file, so we reduce duplication. Maybe a separate macro call set_version_header(service.version)
, and the macro could take care of the conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 009fc71
… the one in googleads/google-ads-python
Co-authored-by: Victor Chudnovsky <[email protected]>
gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2
Show resolved
Hide resolved
api_core_major, api_core_minor = [int(part) for part in api_core_version.__version__.split(".")[0:2]] | ||
if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 19): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to guard our tests like this every time a new feature is dependent on a version of api-core
which is not the minimum version. This will also add a lot of toil for future clean up.
Instead, we should decide a generalized way of doing this and also keep track of the things that we need to clean up.
I would suggest using a helper function as a decorator for this. Something like:
def is_supported_version(major_version, minor_version):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
api_core_major, api_core_minor = [int(part) for part in api_core_version.__version__.split(".")[0:2]]
if api_core_major > major_version or (api_core_major == major_version and api_core_minor >= minor_version):
return func(*args, **kwargs)
else:
print("Skipping test due to unsupported version ...")
return wrapper
return decorator
Let me know what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good idea. See my related comment about being able to just have a helper function to get the version parts. The decorator could be done as part of that work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed #2023 to clean up the function as a follow up task so we don't block this PR indefinitely with improvements
@@ -24,6 +25,7 @@ from google.api_core import retry_async as retries | |||
from google.auth import credentials as ga_credentials # type: ignore | |||
from google.oauth2 import service_account # type: ignore | |||
|
|||
{{ shared_macros.add_google_api_core_version_header_import(service) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just pass down service.version
here? Same is true for add_api_version_header_to_metadata
if that's the only attribute we need from service for these two macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine. My comments are minor, except for the one about the intended symlink not yet being a symlink; it looks like a regular file (which means we have the same file duplicated).
except ImportError: # pragma: NO COVER | ||
HAS_GOOGLE_API_CORE_VERSION_HEADER = False | ||
#} | ||
{% if service.version %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not show up as a symlink; see comment below.
@@ -0,0 +1,69 @@ | |||
{# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regular file, not a symlink:
git ls-files -s gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_shared_macros.j2
100644 7094d3039af53ead4b844ba9952d7084f0526bd2 0 gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_shared_macros.j2
See the meaning of Git modes. (Credit: SO answer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch and thanks for the link! Fixed in 7957ded
(py39) partheniou@partheniou-vm-3:~/git/gapic-generator-python$ git ls-files -s gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_shared_macros.j2
120000 6884f2def889f3f4f2a5b19b54e76a52c2826174 0 gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_shared_macros.j2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the symlinks don't work (weird, they should), can you specify a template outside the current directory (something like {% include ../templates/foo/bar %}
If that also doesn't work, I would suggest keeping the duplicate files but adding a prominent header to the ads one saying that this is a copy of the one in the standard templates, intended to be a symlink. My rationale: we have duplicate code either way, and the macro file9s) makes them more organized....and it paves the way for the symlink once we can figure it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. You reverted back to the duplicate file, like I said in that last paragraph. SG. Could you add a note that this is intended to be a symlink to the other file, and for now is a duplicate?
gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2
Show resolved
Hide resolved
{{ shared_macros.add_google_api_core_version_header_import(service) }} | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need blank lines before and/or after?
{{ shared_macros.add_google_api_core_version_header_import(service) }} | |
try: | |
{{ shared_macros.add_google_api_core_version_header_import(service) }} | |
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied this change but reverted it in 16402e1 as it caused unnecessary blank lines to be added to the golden files as the import statements in shared_macros.add_google_api_core_version_header_import(service)
are guarded by conditional logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Hopefully the generated files are nicely formatted through all code paths.
api_core_major, api_core_minor = [int(part) for part in api_core_version.__version__.split(".")[0:2]] | ||
if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 19): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good idea. See my related comment about being able to just have a helper function to get the version parts. The decorator could be done as part of that work.
…ce/_shared_macros.j2 Co-authored-by: Victor Chudnovsky <[email protected]>
This reverts commit 7957ded.
…ce/client.py.j2 Co-authored-by: Victor Chudnovsky <[email protected]>
…s/%service/client.py.j2" This reverts commit 0f68169.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one suggestion to flag the intended symlink.
Thanks for working on this and responding to the review comments!
@@ -38,32 +38,32 @@ | |||
{% endwith %}{# method_settings #} | |||
{% endmacro %} | |||
|
|||
{% macro add_google_api_core_version_header_import(service) %} | |||
{% macro add_google_api_core_version_header_import(service_version) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a note at the top that this is intended to be a symlink to the other file, and for now is a duplicate (link to the issue you filed)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a62b313
Towards b/330968465