-
Notifications
You must be signed in to change notification settings - Fork 119
SG-32657 Enable support for Python 3.10 in CI #920
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
Changes from all commits
0c40b0b
59e7b39
d3fdd92
d975b24
a226581
4ae5026
2acdb7c
934f412
ce5718c
f0d38a2
4240b18
94418c9
106cf7b
6fce300
224d251
2625371
de6428c
4689666
d73e0bd
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 |
|---|---|---|
|
|
@@ -7,11 +7,19 @@ | |
| # By accessing, using, copying or modifying this work you indicate your | ||
| # agreement to the Shotgun Pipeline Toolkit Source Code License. All rights | ||
| # not expressly granted therein are reserved by Shotgun Software Inc. | ||
| import warnings | ||
| import contextlib | ||
| import sys | ||
|
|
||
| if sys.version_info[0:2] >= (3, 10): | ||
| from setuptools._distutils.version import LooseVersion | ||
| else: | ||
| from distutils.version import LooseVersion | ||
|
|
||
| from distutils.version import LooseVersion | ||
| from . import sgre as re | ||
| from ..errors import TankError | ||
|
|
||
|
|
||
| GITHUB_HASH_RE = re.compile("^[0-9a-fA-F]{7,40}$") | ||
|
|
||
|
|
||
|
|
@@ -115,6 +123,20 @@ def is_version_number(version): | |
| return False | ||
|
|
||
|
|
||
| @contextlib.contextmanager | ||
| def suppress_known_deprecation(): | ||
| """ | ||
| Imported function from setuptools.distutils module | ||
| """ | ||
| with warnings.catch_warnings(record=True) as ctx: | ||
| warnings.filterwarnings( | ||
| action="default", | ||
| category=DeprecationWarning, | ||
| message="distutils Version classes are deprecated.", | ||
|
Member
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 am confused now. Should we not use this method then?
Contributor
Author
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. You can find more information in the PR description. To sum up, distutils is now deprecated, and starting from Python 3.10 we will use the distutils copy that is shipped on
Member
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. Ok but this is a temporary solution, right? At some point, we need to migrate to
Contributor
Author
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. Yes, it's too big. At first, I tried the migration to We won't be able to easily move to packaging. I'd suggest to keep using |
||
| ) | ||
| yield ctx | ||
|
|
||
|
|
||
| def _compare_versions(a, b): | ||
| """ | ||
| Tests if version a is newer than version b. | ||
|
|
@@ -124,8 +146,8 @@ def _compare_versions(a, b): | |
|
|
||
| :rtype: bool | ||
| """ | ||
| if b is None: | ||
| # a is always newer than None | ||
| if b in [None, "Undefined"]: | ||
| # a is always newer than None or `Undefined` | ||
| return True | ||
|
|
||
| if _is_git_commit(a) and not _is_git_commit(b): | ||
|
|
@@ -157,37 +179,40 @@ def _compare_versions(a, b): | |
| # First, try to use LooseVersion for comparison. This should work in | ||
| # most cases. | ||
| try: | ||
| version_a = LooseVersion(a).version | ||
| version_b = LooseVersion(b).version | ||
| version_num_a = [] | ||
| version_num_b = [] | ||
| # taking only the integers of the version to make comparison | ||
| for version in version_a: | ||
| if isinstance(version, (int)): | ||
| version_num_a.append(version) | ||
| elif version == "-": | ||
| break | ||
| for version in version_b: | ||
| if isinstance(version, (int)): | ||
| version_num_b.append(version) | ||
| elif version == "-": | ||
| break | ||
|
|
||
| # Comparing equal number versions with with one of them with '-' appended, if a version | ||
| # has '-' appended it's older than the same version with '-' at the end | ||
| if version_num_a == version_num_b: | ||
| if "-" in a and "-" not in b: | ||
| return False # False, version a is older than b | ||
| elif "-" in b and "-" not in a: | ||
| return True # True, version a is older than b | ||
| with suppress_known_deprecation(): | ||
| # Supress `distutils Version classes are deprecated.` for Python 3.10 | ||
| version_a = LooseVersion(a).version | ||
| version_b = LooseVersion(b).version | ||
|
|
||
| version_num_a = [] | ||
| version_num_b = [] | ||
| # taking only the integers of the version to make comparison | ||
| for version in version_a: | ||
| if isinstance(version, (int)): | ||
| version_num_a.append(version) | ||
| elif version == "-": | ||
| break | ||
| for version in version_b: | ||
| if isinstance(version, (int)): | ||
| version_num_b.append(version) | ||
| elif version == "-": | ||
| break | ||
|
|
||
| # Comparing equal number versions with with one of them with '-' appended, if a version | ||
| # has '-' appended it's older than the same version with '-' at the end | ||
| if version_num_a == version_num_b: | ||
| if "-" in a and "-" not in b: | ||
| return False # False, version a is older than b | ||
| elif "-" in b and "-" not in a: | ||
| return True # True, version a is older than b | ||
| else: | ||
| return LooseVersion(a) > LooseVersion( | ||
| b | ||
| ) # If both has '-' compare '-rcx' versions | ||
| else: | ||
| return LooseVersion(a) > LooseVersion( | ||
| b | ||
| ) # If both has '-' compare '-rcx' versions | ||
| else: | ||
| return LooseVersion(a) > LooseVersion( | ||
| b | ||
| ) # If they are different numeric versions | ||
| ) # If they are different numeric versions | ||
| except TypeError: | ||
| # To mimick the behavior in Python 2.7 as closely as possible, we will | ||
| # If LooseVersion comparison didn't work, try to extract a numeric | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1f132f8f495333acc7303996a8151d73b2c204ae | ||
| 11db780c4a18993130a988d73f9e50bd7d17e53f |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import base64 | ||
| import re | ||
|
|
||
| from ... import pyparsing as pp | ||
|
|
||
| from .error import * | ||
|
|
||
|
|
||
| try: # pyparsing>=3.0.0 | ||
| downcaseTokens = pp.common.downcaseTokens | ||
| except AttributeError: | ||
| downcaseTokens = pp.downcaseTokens | ||
|
|
||
| UNQUOTE_PAIRS = re.compile(r"\\(.)") | ||
| unquote = lambda s, l, t: UNQUOTE_PAIRS.sub(r"\1", t[0][1:-1]) | ||
|
|
||
| # https://tools.ietf.org/html/rfc7235#section-1.2 | ||
| # https://tools.ietf.org/html/rfc7235#appendix-B | ||
| tchar = "!#$%&'*+-.^_`|~" + pp.nums + pp.alphas | ||
| token = pp.Word(tchar).setName("token") | ||
| token68 = pp.Combine(pp.Word("-._~+/" + pp.nums + pp.alphas) + pp.Optional(pp.Word("=").leaveWhitespace())).setName( | ||
| "token68" | ||
| ) | ||
|
|
||
| quoted_string = pp.dblQuotedString.copy().setName("quoted-string").setParseAction(unquote) | ||
| auth_param_name = token.copy().setName("auth-param-name").addParseAction(downcaseTokens) | ||
| auth_param = auth_param_name + pp.Suppress("=") + (quoted_string | token) | ||
| params = pp.Dict(pp.delimitedList(pp.Group(auth_param))) | ||
|
|
||
| scheme = token("scheme") | ||
| challenge = scheme + (params("params") | token68("token")) | ||
|
|
||
| authentication_info = params.copy() | ||
| www_authenticate = pp.delimitedList(pp.Group(challenge)) | ||
|
|
||
|
|
||
| def _parse_authentication_info(headers, headername="authentication-info"): | ||
| """https://tools.ietf.org/html/rfc7615 | ||
| """ | ||
| header = headers.get(headername, "").strip() | ||
| if not header: | ||
| return {} | ||
| try: | ||
| parsed = authentication_info.parseString(header) | ||
| except pp.ParseException as ex: | ||
| # print(ex.explain(ex)) | ||
| raise MalformedHeader(headername) | ||
|
|
||
| return parsed.asDict() | ||
|
|
||
|
|
||
| def _parse_www_authenticate(headers, headername="www-authenticate"): | ||
| """Returns a dictionary of dictionaries, one dict per auth_scheme.""" | ||
| header = headers.get(headername, "").strip() | ||
| if not header: | ||
| return {} | ||
| try: | ||
| parsed = www_authenticate.parseString(header) | ||
| except pp.ParseException as ex: | ||
| # print(ex.explain(ex)) | ||
| raise MalformedHeader(headername) | ||
|
|
||
| retval = { | ||
| challenge["scheme"].lower(): challenge["params"].asDict() | ||
| if "params" in challenge | ||
| else {"token": challenge.get("token")} | ||
| for challenge in parsed | ||
| } | ||
| return retval |
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.
Again, not a blocker but I really wonder why bother listing all these modules, classes, and methods in this file instead of using Python's default import system? (
from utils import versionthenversion.suppress_known_deprecation)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.
From what I've seen it's just to simplify the importing workflow. Maybe that was the original code style for tk-core.