-
Notifications
You must be signed in to change notification settings - Fork 198
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
SG-29997 Removing Python 2 code #345
SG-29997 Removing Python 2 code #345
Conversation
eduardoChaucaGallegos
commented
Jun 4, 2024
- Removing the use of six package
- Useful functions for shotgun.py copied to sgsix.py
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.
Good start.
del __SSLHandshakeError | ||
# Generate ssl_error_classes | ||
import ssl as __ssl | ||
ssl_error_classes = (__ssl.SSLError, __ssl.CertificateError) |
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.
Do we need to keep this variable or can we just replace the code where ssl_error_classes is used by __ssl.SSLError, __ssl.CertificateError?
# get the python2 fork of httplib2 | ||
from . import python2 as __httplib2_compat | ||
# get the python3 fork of httplib2 | ||
from . import python3 as __httplib2_compat |
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.
why do we have a "python3" folder in there? Can we simplify how we bundle httplib2 in this repo?
shotgun_api3/shotgun.py
Outdated
|
||
from .lib.httplib2 import Http, ProxyInfo, socks, ssl_error_classes | ||
from .lib.sgtimezone import SgTimezone | ||
from .lib import sgsix |
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.
Can/Should we get rid of that? (or rename the module to "something_utils.py"?)
shotgun_api3/shotgun.py
Outdated
@@ -2136,7 +2126,7 @@ def schema_field_update(self, entity_type, field_name, properties, project_entit | |||
"field_name": field_name, | |||
"properties": [ | |||
{"property_name": k, "value": v} | |||
for k, v in six.iteritems((properties or {})) | |||
for k, v in (properties.items() if isinstance(properties, dict) else {}) |
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.
I don't think this is correct. What you want is:
for k, v in (properties.items() if isinstance(properties, dict) else {}) | |
for k, v in ((properties if isinstance(properties, dict) else {}).items()) |
But I think we'd better have this check done earlier in the function instead.
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.
I don't think we want to edit httplib2. This is third-party we bundle. But can we update to a newer version if we drop py2?
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.
Actually, it was manually updated by #202 so we might want to clean up (or simply update to a newer version)
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.
Make sure to look #202 when addressing this PR
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.
I am starting to get scared by this PR. This is super big and going all over the place. We might want to chunk it.
=================== | ||
- Drop support for Python 2.x.x | ||
- Drop use of six package | ||
- Documentation update |
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.
We only change this file when we prepare a release of python-api. Not when we work on the code.
|
||
|
||
setup( | ||
name='shotgun_api3', | ||
version='3.6.0', | ||
version='3.7.0', |
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.
No, not in this PR
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.
Actually, it was manually updated by #202 so we might want to clean up (or simply update to a newer version)
@@ -3575,7 +3546,7 @@ def _make_call(self, verb, path, body, headers): | |||
attempt += 1 | |||
try: | |||
return self._http_request(verb, path, body, req_headers) | |||
except ssl_error_classes as e: | |||
except (SSLError, CertificateError) as e: | |||
# Test whether the exception is due to the fact that this is an older version of | |||
# Python that cannot validate certificates encrypted with SHA-2. If it is, then |
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.
This comment talks about Python 2.5 and below. We might want to clean that up. I started that in #347.
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.
Looks good so far. It would be great to depend less from six or sgsix functions.
I also opened a few questions.
@@ -23,17 +23,11 @@ See bugs: | |||
|
|||
The version of `mimetypes` bundled should be updated manually if necessary, however it is unlikely this will be needed, as it is only used for Python versions 2.7.0 - 2.7.9, and newer Python versions simply use the native `mimetypes` module. | |||
|
|||
### six |
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.
I don't see six
removed in this PR. We should keep this until it is completely removed.
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.
Why is the reason of this rename? There are components importing sgsix
and this change could potentially break them. Example: https://github.com/shotgunsoftware/tk-core/blob/master/python/tank/commands/core_localize.py#L26
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.
@eduardoChaucaGallegos Crazy idea: can we leave these methods on six.py for now and keep a mini-version of six.py only with the methods implemented in this file?
My intention is to avoid renaming the package and impact the TK components that depends on these functions.
We can discuss this internally.
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.
Not so crazy, I kind of like that.
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.
I'm going to revert changes in this MR to only apply steps for first phase (that mini-version of six.py can be sgutils.py )
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.
that mini-version of six.py can be sgutils.py
Yes, but keeping the same name of six.py
That way, dependant component won't need to rename the import for ensure_*
if isinstance(k, str): | ||
k = sgutils.ensure_str(k) | ||
if isinstance(v, str): | ||
v = sgutils.ensure_str(v) |
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.
I think this was needed when we have different string types in Python 2 (string and unicode). I guess ensure_str
is not needed anymore making these two conditionals useless. This is just an assumption.
if isinstance(value, six.string_types): | ||
return six.ensure_text(value) | ||
if isinstance(value, str): | ||
return sgutils.ensure_text(value) |
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.
Same as my previous comment.
@@ -4253,7 +4224,7 @@ def _send_form(self, url, params): | |||
else: | |||
raise ShotgunError("Unanticipated error occurred %s" % (e)) | |||
|
|||
return six.ensure_text(result) | |||
return sgutils.ensure_text(result) |
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.
Same here, I think we can just use
return sgutils.ensure_text(result) | |
return str(result) |
value = sgutils.ensure_text(value) | ||
key = sgutils.ensure_text(key) |
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.
same here, I think we can safely replace str
casting method isntead.