Skip to content

Commit a567589

Browse files
julien-langCopilotmchesnay
authored
SG-40994 Update deprecation warning message about end of compat with Py 3.7 (#424)
* Update deprecation warning message about end of compat with Py 3.7 * Make module not importable * Address review and update documentation * Update shotgun_api3/__init__.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Better for review * Apply suggestions from code review Co-authored-by: Martin Chesnay <104032692+mchesnay@users.noreply.github.com> * Apply suggestion from review * Unify variable name with tk-core --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Martin Chesnay <104032692+mchesnay@users.noreply.github.com>
1 parent 9e35983 commit a567589

4 files changed

Lines changed: 48 additions & 14 deletions

File tree

docs/installation.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ Installation
66
Minimum Requirements
77
********************
88

9-
- Python 3.7
10-
119
.. note::
1210
Some features of the API are only supported by more recent versions of the Flow Production Tracking server.
1311
These features are added to the Python API in a backwards compatible way so that existing
1412
scripts will continue to function as expected. Accessing a method that is not supported for
1513
your version of Flow Production Tracking will raise an appropriate exception. In general, we attempt to
1614
document these where possible.
1715

16+
Python versions
17+
===============
18+
19+
The Python API library supports the following Python versions: `3.9 - 3.11`. We recommend using Python 3.11.
20+
21+
.. important::
22+
Python versions older than 3.9 are no longer supported as of March 2025 and compatibility will be discontinued after
23+
March 2026.
24+
25+
1826
******************************
1927
Installing into ``PYTHONPATH``
2028
******************************

docs/reference.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,19 @@ Will internally be transformed as if you invoked something like this:
994994
sg.find('Asset', [['project', 'is', {'id': 999, 'type': 'Project'}]])
995995
996996
997+
SHOTGUN_ALLOW_OLD_PYTHON
998+
========================
999+
1000+
When set to ``1``, ``shotgun_api3`` will allow being imported from Python versions that are no longer supported.
1001+
Otherwise, when unset (or set to any other value), importing the module will raise an exception.
1002+
1003+
This is not recommended and should only be used for testing purposes.
1004+
1005+
.. important::
1006+
The ability to import the module does not guarantee that the module will work properly on the unsupported Python
1007+
version. In fact, it is very likely that it will not work properly.
1008+
1009+
9971010
************
9981011
Localization
9991012
************

shotgun_api3/__init__.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,35 @@
88
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
99
# not expressly granted therein are reserved by Shotgun Software Inc.
1010

11+
import os
1112
import sys
1213
import warnings
1314

14-
if sys.version_info < (3, 9):
15+
if sys.version_info < (3, 7):
16+
if os.environ.get("SHOTGUN_ALLOW_OLD_PYTHON", "0") != "1":
17+
# This is our preferred default behavior when using an old
18+
# unsupported Python version.
19+
# This way, we can control where the exception is raised, and it provides a
20+
# comprehensive error message rather than having users facing a random
21+
# Python traceback and trying to understand this is due to using an
22+
# unsupported Python version.
23+
24+
raise RuntimeError("This module requires Python version 3.7 or higher.")
25+
26+
warnings.warn(
27+
"Python versions older than 3.7 are no longer supported as of January "
28+
"2023. Since the SHOTGUN_ALLOW_OLD_PYTHON variable is enabled, this "
29+
"module is raising a warning instead of an exception. "
30+
"However, it is very likely that this module will not be able to work "
31+
"on this Python version.",
32+
RuntimeWarning,
33+
stacklevel=2,
34+
)
35+
elif sys.version_info < (3, 9):
1536
warnings.warn(
16-
"Python versions older than 3.9 are no longer supported since 2025-03 "
17-
"and compatibility will be removed at any time after 2026-01. "
18-
"Please update to Python 3.9 or a newer supported version.",
37+
"Python versions older than 3.9 are no longer supported as of March "
38+
"2025 and compatibility will be discontinued after March 2026. "
39+
"Please update to Python 3.11 or any other supported version.",
1940
DeprecationWarning,
2041
stacklevel=2,
2142
)

shotgun_api3/shotgun.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ def __init__(self, host: str, meta: Dict[str, Any]) -> None:
222222
:ivar bool is_dev: ``True`` if server is running a development version of the Shotgun
223223
codebase.
224224
"""
225-
self._ensure_python_version_supported()
226225
# Server host name
227226
self.host = host
228227
self.server_info = meta
@@ -249,13 +248,6 @@ def __init__(self, host: str, meta: Dict[str, Any]) -> None:
249248
self.version = tuple(self.version[:3])
250249
self._ensure_json_supported()
251250

252-
def _ensure_python_version_supported(self) -> None:
253-
"""
254-
Checks the if current Python version is supported.
255-
"""
256-
if sys.version_info < (3, 7):
257-
raise ShotgunError("This module requires Python version 3.7 or higher.")
258-
259251
def _ensure_support(self, feature: Dict[str, Any], raise_hell: bool = True) -> bool:
260252
"""
261253
Checks the server version supports a given feature, raises an exception if it does not.

0 commit comments

Comments
 (0)