-
Notifications
You must be signed in to change notification settings - Fork 73
feat: check Python and dependency versions in generated GAPICs #2419
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
base: main
Are you sure you want to change the base?
Changes from all commits
cac8d87
20ea9b3
e970c07
9b2d7cd
e132cca
34705c6
51a8b5e
baefecb
ad55260
ff52e49
b29ad98
b90eb09
6ea418b
9c9db92
c72b272
d1a4a3e
11a1f16
67e731d
0bf1c15
8942f0c
316ea57
81a7379
08598d0
fbab30f
6e548f0
b1aea7a
de880d9
cb164fb
be23134
406f48d
5f4bb03
cd3fcae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,85 @@ | |
| __version__ = package_version.__version__ | ||
|
|
||
|
|
||
| import google.api_core as api_core | ||
|
|
||
| if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER | ||
| api_core.check_python_version("google.cloud.asset_v1") # type: ignore | ||
| api_core.check_dependency_versions("google.cloud.asset_v1") # type: ignore | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intent was to have each package issue a warning saying it would soon stop getting updated if the specified dependencies were pinned to old versions. I guess when this PR started as a prototype PR, I was thinking that the dependencies in question were the same for both packages, so we would re-use the warnings. But I think there's a lot of merit to what you're suggesting: each of our artifacts sets up the warning message for its direct, not transitive, dependencies. Update: I updated googleapis/python-api-core#832 so we could pass the list of dependencies. If none are given, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome, that seems like a great change! |
||
| else: # pragma: NO COVER | ||
| # An older version of api_core is installed which does not define the | ||
| # functions above. We do equivalent checks manually. | ||
| try: | ||
| import warnings | ||
| import sys | ||
|
|
||
| _py_version_str = sys.version.split()[0] | ||
| _package_label = "google.cloud.asset_v1" | ||
| if sys.version_info < (3, 9): | ||
| warnings.warn("You are using a non-supported Python version " + | ||
| f"({_py_version_str}). Google will not post any further " + | ||
| f"updates to {_package_label} supporting this Python version. " + | ||
| "Please upgrade to the latest Python version, or at " + | ||
| f"least to Python 3.9, and then update {_package_label}.", | ||
| FutureWarning) | ||
| if sys.version_info[:2] == (3, 9): | ||
| warnings.warn(f"You are using a Python version ({_py_version_str}) " + | ||
| f"which Google will stop supporting in {_package_label} in " + | ||
| "January 2026. Please " + | ||
| "upgrade to the latest Python version, or at " + | ||
| "least to Python 3.10, before then, and " + | ||
| f"then update {_package_label}.", | ||
| FutureWarning) | ||
|
|
||
| from packaging.version import parse as parse_version | ||
|
|
||
| if sys.version_info < (3, 8): | ||
| import pkg_resources | ||
|
|
||
| def _get_version(dependency_name): | ||
| try: | ||
| version_string = pkg_resources.get_distribution(dependency_name).version | ||
| return (parse_version(version_string), version_string) | ||
| except pkg_resources.DistributionNotFound: | ||
| return (None, "--") | ||
| else: | ||
| from importlib import metadata | ||
|
|
||
| def _get_version(dependency_name): | ||
| try: | ||
| version_string = metadata.version("requests") | ||
| parsed_version = parse_version(version_string) | ||
| return (parsed_version.release, version_string) | ||
| except metadata.PackageNotFoundError: | ||
| return (None, "--") | ||
|
|
||
| _dependency_package = "google.protobuf" | ||
| _next_supported_version = "4.25.8" | ||
| _next_supported_version_tuple = (4, 25, 8) | ||
| _recommendation = " (we recommend 6.x)" | ||
| (_version_used, _version_used_string) = _get_version(_dependency_package) | ||
| if _version_used and _version_used < _next_supported_version_tuple: | ||
| warnings.warn(f"Package {_package_label} depends on " + | ||
| f"{_dependency_package}, currently installed at version " + | ||
| f"{_version_used_string}. Future updates to " + | ||
| f"{_package_label} will require {_dependency_package} at " + | ||
| f"version {_next_supported_version} or higher{_recommendation}." + | ||
| " Please ensure " + | ||
| "that either (a) your Python environment doesn't pin the " + | ||
| f"version of {_dependency_package}, so that updates to " + | ||
| f"{_package_label} can require the higher version, or " + | ||
| "(b) you manually update your Python environment to use at " + | ||
| f"least version {_next_supported_version} of " + | ||
| f"{_dependency_package}.", | ||
| FutureWarning) | ||
| except Exception: | ||
| warnings.warn("Could not determine the version of Python " + | ||
| "currently being used. To continue receiving " + | ||
| "updates for {_package_label}, ensure you are " + | ||
| "using a supported version of Python; see " + | ||
| "https://devguide.python.org/versions/") | ||
|
|
||
|
|
||
| from .services.asset_service import AssetServiceClient | ||
| from .services.asset_service import AssetServiceAsyncClient | ||
|
|
||
|
|
||
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 to make sure I understand: we expect to see duplicate warnings for each GCP library and api_core, right?
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 exactly duplicate; just very similar, one for each of our packages losing support for the Python version currently being used. Paraphrasing the exact wording, here's an example: