Skip to content

Commit 05bcf6f

Browse files
committed
feat: allow check_dependency_versions() to take any number of DependencyConstraints
1 parent 6338389 commit 05bcf6f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

google/api_core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
warn_deprecation_for_versions_less_than = (
3434
_python_package_support.warn_deprecation_for_versions_less_than
3535
)
36+
DependencyConstraint = _python_package_support.DependencyConstraint
3637

3738
# perform version checks against api_core, and emit warnings if needed
3839
check_python_version(package="google.api_core")

google/api_core/_python_package_support.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929

3030
# Here we list all the packages for which we want to issue warnings
3131
# about deprecated and unsupported versions.
32-
_DependencyConstraint = namedtuple(
33-
"_DependencyConstraint",
32+
DependencyConstraint = namedtuple(
33+
"DependencyConstraint",
3434
["package_name", "minimum_fully_supported_version", "recommended_version"],
3535
)
3636
_PACKAGE_DEPENDENCY_WARNINGS = [
37-
_DependencyConstraint(
37+
DependencyConstraint(
3838
"google.protobuf",
3939
minimum_fully_supported_version="4.25.8",
4040
recommended_version="6.x",
@@ -181,19 +181,26 @@ def warn_deprecation_for_versions_less_than(
181181
)
182182

183183

184-
def check_dependency_versions(consumer_import_package: str):
184+
def check_dependency_versions(
185+
consumer_import_package: str, *package_dependency_warnings: DependencyConstraint
186+
):
185187
"""Bundle checks for all package dependencies.
186188
187-
This function can be called by all dependents of google.api_core,
189+
This function can be called by all consumers of google.api_core,
188190
to emit needed deprecation warnings for any of their
189-
dependencies. The dependencies to check should be updated here.
191+
dependencies. The dependencies to check can be passed as arguments, or if
192+
none are provided, it will default to the list in
193+
`_PACKAGE_DEPENDENCY_WARNINGS`.
190194
191195
Args:
192196
consumer_import_package: The distribution name of the calling package, whose
193197
dependencies we're checking.
194-
198+
*package_dependency_warnings: A variable number of DependencyConstraint
199+
objects, each specifying a dependency to check.
195200
"""
196-
for package_info in _PACKAGE_DEPENDENCY_WARNINGS:
201+
if not package_dependency_warnings:
202+
package_dependency_warnings = tuple(_PACKAGE_DEPENDENCY_WARNINGS)
203+
for package_info in package_dependency_warnings:
197204
warn_deprecation_for_versions_less_than(
198205
consumer_import_package,
199206
package_info.package_name,

0 commit comments

Comments
 (0)