Skip to content
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

Closed

Conversation

eduardoChaucaGallegos
Copy link
Contributor

  • Removing the use of six package
  • Useful functions for shotgun.py copied to sgsix.py

Copy link
Contributor

@julien-lang julien-lang left a 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)
Copy link
Contributor

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
Copy link
Contributor

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?


from .lib.httplib2 import Http, ProxyInfo, socks, ssl_error_classes
from .lib.sgtimezone import SgTimezone
from .lib import sgsix
Copy link
Contributor

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"?)

@@ -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 {})
Copy link
Contributor

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:

Suggested change
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.

Copy link
Contributor

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?

Copy link
Contributor

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)

Copy link
Contributor

@julien-lang julien-lang left a 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

Copy link
Contributor

@julien-lang julien-lang left a 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
Copy link
Contributor

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',
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

@carlos-villavicencio-adsk carlos-villavicencio-adsk left a 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
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 )

Copy link
Contributor

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_*

Comment on lines +3691 to +3694
if isinstance(k, str):
k = sgutils.ensure_str(k)
if isinstance(v, str):
v = sgutils.ensure_str(v)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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

Suggested change
return sgutils.ensure_text(result)
return str(result)

Comment on lines +4325 to +4326
value = sgutils.ensure_text(value)
key = sgutils.ensure_text(key)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants