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

For #45220: Tweaks support for non-ascii document names. #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
12 changes: 12 additions & 0 deletions hooks/tk-multi-publish2/basic/publish_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# not expressly granted therein are reserved by Shotgun Software Inc.

import os
import sys
import sgtk

HookBaseClass = sgtk.get_hook_baseclass()
Expand Down Expand Up @@ -391,4 +392,15 @@ def _document_path(document):
except Exception:
path = None

# The RPC API is always going to return a utf-8 encoded string
# here. This is fine (and correct) in almost all cases, but there
# are some situations on Windows where the encoded path, if it
# includes non-ascii characters, will test as false when checking
# existence. In that case, we're forced to decode the string to
# unicode.
#
# Note: This does not appear to be an issue on OS X.
if path and sys.platform.startswith("win") and not os.path.exists(path):
path = path.decode("utf-8")
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a :returns: to the docstring. But if i am reading this correctly, looks like the returns would look like:

returns a utf-8 encoded path to the document, UNLESS you are on 
windows and the path does not exist or contains non-ascii characters, 
in which case a unicode string is returned.

That doesn't seem like good encapsulation or consistency and seems like it can lead to subtle bugs.

As far as i understand, i think there are two ways to go, both approaches returning a consistent string from _document_path():

  • If there are several more complex path operations inside the photoshop hook logic, all requiring unicode paths on windows to function, we return all paths from _document_path() as unicode. Ideally for all OSes, but possibly for windows only if that makes sense.

  • if path operations are atomic and simple (like for example in the loader), we convert to unicode right before the operation (os.path.exists(path.decode("utf-8"))

I am happy either way as long as we keep the return values consistent and we explain the logic in some comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Thanks!


return path
13 changes: 11 additions & 2 deletions python/tk_photoshopcc/adobe_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# not expressly granted therein are reserved by Shotgun Software Inc.

import os
import sys
import functools
import threading

Expand Down Expand Up @@ -207,8 +208,16 @@ def get_active_document_path(self):
except Exception:
path = None

if isinstance(path, unicode):
path = path.encode("utf-8")
# The RPC API is always going to return a utf-8 encoded string
# here. This is fine (and correct) in almost all cases, but there
# are some situations on Windows where the encoded path, if it
# includes non-ascii characters, will test as false when checking
# existence. In that case, we're forced to decode the string to
# unicode.
#
# Note: This does not appear to be an issue on OS X.
if path and sys.platform.startswith("win") and not os.path.exists(path):
path = path.decode("utf-8")

return path

Expand Down