Skip to content

Commit fda4b75

Browse files
committed
chore: fix comments and exported function
1 parent 417064d commit fda4b75

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

google/api_core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@
3232

3333
check_dependency_versions = _python_package_support.check_dependency_versions
3434
check_dependency_versions("google.api_core")
35+
36+
warn_deprecation_for_versions_less_than = _python_package_support.warn_deprecation_for_versions_less_than

google/api_core/_python_package_support.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
_get_distribution_and_import_packages,
2323
)
2424

25-
# It is a good practice to alias the Version class for clarity in type hints.
2625
from packaging.version import parse as parse_version, Version as PackagingVersion
2726

2827

@@ -72,24 +71,28 @@ def warn_deprecation_for_versions_less_than(
7271
`next_supported_version`, this issues a warning using either a
7372
default `message_template` or one provided by the user. The
7473
default `message_template` informs the user that they will not receive
75-
future updates `dependent_import_package` if
74+
future updates for `dependent_import_package` if
7675
`dependency_import_package` is somehow pinned to a version lower
7776
than `next_supported_version`.
7877
7978
Args:
8079
dependent_import_package: The import name of the package that
8180
needs `dependency_import_package`.
8281
dependency_import_package: The import name of the dependency to check.
83-
next_supported_version: The version number below which a deprecation
84-
warning will be logged.
82+
next_supported_version: The dependency_import_package version number
83+
below which a deprecation warning will be logged.
8584
message_template: A custom default message template to replace
8685
the default. This `message_template` is treated as an
8786
f-string, where the following variables are defined:
8887
`dependency_import_package`, `dependent_import_package` and
89-
`dependency_package`, `dependent_package`, which contain both the
90-
import and distribution packages for the dependency and the dependent,
91-
respectively; and `next_supported_version` and `version_used`, which
92-
refer to supported and currently-used versions of the dependency.
88+
`dependency_distribution_package` and
89+
`dependent_distribution_package` and `dependency_package`,
90+
`dependent_package` , which contain the import packages, the
91+
distribution packages, and pretty string with both the
92+
distribution and import packages for the dependency and the
93+
dependent, respectively; and `next_supported_version` and
94+
`version_used`, which refer to supported and currently-used
95+
versions of the dependency.
9396
9497
"""
9598
if (
@@ -129,6 +132,8 @@ def warn_deprecation_for_versions_less_than(
129132
message_template.format(
130133
dependent_import_package=dependent_import_package,
131134
dependency_import_package=dependency_import_package,
135+
dependent_distribution_package=dependent_distribution_package,
136+
dependency_distribution_package=dependency_distribution_package,
132137
dependency_package=dependency_package,
133138
dependent_package=dependent_package,
134139
next_supported_version=next_supported_version,

google/api_core/_python_version_support.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ class VersionInfo(NamedTuple):
9696

9797

9898
def _flatten_message(text: str) -> str:
99-
"""Dedent a multi-line string and flattens it into a single line."""
99+
"""Dedent a multi-line string and flatten it into a single line."""
100100
return textwrap.dedent(text).strip().replace("\n", " ")
101101

102102

103-
# TODO: Remove once we no longer support Python 3.7
103+
# TODO(https://github.com/googleapis/python-api-core/issues/835): Remove once we
104+
# no longer support Python 3.7
104105
if sys.version_info < (3, 8):
105106

106107
def _get_pypi_package_name(module_name): # pragma: NO COVER

tests/unit/test_python_package_support.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
)
2525

2626

27+
# TODO(https://github.com/googleapis/python-api-core/issues/835): Remove
28+
# this mark once we drop support for Python 3.7
2729
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
2830
@patch("importlib.metadata.version")
2931
def test_get_dependency_version_py38_plus(mock_version):
@@ -37,6 +39,8 @@ def test_get_dependency_version_py38_plus(mock_version):
3739
assert get_dependency_version("not-a-package") is None
3840

3941

42+
# TODO(https://github.com/googleapis/python-api-core/issues/835): Remove
43+
# this test function once we drop support for Python 3.7
4044
@pytest.mark.skipif(sys.version_info >= (3, 8), reason="requires python3.7")
4145
@patch("pkg_resources.get_distribution")
4246
def test_get_dependency_version_py37(mock_get_distribution):

tests/unit/test_python_version_support.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ def test_override_gapic_end_only():
162162
"google.api_core._python_version_support.PYTHON_VERSION_INFO",
163163
{version_tuple: overridden_info},
164164
):
165+
result_before_boundary = check_python_version(
166+
today=custom_gapic_end + datetime.timedelta(days=-1))
167+
assert result_before_boundary == PythonVersionStatus.PYTHON_VERSION_DEPRECATED
168+
165169
result_at_boundary = check_python_version(today=custom_gapic_end)
166170
assert result_at_boundary == PythonVersionStatus.PYTHON_VERSION_EOL
167171

@@ -221,7 +225,7 @@ def test_untracked_older_version_is_unsupported():
221225

222226
def test_untracked_newer_version_is_supported():
223227
"""Test that a new, untracked version is supported and does not log."""
224-
mock_py_version = VersionInfoMock(major=4, minor=0)
228+
mock_py_version = VersionInfoMock(major=40, minor=0)
225229

226230
with patch(
227231
"google.api_core._python_version_support.sys.version_info", mock_py_version

0 commit comments

Comments
 (0)