Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6316d70
feat: provide Python run-time version support
vchudnov-g Jul 29, 2025
a136ad7
feat: apply Python version suport warnings to api_core
vchudnov-g Jul 29, 2025
45cd647
feat: add deprecation check for the protobuf package
vchudnov-g Jul 30, 2025
25225fa
format files
vchudnov-g Jul 30, 2025
1d567c0
fix lint warning
vchudnov-g Jul 30, 2025
f1dbbb4
add docstring to `warn_deprecation_for_versions_less_than`
vchudnov-g Jul 30, 2025
e3fd56f
Add/fix docstrings
vchudnov-g Jul 30, 2025
8b1dfb1
fix typo
vchudnov-g Jul 31, 2025
4b9208e
add test for _python_package_support.py
vchudnov-g Jul 31, 2025
5cf8652
add constants for various buffer periods
vchudnov-g Jul 31, 2025
7d8b1c7
Update warning code to only require import package names
vchudnov-g Jul 31, 2025
cda8e27
Fix messaegs and test
vchudnov-g Jul 31, 2025
db92fac
Add TODO: provide the functionality in previous versions of api_core
vchudnov-g Jul 31, 2025
118a7c8
Fix mypy failures
vchudnov-g Aug 12, 2025
f1c46aa
Try to remove a round-off error causing a test mock failure
vchudnov-g Aug 12, 2025
474ec0d
Remove more potential test failures/warnings
vchudnov-g Aug 12, 2025
2083b49
Format
vchudnov-g Aug 12, 2025
4ea124e
Try making the specified_timeout a float
vchudnov-g Aug 12, 2025
c5949c4
fix: tweak message parameter names
vchudnov-g Sep 3, 2025
6fc1473
fix: add PYTHON_VERSION_STATUS_UNSPECIFIED enum value
vchudnov-g Sep 3, 2025
8829e20
docs: tweak TODOs
vchudnov-g Sep 3, 2025
bdb6260
fix test to match code changes
vchudnov-g Sep 3, 2025
7896664
fix: restore asyncio designator for async tests
vchudnov-g Sep 4, 2025
54a5611
Remove some workarounds trying to fix presubmit errors (since fixed)
vchudnov-g Sep 5, 2025
2e2990b
Additional test tweaks to prevent non-significant failures
vchudnov-g Sep 5, 2025
35a2074
chore: fix test that was waiting before initiating operation
vchudnov-g Sep 5, 2025
cd64832
fix: skip coverage checks for code specific to Pyton 3.7
vchudnov-g Sep 5, 2025
e36414a
chore: try to address coverage failures
vchudnov-g Sep 8, 2025
b6245ca
chore: try to address more coverage failures
vchudnov-g Sep 8, 2025
3a897ba
chore: fix comments and exported function
vchudnov-g Sep 9, 2025
814ea63
fix lint
vchudnov-g Sep 9, 2025
8dee04b
chore: fix unit test
vchudnov-g Sep 9, 2025
95f4777
chore: lint
vchudnov-g Sep 9, 2025
a34ec15
Use warnings module instead of logging module
vchudnov-g Sep 10, 2025
a04e2e6
fix: print the current package versions correctly
vchudnov-g Sep 15, 2025
8b3f337
wip: before gemini doc fixes
vchudnov-g Sep 15, 2025
29896cf
fix: return tuple of version tuple and version string, fix tests
vchudnov-g Sep 16, 2025
d421f98
lint
vchudnov-g Sep 22, 2025
ac76f7a
feat: add grace period for 3.9; tweak warning
vchudnov-g Oct 1, 2025
e093a96
lint
vchudnov-g Oct 1, 2025
187f848
allow providing a recommended version
vchudnov-g Oct 1, 2025
b575a16
refactor: used namedtuple
vchudnov-g Oct 13, 2025
ecb7211
refactor: s/"--"/UNKNOWN_VERSION_STRING/ in code, not test
vchudnov-g Oct 13, 2025
3c587cf
refactor s/next_supported_version/minimum_fully_supported_version/
vchudnov-g Oct 13, 2025
fbe0f0b
refactor: s/dependent_/consumer_/
vchudnov-g Oct 13, 2025
28b0b32
refactor: add _PACKAGE_DEPENDENCY_WARNINGS
vchudnov-g Oct 13, 2025
21c9aec
refactor: reorder and comment on _init__ statements for clarity
vchudnov-g Oct 13, 2025
e24c13d
fix: exapnd VersionInfo with version field; clarify fake dates
vchudnov-g Oct 13, 2025
dbc3a26
doc: document PythonVersionSupportStatus
vchudnov-g Oct 13, 2025
d472bae
refactor: make fake past and future versions into constants
vchudnov-g Oct 14, 2025
0550f83
refactor: reword default string for min_python
vchudnov-g Oct 14, 2025
491b695
fix: fix populating PYTHON_VERSION_INFO
vchudnov-g Oct 14, 2025
6338389
fix: type hints
vchudnov-g Oct 14, 2025
05bcf6f
feat: allow check_dependency_versions() to take any number of Depende…
vchudnov-g Oct 17, 2025
fc224b7
add unit test to satisfy coverage requirement
vchudnov-g Oct 17, 2025
a6c40ce
fix lint
vchudnov-g Oct 17, 2025
d0414b2
fix lint
vchudnov-g Oct 17, 2025
835df53
test: add test for _flatten_message
vchudnov-g Oct 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: apply Python version suport warnings to api_core
  • Loading branch information
vchudnov-g committed Oct 23, 2025
commit a136ad731c15eae1cdbf04cf7b91939b774e38dd
1 change: 1 addition & 0 deletions google/api_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@

__version__ = api_core_version.__version__
check_python_version = _python_version_support.check_python_version
check_python_version(package="package google-api-core (google.api_core)")
28 changes: 14 additions & 14 deletions google/api_core/_python_version_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class VersionInfo(NamedTuple):
python_beta: Optional[datetime.date]
python_start: datetime.date
python_eol: datetime.date
gapic_start: Optional[datetime.date] = None
gapic_start: Optional[datetime.date] = None # unused
gapic_deprecation: Optional[datetime.date] = None
gapic_end: Optional[datetime.date] = None
dep_unpatchable_cve: Optional[datetime.date] = None
dep_unpatchable_cve: Optional[datetime.date] = None # unused


PYTHON_VERSION_INFO: Dict[Tuple[int, int], VersionInfo] = {
Expand Down Expand Up @@ -97,7 +97,8 @@ def _flatten_message(text: str) -> str:
return textwrap.dedent(text).strip().replace("\n", " ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? You could use parentheses to build the multi-line strings, without having to post-process it at runtime:

(
  f"You are using a non-supported Python version ({py_version_str}). "
  f"Google will not post any further updates to {package_label} "
  "supporting this Python version. Please upgrade to the latest Python "
  f"version, or at least Python {min_python(today)}, and then update "
  f"{package_label}."
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contrariwise, is the optimization you suggest really necessary?

The advantage of the way I have it is that it makes changing the message simpler for developers: just write and re-wrap the text. The cost is that, yes, it does get called at run time, but only upon initialization and only once per message that is printed. So yes, it could add up, but it doesn't seem like that would be substantial.

If you feel strongly about it I'll change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I raised this more for simplicity rather than performance concerns. Python has built-in functionality for building long strings, so adding a custom helper for this seemed unnecessary to me. But this is more of a nit; I don't think this helper is too complex, and I don't feel too strongly about it

If we keep it, can we add some unit tests or something around it though?



def check_python_version(today: Optional[datetime.date] = None) -> PythonVersionStatus:
def check_python_version(package: Optional[str] = "this package",
today: Optional[datetime.date] = None) -> PythonVersionStatus:
"""Check the running Python version and issue a support warning if needed.

Args:
Expand Down Expand Up @@ -146,9 +147,9 @@ def min_python(date: datetime.date) -> str:
message = _flatten_message(
f"""
You are using a non-supported Python version ({py_version_str}).
You will receive no updates to this client library. We suggest
Google will not post any further updates to {package}. We suggest
you upgrade to the latest Python version, or at least Python
{min_python(today)}, and then update this library.
{min_python(today)}, and then update {package}.
"""
)
logging.warning(message)
Expand All @@ -159,11 +160,10 @@ def min_python(date: datetime.date) -> str:
message = _flatten_message(
f"""
You are using a Python version ({py_version_str}) past its end
of life. This client library will continue receiving critical
bug fixes on a best-effort basis, but not any other fixes or
of life. Google will update {package} with critical
bug fixes on a best-effort basis, but not with any other fixes or
features. We suggest you upgrade to the latest Python version,
or at least Python {min_python(today)}, and then update this
library.
or at least Python {min_python(today)}, and then update {package}.
"""
)
logging.warning(message)
Expand All @@ -172,12 +172,12 @@ def min_python(date: datetime.date) -> str:
if gapic_deprecation <= today <= gapic_end:
message = _flatten_message(
f"""
You are using a Python version ({py_version_str}), which new
releases of this client library will stop supporting when it
You are using a Python version ({py_version_str}),
which Google will stop supporting in {package} when it
reaches its end of life ({version_info.python_eol}). We
suggest you upgrade to the latest Python version, or at least
Python {min_python(version_info.python_eol)}, and then update
this library.
suggest you upgrade to the latest Python version, or at
least Python {min_python(version_info.python_eol)}, and
then update {package}.
"""
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think these message (or at least templates) would be better as constants, instead of embedded in the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, for the same reason as the other case. They are defined and used directly only once, and the substitution strings and the text are closely related to the logic of the function. I think it reads more clearly to have them defined inline, as they are now.

logging.warning(message)
Expand Down